Documentation Index
Fetch the complete documentation index at: https://docs.pg-sharding.tech/llms.txt
Use this file to discover all available pages before exploring further.
Transaction Behavior
Default Route Behaviour
query_routing.default_route_behaviour parameter determines what happens when SPQR cannot route a query to a single shard:BLOCK: Rejects queries that would need to execute on multiple shards (safer for consistency)ALLOW: Permits multi-shard queries to execute (useful for DDL and administrative queries)
BLOCK: Production environments where you want strict control over shard accessALLOW: Development, testing, or when executing DDL commands across all shards
Scatter Query
__spqr__scatter_query routing hint is useful when you need to run a query across all shards, regardless of sharding key:
Bulk Operations
SPQR supports bulk data loading across multiple shards, including COPY FROM and batch INSERT statements. When engine V2 is enabled, multi-value INSERT statements are automatically split and routed to the correct shards. For detailed information, examples, and limitations, see Bulk Operations.Commit Strategies
SPQR provides three commit strategies for distributed transactions, controlled by the default_commit_strategy parameter.1. One-Phase Commit
Value:1pc (alias: best-effort)
This is the default commit strategy. In this mode transactions are committed on each shard independently with no coordination between shards and is best used for single-shard transactions or when eventual consistency is acceptable.
2. Two-Phase Commit (2PC)
Two-phase commit ensures atomicity across multiple shards using PostgreSQL’s prepared transaction feature. How 2PC Works:- Prepare Phase: SPQR sends
PREPARE TRANSACTIONto all involved shards with a unique transaction ID - Commit Phase: If all shards successfully prepare, SPQR sends
COMMIT PREPAREDto each shard - Rollback on Failure: If any shard fails to prepare, SPQR rolls back the entire transaction
2PC provides atomicity but has performance overhead. Prepared transactions consume resources on shards until committed or rolled back. Monitor prepared transactions with
pg_prepared_xacts on each shard and configure max_prepared_transactions based on your expected concurrent transaction volume.