What is SPQR
SPQR (Stateless Postgres Query Router) is a production-ready system for horizontal scaling of PostgreSQL via sharding. A real open source distributed under the PostgreSQL Global Development Group License.
# Pull the latest stable SPQR router image
docker pull pgsharding/spqr-router:latest
# Run with your configuration
docker run -d \
--name spqr-router \
-v /path/to/router.yaml:/etc/spqr/router.yaml:ro \
-p 6432:6432 \
-p 7432:7432 \
-p 7000:7000 \
pgsharding/spqr-router:latest
Why SPQR
PostgreSQL is awesome, but it’s hard to manage a single database with some terabytes of data and 105+ queries per second. Existing sharding solutions focus on analytical and hybrid workloads (OLAP, HTAP). Moreover, most of those solutions do not provide a simple, painless path for the monolith <-> sharded transitions. That’s why the
Data Platform team of Yandex.Cloud designed SPQR.
Our team has been exploring different approaches to sharding a PostgreSQL cluster for a long time. We have considered FDW-based sharding, CustomNode-based sharding, C-implemented lightweight query routing, and finally came to the SPQR design.
SPQR is a good fit for:
- Developers who are comfortable with Postgres and prefer not to use other database engines
- Developers who cannot or do not wish to implement sharding logic on the application level
- A database that is well splitted by a sharding key
- Single-shard OLTP queries