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
This commit is contained in:
Fujii Masao 2020-04-03 12:15:56 +09:00
parent 9d8ef98800
commit 18808f8c89
4 changed files with 29 additions and 5 deletions

View File

@ -1346,7 +1346,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<entry>Waiting in an extension.</entry> <entry>Waiting in an extension.</entry>
</row> </row>
<row> <row>
<entry morerows="38"><literal>IPC</literal></entry> <entry morerows="40"><literal>IPC</literal></entry>
<entry><literal>BackupWaitWalArchive</literal></entry> <entry><literal>BackupWaitWalArchive</literal></entry>
<entry>Waiting for WAL files required for the backup to be successfully archived.</entry> <entry>Waiting for WAL files required for the backup to be successfully archived.</entry>
</row> </row>
@ -1482,6 +1482,14 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
<entry><literal>Promote</literal></entry> <entry><literal>Promote</literal></entry>
<entry>Waiting for standby promotion.</entry> <entry>Waiting for standby promotion.</entry>
</row> </row>
<row>
<entry><literal>RecoveryConflictSnapshot</literal></entry>
<entry>Waiting for recovery conflict resolution on a vacuum cleanup.</entry>
</row>
<row>
<entry><literal>RecoveryConflictTablespace</literal></entry>
<entry>Waiting for recovery conflict resolution on dropping tablespace.</entry>
</row>
<row> <row>
<entry><literal>RecoveryPause</literal></entry> <entry><literal>RecoveryPause</literal></entry>
<entry>Waiting for recovery to be resumed.</entry> <entry>Waiting for recovery to be resumed.</entry>

View File

@ -3852,6 +3852,12 @@ pgstat_get_wait_ipc(WaitEventIPC w)
case WAIT_EVENT_PROMOTE: case WAIT_EVENT_PROMOTE:
event_name = "Promote"; event_name = "Promote";
break; 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: case WAIT_EVENT_RECOVERY_PAUSE:
event_name = "RecoveryPause"; event_name = "RecoveryPause";
break; break;

View File

@ -43,7 +43,9 @@ int max_standby_streaming_delay = 30 * 1000;
static HTAB *RecoveryLockLists; static HTAB *RecoveryLockLists;
static void ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, 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 void SendRecoveryConflictWithBufferPin(ProcSignalReason reason);
static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts); static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts);
static void LogAccessExclusiveLocks(int nlocks, xl_standby_lock *locks); 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. * more then we return true, if we can wait some more return false.
*/ */
static bool static bool
WaitExceedsMaxStandbyDelay(void) WaitExceedsMaxStandbyDelay(uint32 wait_event_info)
{ {
TimestampTz ltime; TimestampTz ltime;
@ -198,7 +200,9 @@ WaitExceedsMaxStandbyDelay(void)
/* /*
* Sleep a bit (this is essential to avoid busy-waiting). * Sleep a bit (this is essential to avoid busy-waiting).
*/ */
pgstat_report_wait_start(wait_event_info);
pg_usleep(standbyWait_us); pg_usleep(standbyWait_us);
pgstat_report_wait_end();
/* /*
* Progressively increase the sleep times, but not to more than 1s, since * Progressively increase the sleep times, but not to more than 1s, since
@ -223,7 +227,8 @@ WaitExceedsMaxStandbyDelay(void)
*/ */
static void static void
ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist, ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
ProcSignalReason reason, bool report_waiting) ProcSignalReason reason, uint32 wait_event_info,
bool report_waiting)
{ {
TimestampTz waitStart = 0; TimestampTz waitStart = 0;
char *new_status; char *new_status;
@ -264,7 +269,7 @@ ResolveRecoveryConflictWithVirtualXIDs(VirtualTransactionId *waitlist,
} }
/* Is it time to kill it? */ /* Is it time to kill it? */
if (WaitExceedsMaxStandbyDelay()) if (WaitExceedsMaxStandbyDelay(wait_event_info))
{ {
pid_t pid; pid_t pid;
@ -317,6 +322,7 @@ ResolveRecoveryConflictWithSnapshot(TransactionId latestRemovedXid, RelFileNode
ResolveRecoveryConflictWithVirtualXIDs(backends, ResolveRecoveryConflictWithVirtualXIDs(backends,
PROCSIG_RECOVERY_CONFLICT_SNAPSHOT, PROCSIG_RECOVERY_CONFLICT_SNAPSHOT,
WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT,
true); true);
} }
@ -346,6 +352,7 @@ ResolveRecoveryConflictWithTablespace(Oid tsid)
InvalidOid); InvalidOid);
ResolveRecoveryConflictWithVirtualXIDs(temp_file_users, ResolveRecoveryConflictWithVirtualXIDs(temp_file_users,
PROCSIG_RECOVERY_CONFLICT_TABLESPACE, PROCSIG_RECOVERY_CONFLICT_TABLESPACE,
WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE,
true); true);
} }
@ -417,6 +424,7 @@ ResolveRecoveryConflictWithLock(LOCKTAG locktag)
*/ */
ResolveRecoveryConflictWithVirtualXIDs(backends, ResolveRecoveryConflictWithVirtualXIDs(backends,
PROCSIG_RECOVERY_CONFLICT_LOCK, PROCSIG_RECOVERY_CONFLICT_LOCK,
PG_WAIT_LOCK | locktag.locktag_type,
false); false);
} }
else else

View File

@ -881,6 +881,8 @@ typedef enum
WAIT_EVENT_PARALLEL_FINISH, WAIT_EVENT_PARALLEL_FINISH,
WAIT_EVENT_PROCARRAY_GROUP_UPDATE, WAIT_EVENT_PROCARRAY_GROUP_UPDATE,
WAIT_EVENT_PROMOTE, WAIT_EVENT_PROMOTE,
WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT,
WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE,
WAIT_EVENT_RECOVERY_PAUSE, WAIT_EVENT_RECOVERY_PAUSE,
WAIT_EVENT_REPLICATION_ORIGIN_DROP, WAIT_EVENT_REPLICATION_ORIGIN_DROP,
WAIT_EVENT_REPLICATION_SLOT_DROP, WAIT_EVENT_REPLICATION_SLOT_DROP,