Skip to content

Commit 1b06d7b

Browse files
committed
Report wait events for local shell commands like archive_command.
This commit introduces new wait events for archive_command, archive_cleanup_command, restore_command and recovery_end_command. Author: Fujii Masao Reviewed-by: Bharath Rupireddy, Michael Paquier Discussion: https://postgr.es/m/4ca4f920-6b48-638d-08b2-93598356f5d3@oss.nttdata.com
1 parent 97f5aef commit 1b06d7b

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

doc/src/sgml/monitoring.sgml

+21-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,17 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
15691569
<entry>Waiting for subplan nodes of an <literal>Append</literal> plan
15701570
node to be ready.</entry>
15711571
</row>
1572-
<row>
1572+
<row>
1573+
<entry><literal>ArchiveCleanupCommand</literal></entry>
1574+
<entry>Waiting for <xref linkend="guc-archive-cleanup-command"/> to
1575+
complete.</entry>
1576+
</row>
1577+
<row>
1578+
<entry><literal>ArchiveCommand</literal></entry>
1579+
<entry>Waiting for <xref linkend="guc-archive-command"/> to
1580+
complete.</entry>
1581+
</row>
1582+
<row>
15731583
<entry><literal>BackendTermination</literal></entry>
15741584
<entry>Waiting for the termination of another backend.</entry>
15751585
</row>
@@ -1747,6 +1757,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
17471757
<entry>Waiting for recovery conflict resolution for dropping a
17481758
tablespace.</entry>
17491759
</row>
1760+
<row>
1761+
<entry><literal>RecoveryEndCommand</literal></entry>
1762+
<entry>Waiting for <xref linkend="guc-recovery-end-command"/> to
1763+
complete.</entry>
1764+
</row>
17501765
<row>
17511766
<entry><literal>RecoveryPause</literal></entry>
17521767
<entry>Waiting for recovery to be resumed.</entry>
@@ -1761,6 +1776,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
17611776
<entry>Waiting for a replication slot to become inactive so it can be
17621777
dropped.</entry>
17631778
</row>
1779+
<row>
1780+
<entry><literal>RestoreCommand</literal></entry>
1781+
<entry>Waiting for <xref linkend="guc-restore-command"/> to
1782+
complete.</entry>
1783+
</row>
17641784
<row>
17651785
<entry><literal>SafeSnapshot</literal></entry>
17661786
<entry>Waiting to obtain a valid snapshot for a <literal>READ ONLY

src/backend/access/transam/xlog.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -5800,7 +5800,8 @@ CleanupAfterArchiveRecovery(TimeLineID EndOfLogTLI, XLogRecPtr EndOfLog,
58005800
if (recoveryEndCommand && strcmp(recoveryEndCommand, "") != 0)
58015801
ExecuteRecoveryCommand(recoveryEndCommand,
58025802
"recovery_end_command",
5803-
true);
5803+
true,
5804+
WAIT_EVENT_RECOVERY_END_COMMAND);
58045805

58055806
/*
58065807
* We switched to a new timeline. Clean up segments on the old timeline.
@@ -9915,7 +9916,8 @@ CreateRestartPoint(int flags)
99159916
if (archiveCleanupCommand && strcmp(archiveCleanupCommand, "") != 0)
99169917
ExecuteRecoveryCommand(archiveCleanupCommand,
99179918
"archive_cleanup_command",
9918-
false);
9919+
false,
9920+
WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND);
99199921

99209922
return true;
99219923
}

src/backend/access/transam/xlogarchive.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "access/xlogarchive.h"
2525
#include "common/archive.h"
2626
#include "miscadmin.h"
27+
#include "pgstat.h"
2728
#include "postmaster/startup.h"
2829
#include "postmaster/pgarch.h"
2930
#include "replication/walsender.h"
@@ -168,7 +169,9 @@ RestoreArchivedFile(char *path, const char *xlogfname,
168169
/*
169170
* Copy xlog from archival storage to XLOGDIR
170171
*/
172+
pgstat_report_wait_start(WAIT_EVENT_RESTORE_COMMAND);
171173
rc = system(xlogRestoreCmd);
174+
pgstat_report_wait_end();
172175

173176
PostRestoreCommand();
174177
pfree(xlogRestoreCmd);
@@ -284,7 +287,8 @@ RestoreArchivedFile(char *path, const char *xlogfname,
284287
* This is currently used for recovery_end_command and archive_cleanup_command.
285288
*/
286289
void
287-
ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOnSignal)
290+
ExecuteRecoveryCommand(const char *command, const char *commandName,
291+
bool failOnSignal, uint32 wait_event_info)
288292
{
289293
char xlogRecoveryCmd[MAXPGPATH];
290294
char lastRestartPointFname[MAXPGPATH];
@@ -354,7 +358,10 @@ ExecuteRecoveryCommand(const char *command, const char *commandName, bool failOn
354358
/*
355359
* execute the constructed command
356360
*/
361+
pgstat_report_wait_start(wait_event_info);
357362
rc = system(xlogRecoveryCmd);
363+
pgstat_report_wait_end();
364+
358365
if (rc != 0)
359366
{
360367
/*

src/backend/postmaster/pgarch.c

+3
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ pgarch_archiveXlog(char *xlog)
555555
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
556556
set_ps_display(activitymsg);
557557

558+
pgstat_report_wait_start(WAIT_EVENT_ARCHIVE_COMMAND);
558559
rc = system(xlogarchcmd);
560+
pgstat_report_wait_end();
561+
559562
if (rc != 0)
560563
{
561564
/*

src/backend/utils/activity/wait_event.c

+12
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ pgstat_get_wait_ipc(WaitEventIPC w)
313313
case WAIT_EVENT_APPEND_READY:
314314
event_name = "AppendReady";
315315
break;
316+
case WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND:
317+
event_name = "ArchiveCleanupCommand";
318+
break;
319+
case WAIT_EVENT_ARCHIVE_COMMAND:
320+
event_name = "ArchiveCommand";
321+
break;
316322
case WAIT_EVENT_BACKEND_TERMINATION:
317323
event_name = "BackendTermination";
318324
break;
@@ -427,6 +433,9 @@ pgstat_get_wait_ipc(WaitEventIPC w)
427433
case WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE:
428434
event_name = "RecoveryConflictTablespace";
429435
break;
436+
case WAIT_EVENT_RECOVERY_END_COMMAND:
437+
event_name = "RecoveryEndCommand";
438+
break;
430439
case WAIT_EVENT_RECOVERY_PAUSE:
431440
event_name = "RecoveryPause";
432441
break;
@@ -436,6 +445,9 @@ pgstat_get_wait_ipc(WaitEventIPC w)
436445
case WAIT_EVENT_REPLICATION_SLOT_DROP:
437446
event_name = "ReplicationSlotDrop";
438447
break;
448+
case WAIT_EVENT_RESTORE_COMMAND:
449+
event_name = "RestoreCommand";
450+
break;
439451
case WAIT_EVENT_SAFE_SNAPSHOT:
440452
event_name = "SafeSnapshot";
441453
break;

src/include/access/xlogarchive.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern bool RestoreArchivedFile(char *path, const char *xlogfname,
2121
const char *recovername, off_t expectedSize,
2222
bool cleanupEnabled);
2323
extern void ExecuteRecoveryCommand(const char *command, const char *commandName,
24-
bool failOnSignal);
24+
bool failOnSignal, uint32 wait_event_info);
2525
extern void KeepFileRestoredFromArchive(const char *path, const char *xlogfname);
2626
extern void XLogArchiveNotify(const char *xlog);
2727
extern void XLogArchiveNotifySeg(XLogSegNo segno, TimeLineID tli);

src/include/utils/wait_event.h

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ typedef enum
8080
typedef enum
8181
{
8282
WAIT_EVENT_APPEND_READY = PG_WAIT_IPC,
83+
WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND,
84+
WAIT_EVENT_ARCHIVE_COMMAND,
8385
WAIT_EVENT_BACKEND_TERMINATION,
8486
WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE,
8587
WAIT_EVENT_BGWORKER_SHUTDOWN,
@@ -118,9 +120,11 @@ typedef enum
118120
WAIT_EVENT_PROMOTE,
119121
WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT,
120122
WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE,
123+
WAIT_EVENT_RECOVERY_END_COMMAND,
121124
WAIT_EVENT_RECOVERY_PAUSE,
122125
WAIT_EVENT_REPLICATION_ORIGIN_DROP,
123126
WAIT_EVENT_REPLICATION_SLOT_DROP,
127+
WAIT_EVENT_RESTORE_COMMAND,
124128
WAIT_EVENT_SAFE_SNAPSHOT,
125129
WAIT_EVENT_SYNC_REP,
126130
WAIT_EVENT_WAL_RECEIVER_EXIT,

0 commit comments

Comments
 (0)