Get Started
Start sharding your PostgreSQL cluster in 5 minutes
Let’s set up the simplest possible installation scenario - when you have two shards and one router.
Setting up sharding
First, you need to configure the rules by which the router will decide which of the shards to send each request to.
For this purpose, SPQR has an administrative console. This is an app that works by PostgreSQL protocol and you can connect to it by usual psql. You can find the console port in your config file.
To make all things work, the router needs to know the following:
- What tables do you query
- Which columns in each table should the router search for
- Types of these columns
- Mapping from [range of values] to [shard number]
Let’s create a distribution first:
The next step is to specify a list of tables and columns.
And at the end specify a list of ranges: which values to route to which shard. Note: The right bound is infinity if there are no key ranges.
Here we go! You can play with some SELECTs or INSERTs.
Connect to SPQR router
Now we can connect to proxy a.k.a. router and play with it. Please use psql again, but this time connect to a different port.
Then, populate it with an order:
NOTICE messages are disabled by default, specify
show_notice_messages
setting in the router config to enable them
The order can be found on the first shard:
SPQR can handle such queries as SELECT * FROM table
but we don’t recommend using it. This feature is implemented in a non-transactional way.
Was this page helpful?