What Is the Best Way to Control the Total Number of Shards in My YugabyteDB Cluster ?

Distributed SQL Tips and Tricks Series
Marko Rajcevic

You can control the number of shards—called tablets in YugabyteDB—using multiple methods depending on how much control you want. The flag ysql_num_tablets controls the number of tablets per YSQL table. The default value is -1. If its value is not set then the value defaults to ysql_num_shards_per_tserver. The difference between the two is that the first controls the total number of tablets for the table; the second controls the number of tablets per tserver.

For example, ysql_num_tablets=1 stores the table into a single tablet.

However, if the cluster has 3 nodes, where each has a tserver, and ysql_num_shards_per_tserver=1 then the table will be split into 3 tablets since there are 3 tservers.

So, in this case, the number of tservers will determine the tablet count.

If the user uses the SPLIT INTO syntax during the CREATE TABLE DDL statement then it overrides the values of the flags specified above. NOTE: you can always manually split any existing tablets after the fact as well.

Additionally, YugabyteDB supports dynamic auto-splitting which handles this for you as your data grows.

Remember, since indexes are additional tables in YugabyteDB this applies to them as well. For YCQL, the syntax is different and YCQL-specific, however, the same process applies.

Additional Resources on Sharding

Discover More Tips and Tricks

Explore our library of distributed SQL tips and tricks and general “how to” information on the YugabyteDB blog and on our DEV Community Blogs.

Events and Training

Check out the upcoming YugabyteDB events, including all training sessions, conferences, in-person and virtual events, and YugabyteDB Friday Tech Talks (designed for engineers by engineers).

In addition, there is some extremely popular “how to” content on the YugabyteDB YouTube channel.

If You Have Questions About Distributed SQL

If you have questions, ask them on the YugabyteDB Slack channel, Forum, GitHub, or Stack Overflow.

Next Steps

Ready to start exploring YugabyteDB features? You have some great options to get started. Run the database locally on your laptop (Quick Start), deploy it to your favorite cloud provider (Multi-node Cluster Deployment), sign up for a free YugabyteDB Managed cluster, or request a full-featured trial. It’s easy! Get started today!

Marko Rajcevic

Related Posts

Explore Distributed SQL and YugabyteDB in Depth

Discover the future of data management.
Learn at Yugabyte University
Get Started
Browse Yugabyte Docs
Explore docs
PostgreSQL For Cloud Native World
Read for Free