Display the Number of Tablets (Shards) for a Table

By default, YugabyteDB presplits a table in ysql_num_shards_per_tserver * num_of_tserver shards. 

We can display the number of tablets for a table using the yb_table_properties function.

				
					yugabyte=# CREATE TABLE test (c1 INT PRIMARY KEY, c2 VARCHAR);
CREATE TABLE

yugabyte=# SELECT * FROM yb_table_properties('test'::regclass);
 num_tablets | num_hash_key_columns | is_colocated | tablegroup_oid | colocation_id
-------------+----------------------+--------------+----------------+---------------
           6 |                    1 | f            |                |
(1 row)
				
			

The SPLIT INTO clause can be used to override the ysql_num_shards_per_tserver setting on a per-table basis.

				
					yugabyte=# DROP TABLE test;
DROP TABLE

yugabyte=# CREATE TABLE test (c1 INT PRIMARY KEY, c2 VARCHAR) SPLIT INTO 12 TABLETS;
CREATE TABLE

yugabyte=# SELECT * FROM yb_table_properties('test'::regclass);
 num_tablets | num_hash_key_columns | is_colocated | tablegroup_oid | colocation_id
-------------+----------------------+--------------+----------------+---------------
          12 |                    1 | f            |                |
(1 row)
				
			

Have Fun!