diff options
author | Fujii Masao <fujii@postgresql.org> | 2020-04-03 12:15:56 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2020-04-03 12:15:56 +0900 |
commit | 18808f8c893d4f425f2d21b2a1ffc8e51f1bd0ba (patch) | |
tree | d3a4609106e7d0b9a1619e0a6dd45a89b5e8f5d4 /src | |
parent | 9d8ef98800bd291de145fb1be41f0868546e02ab (diff) | |
download | postgresql-18808f8c893d4f425f2d21b2a1ffc8e51f1bd0ba.tar.gz postgresql-18808f8c893d4f425f2d21b2a1ffc8e51f1bd0ba.zip |
Add wait events for recovery conflicts.
This commit introduces new wait events RecoveryConflictSnapshot and
RecoveryConflictTablespace. The former is reported while waiting for
recovery conflict resolution on a vacuum cleanup. The latter is reported
while waiting for recovery conflict resolution on dropping tablespace.
Also this commit changes the code so that the wait event Lock is reported
while waiting in ResolveRecoveryConflictWithVirtualXIDs() for recovery
conflict resolution on a lock. Basically the wait event Lock is reported
during that wait, but previously was not reported only when that wait
happened in ResolveRecoveryConflictWithVirtualXIDs().
Author: Masahiko Sawada
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/CA+fd4k4mXWTwfQLS3RPwGr4xnfAEs1ysFfgYHvmmoUgv6Zxvmg@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/postmaster/pgstat.c | 6 | ||||
-rw-r--r-- | src/backend/storage/ipc/standby.c | 16 | ||||
-rw-r--r-- | src/include/pgstat.h | 2 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 04274056ca7..9ebde47dea9 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -3852,6 +3852,12 @@ pgstat_get_wait_ipc(WaitEventIPC w) case WAIT_EVENT_PROMOTE: event_name = "Promote"; break; + case WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT: + event_name = "RecoveryConflictSnapshot"; + break; + case WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE: + event_name = "RecoveryConflictTablespace"; + break; case WAIT_EVENT_RECOVERY_PAUSE: event_name = "RecoveryPause"; break; diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index 08f695a9805..bdaf10a4b1f 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -43,7 +43,9 @@ int max_standby_streaming_delay = 30 * 1000; static HTAB *RecoveryLockLists; static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, - ProcSignalReason reason, bool report_waiting); + ProcSignalReason reason, + uint32 wait_event_info, + bool report_waiting); static void SendRecoveryConflictWithBufferPin(ProcSignalReason reason); static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts); static void LogAccessExclusiveLocks(int nlocks, xl_standby_lock *locks); @@ -184,7 +186,7 @@ static int standbyWait_us = STANDBY_INITIAL_WAIT_US; * more then we return true, if we can wait some more return false. */ static bool -WaitExceedsMaxStandbyDelay(void) +WaitExceedsMaxStandbyDelay(uint32 wait_event_info) { TimestampTz ltime; @@ -198,7 +200,9 @@ WaitExceedsMaxStandbyDelay(void) /* * Sleep a bit (this is essential to avoid busy-waiting). */ + pgstat_report_wait_start(wait_event_info); pg_usleep(standbyWait_us); + pgstat_report_wait_end(); /* * Progressively increase the sleep times, but not to more than 1s, since @@ -223,7 +227,8 @@ WaitExceedsMaxStandbyDelay(void) */ static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, - ProcSignalReason reason, bool report_waiting) + ProcSignalReason reason, uint32 wait_event_info, + bool report_waiting) { TimestampTz waitStart = 0; char *new_status; @@ -264,7 +269,7 @@ ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, } /* Is it time to kill it? */ - if (WaitExceedsMaxStandbyDelay()) + if (WaitExceedsMaxStandbyDelay(wait_event_info)) { pid_t pid; @@ -317,6 +322,7 @@ ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode ResolveRecoveryConflictWithVirtualXIDs(backends, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, + WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT, true); } @@ -346,6 +352,7 @@ ResolveRecoveryConflictWithTablespace(Oid tsid) InvalidOid); ResolveRecoveryConflictWithVirtualXIDs(temp_file_users, PROCSIG_RECOVERY_CONFLICT_TABLESPACE, + WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE, true); } @@ -417,6 +424,7 @@ ResolveRecoveryConflictWithLock(LOCKTAG locktag) */ ResolveRecoveryConflictWithVirtualXIDs(backends, PROCSIG_RECOVERY_CONFLICT_LOCK, + PG_WAIT_LOCK | locktag.locktag_type, false); } else diff --git a/src/include/pgstat.h b/src/include/pgstat.h index 9d351e77145..b8041d99880 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -881,6 +881,8 @@ typedef enum WAIT_EVENT_PARALLEL_FINISH, WAIT_EVENT_PROCARRAY_GROUP_UPDATE, WAIT_EVENT_PROMOTE, + WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT, + WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE, WAIT_EVENT_RECOVERY_PAUSE, WAIT_EVENT_REPLICATION_ORIGIN_DROP, WAIT_EVENT_REPLICATION_SLOT_DROP, |