diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2020-04-07 23:51:10 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2020-04-07 23:51:10 +0300 |
commit | 0f5ca02f53ac2b211d8518f0882c49284c0c9610 (patch) | |
tree | a5dce13eaa64e00a6ec95b913a155efe7f91c99c /src/backend/tcop/utility.c | |
parent | 357889eb17bb9c9336c4f324ceb1651da616fe57 (diff) | |
download | postgresql-0f5ca02f53ac2b211d8518f0882c49284c0c9610.tar.gz postgresql-0f5ca02f53ac2b211d8518f0882c49284c0c9610.zip |
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
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r-- | src/backend/tcop/utility.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index b1f7f6e2d01..f516bd22eae 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -57,6 +57,7 @@ #include "commands/user.h" #include "commands/vacuum.h" #include "commands/view.h" +#include "commands/wait.h" #include "miscadmin.h" #include "parser/parse_utilcmd.h" #include "postmaster/bgwriter.h" @@ -591,6 +592,18 @@ standard_ProcessUtility(PlannedStmt *pstmt, case TRANS_STMT_START: { ListCell *lc; + WaitClause *waitstmt = (WaitClause *) stmt->wait; + + /* WAIT FOR cannot be used on master */ + if (stmt->wait && !RecoveryInProgress()) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("WAIT FOR can only be " + "used on standby"))); + + /* If needed to WAIT FOR something but failed */ + if (stmt->wait && WaitLSNMain(waitstmt, dest) == 0) + break; BeginTransactionBlock(); foreach(lc, stmt->options) |