psql client. If you already have an empty SPQR cluster, load the demo there.
Installed the router with install.sh?
Installed the router with install.sh?
If your router is already running with If the router reports a socket permission error with an older config, set On fresh shards, run these commands in The notices show Alice on
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.unix_socket_dir: . in examples/quickstart.yaml and start the router again.Open a second terminal and connect to the running router.psql.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 uses6432 and 7432. The shards use 5441 and 5442.
Port already in use?
Port already in use?
Choose free local ports and export them in the terminal you’ll use for the demo.
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.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 samepsql session. Switch to the admin console on port 7432, inspect the rules, and switch back.
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.
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
Exitpsql 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.