Every lab includes hints and full solutions, so don’t worry if you’re not confident yet.
Overview
In this lab you’ll convert an existingusers table with 10,000 rows into a distributed table using Citus, splitting it into eight shards across two worker machines. The steps below show the exact psql commands and the expected outputs so you can follow along and verify each stage of the distribution.
Prerequisites
- A Citus-enabled PostgreSQL cluster with a control plane and two worker nodes.
- A
chirpdatabase containing auserstable. psqlaccess from the control plane to the coordinator (example uses-h localhost -p 5432 -U postgres -d chirp).
Step 1 — Confirm the users table row count
First, make sure theusers table contains the expected 10,000 rows:
Step 2 — Create the distributed table
Convert the localusers table into a distributed table using create_distributed_table. Specify the distribution column (user_id) and the number of shards (shard_count => 8). Note that the named parameter uses =>.
- Creates 8 shards for the
userstable. - Distributes the shards across available worker nodes.
- Copies existing data from the local table into the distributed shards.
Step 3 — Verify shard placements across workers
Query the Citus distribution metadata to confirm how shards are placed across worker nodes. Thepg_dist_shard_placement table shows the node name and how many placements it has:
Quick reference: commands and purpose
Notes and troubleshooting
If you see an uneven distribution, ensure both workers are properly registered with the coordinator and that there are no placement constraints. Re-run the placement query after any worker configuration changes.