LSN
A sequence-number mechanism in the database transaction log that identifies the order of log records. In Hyperscale it is used to determine data page versions and the consistency point for reads.
Timeline (last 90 days)
The WAIT FOR LSN command makes a standby block and wait until its replay progress reaches or exceeds the specified LSN.
WAL (Write-Ahead Logging) is the core mechanism by which PostgreSQL guarantees transactional durability and replication consistency, and each WAL record has a unique LSN (Log Sequence Number), formatted like 0/0306EE20.
In the example, after a write operation completes, the application can call pg_current_wal_insert_lsn() to obtain the LSN (for example 0/0306EE20); subsequent requests run WAIT FOR LSN '0/0306EE20' WITH (TIMEOUT '0.1s') before executing a query on the standby, and perform the read operation only after the standby has replayed WAL up to the specified LSN.
The mechanisms in MySQL equivalent to WAIT FOR LSN are WAIT_FOR_EXECUTED_GTID_SET() and MASTER_POS_WAIT(); although PostgreSQL has no GTID, the WAL LSN provides an equivalent monotonically advancing position identifier, and WAIT FOR LSN is semantically highly similar to MASTER_POS_WAIT().
For scenarios where session state cannot be maintained (such as stateless HTTP requests), putting the LSN in a cookie is a feasible approach, but security and expiration policies need to be considered.
All Facts (5)
The WAIT FOR LSN command makes a standby block and wait until its replay progress reaches or exceeds the specified LSN.
50%UnverifiedWAL (Write-Ahead Logging) is the core mechanism by which PostgreSQL guarantees transactional durability and replication consistency, and each WAL record has a unique LSN (Log Sequence Number), formatted like 0/0306EE20.
50%UnverifiedIn the example, after a write operation completes, the application can call pg_current_wal_insert_lsn() to obtain the LSN (for example 0/0306EE20); subsequent requests run WAIT FOR LSN '0/0306EE20' WITH (TIMEOUT '0.1s') before executing a query on the standby, and perform the read operation only after the standby has replayed WAL up to the specified LSN.
50%UnverifiedThe mechanisms in MySQL equivalent to WAIT FOR LSN are WAIT_FOR_EXECUTED_GTID_SET() and MASTER_POS_WAIT(); although PostgreSQL has no GTID, the WAL LSN provides an equivalent monotonically advancing position identifier, and WAIT FOR LSN is semantically highly similar to MASTER_POS_WAIT().
50%UnverifiedFor scenarios where session state cannot be maintained (such as stateless HTTP requests), putting the LSN in a cookie is a feasible approach, but security and expiration policies need to be considered.
50%