Skip to main content
The local demo includes two PostgreSQL shards, the SPQR router, and the psql client. If you already have an empty SPQR cluster, load the demo there.
If your router is already running with examples/init.sql, skip to the psql command below. To start it, you need two empty PostgreSQL instances on localhost:5432 and localhost:5433 that accept connections as postgres without a password. Run these commands from the directory containing spqr-router. The first downloads the example configuration if your release omitted it.
If the router reports a socket permission error with an older config, set unix_socket_dir: . in examples/quickstart.yaml and start the router again.Open a second terminal and connect to the running router.
On fresh shards, run these commands in psql.
The notices show Alice on sh1 and Bob on sh2. The sample rules place IDs starting at 50000 on sh2.

Start the local demo

You need Git, Docker with Compose 2.23.1 or later, and four free local ports. SPQR uses 6432 and 7432. The shards use 5441 and 5442.
Choose free local ports and export them in the terminal you’ll use for the demo.
Clone the repository, which includes the Small dataset. The load command starts the router and both shards, then loads the data.
When the loader prints Messenger demo is loaded and the row counts for both shards, you’re ready to connect.

Connect to SPQR router

From the same directory, open a SQL session on the router.
Turn on routing notices and query two chats at opposite ends of the key space.
Compare each title with the shard named in its NOTICE. You used the same connection for both queries. SPQR read the chat_id in each query and sent it to the shard that owns that range.

Read the routing rules

Stay in the same psql session. Switch to the admin console on port 7432, inspect the rules, and switch back.
The first result identifies chat_id as the sharding key for messages. The second shows where each range starts and which shard owns it. Use that map to predict which shard will answer each query below.
Both counts are 43. Check the notices. Chat 500 is on sh2 and chat 501 is on sh1, where the second range starts. Next, find the author of a message and query both shards in the same psql session.

Stop or remove the local demo

Exit psql with \q. Run the command you need from the demo directory. The router keeps its routing rules in memory. After a router restart, use the reset command to recreate the rules and reload the sample data. For other installations, see the router binaries, source build instructions, and deployment guide.