What Is the Best Way to Control the Total Number of Shards in My YugabyteDB Cluster ?
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.
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
- When To Use Range Sharding vs. Hash Sharding
- Will a Partitioned Table in YugabyteDB Also Be Sharded?
- What Is the Difference Between ‘Table Partitioning’ and ‘Sharding’ In a Distributed SQL Deployment?
- When Using YugabyteDB, How Many Shards Should I Break My Tables Into?
- Database Sharding Library
Explore our library of distributed SQL tips and tricks and general “how to” information on the YugabyteDB blog and on our DEV Community Blogs.
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.
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!