P.3. Architecture #
- What is the difference between partitioning and sharding in Postgres Pro Shardman?
Partitioning and sharding are two different layers of data separation in Postgres Pro Shardman:
Sharding is a distribution of a table across nodes of a cluster. The data is physically divided between shards of the Postgres Pro Shardman cluster.
Partitioning is a logical division of a table inside a single server. The data is stored on the same server, it is just divided into multiple local files.
- What is the difference between the multiplexor in Postgres Pro Shardman and postgres_fdw?
postgres_fdw uses one process per client. In case of a distributed database,
Mconnections toNshards sum up toN*Mconnections. This adds significant overhead due to processor context switching and memory usage. Besides, postgres_fdw was not effective — to process a simple query, it consecutively sent at least five requests and used suboptimal text format for data exchange.The Postgres Pro Shardman multiplexor uses a fixed number of node workers. Local backends communicate with the main routing/multiplexing process using fast shared memory. Multiplexors on the servers use a single network connection. Thus, the total number of connections in a cluster is reduced to (
N* (N- 1) +M). For more information, refer to Section 54.3.- Can Postgres Pro Shardman be deployed in several data centers?
Multi-DC deployments require a fast network between the data centers with pings below 5 ms, preferably dark fiber.
- Is it recommended to use a load balancer between my application and a Postgres Pro Shardman cluster, for example pgbouncer?
Generally, it is recommended to use a connection pooler for optimal use of resources and database connections. You can use Postgres Pro Shardman with a connection pooler. However, considering that Postgres Pro Shardman is a horizontally scaled system, using a connection pooler is not always justified. It all depends on the workload.
- How does Postgres Pro Shardman use CSN to solve the time drift issue?
Postgres Pro Shardman uses the csn_commit_delay parameter to introduce an artificial delay, in nanoseconds. If a transaction is committed on the node which system clock is ahead, this delay makes the nodes with the slower system clock wait for their local time to match the start time of the transaction. It guarantees that this transaction is in the past for any reader, preventing the stale read anomaly. If the time drift between the servers is less than the network packet travel speed, the artificial delay is not required.
- What isolation levels does Postgres Pro Shardman support?
Postgres Pro Shardman supports the following isolation levels:
READ COMMITTED. When a transaction uses this isolation level, aSELECTquery (without aFOR UPDATE/SHAREclause) sees only data committed before the query began; it never sees either uncommitted data or changes committed by concurrent transactions during the query's execution.REPEATABLE READ. The default isolation level. This level is different from Read Committed in that a query in a repeatable read transaction sees a snapshot as of the start of the first non-transaction-control statement in the transaction, not as of the start of the current statement within the transaction.
- Does Postgres Pro Shardman support the Serializable isolation level?
Postgres Pro Shardman does not support the Serializable isolation level for cross-shard operations.
- How do two-phase commits (2PC) actually work?
A two-phase commit in Postgres Pro Shardman works like this:
Prepare stage. The coordinator starts a transaction on all involved shards. Each shard performs the required operations and goes to the ready state (
PREPARE TRANSACTION), writing changes to its local log (WAL).Commit stage. If all participants successfully complete
PREPARE TRANSACTION, the coordinator makes the decision to commit the transaction. The coordinator first records the commit decision in its own log (WAL/CLOG). It then instructs the shards to commit their transactions usingCOMMIT PREPARED.
Failure handling:
If the coordinator fails after committing the transaction on its side, the transaction status is preserved in its log. Upon recovery, it uses this information to restore the status of the transaction on its node.
The shards, which transactions remain in the prepared state (in-doubt), periodically request the status of the transaction from the coordinator. If the coordinator confirms that the transaction was committed, they complete it (
COMMIT PREPARED). Otherwise, they roll the transaction back (ROLLBACK PREPARED).
This mechanism guarantees atomicity and consistency in distributed transactions if the coordinator is available to resolve the statuses of pending transactions.
- How does Postgres Pro Shardman solve the issue of pending distributed transactions when one of the nodes fails during the two-phase commit (2PC)?
Postgres Pro Shardman runs a background process on each shard — a monitor. It periodically scans the cluster and checks the status of prepared transactions in the
InDoubtstate. The monitor completes the transaction automatically (commit or rollback) as soon as the failed node goes online.- What happens to ongoing insert operations when I rebalance the load or add a shard?
The process of resharding ends with changing metadata that atomically switches the node for storing data. Until that moment, the client is not aware of the configuration change and continues to insert data into the old node. When Postgres Pro Shardman changes the metadata, the partition gets locked for write operations for a short period of time, and such operations return an error message that a partition is being moved. After the metadata change, the partition is immediately moved to the new node. No race condition occurs.
- Does Postgres Pro Shardman have a limit to requests per second (RPS)?
In general, Postgres Pro Shardman copes well with hundreds of thousands of RPS on dozens of shards. However, the result depends on the workload type.
- Is there a limit to the number of sessions in a single shard?
Theoretically, you can set max_connections up to
262143. But in practice, the maximum number of connections to a single shard should be around 10,000.