1) Check the current distribution column
Query the Citus metadata tablecitus_tables to see which column each distributed table uses:
2) Inspect how rows are spread across shards
Userun_command_on_shards to run a per-shard row count and inspect balance. For example, count rows per shard on users_by_country:
3) How to evaluate shard-key candidates
When evaluating shard keys, prefer columns with these properties:When picking a shard key, aim for high-cardinality columns that are commonly used in your queries’ WHERE clauses. Avoid columns with highly skewed distributions (e.g., a small set of very frequent values) since they create hotspot shards. If you need to change distribution for an existing large table, create a new distributed table with the desired column and migrate data—there is no single
ALTER TABLE ... DISTRIBUTE BY that rehashes a large table in place.4) Example: distribute a table by a different column
To create a distributed table that usesuser_id as the distribution column:
run_command_on_shards to compare per-shard counts and verify improved balance.
5) Troubleshooting and tips
- If one shard is much larger than others, inspect the frequency distribution of the shard key values to find hotspots.
- Consider adding a compound shard key (multiple columns) if single columns don’t provide good distribution and your queries include those columns.
- Test redistribution in a staging environment before running large-scale data migrations in production.
Links and references
- Citus metadata tables: https://docs.citusdata.com/en/latest/reference/metadata_tables.html
- Citus
run_command_on_shards: https://docs.citusdata.com/en/latest/reference/run_command_on_shards.html - Citus
create_distributed_table: https://docs.citusdata.com/en/latest/commands/create_distributed_table.html