From 0f5ca02f53ac2b211d8518f0882c49284c0c9610 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Tue, 7 Apr 2020 23:51:10 +0300 Subject: Implement waiting for given lsn at transaction start This commit adds following optional clause to BEGIN and START TRANSACTION commands. WAIT FOR LSN lsn [ TIMEOUT timeout ] New clause pospones transaction start till given lsn is applied on standby. This clause allows user be sure, that changes previously made on primary would be visible on standby. New shared memory struct is used to track awaited lsn per backend. Recovery process wakes up backend once required lsn is applied. Author: Ivan Kartyshov, Anna Akenteva Reviewed-by: Craig Ringer, Thomas Munro, Robert Haas, Kyotaro Horiguchi Reviewed-by: Masahiko Sawada, Ants Aasma, Dmitry Ivanov, Simon Riggs Reviewed-by: Amit Kapila, Alexander Korotkov Discussion: https://postgr.es/m/0240c26c-9f84-30ea-fca9-93ab2df5f305%40postgrespro.ru --- doc/src/sgml/ref/begin.sgml | 17 ++++++++++++++++- doc/src/sgml/ref/start_transaction.sgml | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/begin.sgml b/doc/src/sgml/ref/begin.sgml index c23bbfb4e71..66d9ad7cb23 100644 --- a/doc/src/sgml/ref/begin.sgml +++ b/doc/src/sgml/ref/begin.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation -BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ] +BEGIN [ WORK | TRANSACTION ] [ transaction_mode [, ...] ] [ WAIT FOR LSN lsn_value [TIMEOUT number_of_milliseconds ] ] where transaction_mode is one of: @@ -63,6 +63,17 @@ BEGIN [ WORK | TRANSACTION ] [ transaction_mode was executed. + + + The WAIT FOR clause allows to wait for the target log + sequence number (LSN) to be replayed on standby before + starting the transaction in PostgreSQL databases + with master-standby asynchronous replication. Wait time can be limited by + specifying a timeout, which is measured in milliseconds and must be a positive + integer. If LSN was not reached before timeout, transaction + doesn't begin. Waiting can be interrupted by cancelling + BEGIN command. + @@ -146,6 +157,10 @@ BEGIN; different purpose in embedded SQL. You are advised to be careful about the transaction semantics when porting database applications. + + + There is no WAIT FOR clause in the SQL standard. + diff --git a/doc/src/sgml/ref/start_transaction.sgml b/doc/src/sgml/ref/start_transaction.sgml index d6cd1d41779..b94ab00b403 100644 --- a/doc/src/sgml/ref/start_transaction.sgml +++ b/doc/src/sgml/ref/start_transaction.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation -START TRANSACTION [ transaction_mode [, ...] ] +START TRANSACTION [ transaction_mode [, ...] ] [ WAIT FOR LSN lsn_value [TIMEOUT number_of_milliseconds ] ] where transaction_mode is one of: @@ -40,6 +40,17 @@ START TRANSACTION [ transaction_mode was executed. This is the same as the command. + + + The WAIT FOR clause allows to wait for the target log + sequence number (LSN) to be replayed on standby before + starting the transaction in PostgreSQL databases + with master-standby asynchronous replication. Wait time can be limited by + specifying a timeout, which is measured in milliseconds and must be a positive + integer. If LSN was not reached before timeout, transaction + doesn't begin. Waiting can be interrupted by cancelling + START TRANSACTION command. + @@ -78,6 +89,10 @@ START TRANSACTION [ transaction_mode + + There is no WAIT FOR clause in the SQL standard. + + See also the compatibility section of . -- cgit v1.2.3