mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Create and use wait events for read, write, and fsync operations.
Previous commits, notably53be0b1add
and6f3bd98ebf
, made it possible to see from pg_stat_activity when a backend was stuck waiting for another backend, but it's also fairly common for a backend to be stuck waiting for an I/O. Add wait events for those operations, too. Rushabh Lathia, with further hacking by me. Reviewed and tested by Michael Paquier, Amit Kapila, Rajkumar Raghuwanshi, and Rahila Syed. Discussion: http://postgr.es/m/CAGPqQf0LsYHXREPAZqYGVkDqHSyjf=KsD=k0GTVPAuzyThh-VQ@mail.gmail.com
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include "access/xlog_internal.h"
|
||||
#include "common/string.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "replication/slot.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/proc.h"
|
||||
@@ -1100,10 +1101,12 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
||||
SnapBuildOnDiskChecksummedSize);
|
||||
FIN_CRC32C(cp.checksum);
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_WRITE);
|
||||
if ((write(fd, &cp, sizeof(cp))) != sizeof(cp))
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
pgstat_report_wait_end();
|
||||
CloseTransientFile(fd);
|
||||
errno = save_errno;
|
||||
ereport(elevel,
|
||||
@@ -1112,12 +1115,15 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
||||
tmppath)));
|
||||
return;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
/* fsync the temporary file */
|
||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_SYNC);
|
||||
if (pg_fsync(fd) != 0)
|
||||
{
|
||||
int save_errno = errno;
|
||||
|
||||
pgstat_report_wait_end();
|
||||
CloseTransientFile(fd);
|
||||
errno = save_errno;
|
||||
ereport(elevel,
|
||||
@@ -1126,6 +1132,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
|
||||
tmppath)));
|
||||
return;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
CloseTransientFile(fd);
|
||||
|
||||
@@ -1202,6 +1209,7 @@ RestoreSlotFromDisk(const char *name)
|
||||
* Sync state file before we're reading from it. We might have crashed
|
||||
* while it wasn't synced yet and we shouldn't continue on that basis.
|
||||
*/
|
||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC);
|
||||
if (pg_fsync(fd) != 0)
|
||||
{
|
||||
CloseTransientFile(fd);
|
||||
@@ -1210,6 +1218,7 @@ RestoreSlotFromDisk(const char *name)
|
||||
errmsg("could not fsync file \"%s\": %m",
|
||||
path)));
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
/* Also sync the parent directory */
|
||||
START_CRIT_SECTION();
|
||||
@@ -1217,7 +1226,9 @@ RestoreSlotFromDisk(const char *name)
|
||||
END_CRIT_SECTION();
|
||||
|
||||
/* read part of statefile that's guaranteed to be version independent */
|
||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_READ);
|
||||
readBytes = read(fd, &cp, ReplicationSlotOnDiskConstantSize);
|
||||
pgstat_report_wait_end();
|
||||
if (readBytes != ReplicationSlotOnDiskConstantSize)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
@@ -1253,9 +1264,11 @@ RestoreSlotFromDisk(const char *name)
|
||||
path, cp.length)));
|
||||
|
||||
/* Now that we know the size, read the entire file */
|
||||
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_READ);
|
||||
readBytes = read(fd,
|
||||
(char *) &cp + ReplicationSlotOnDiskConstantSize,
|
||||
cp.length);
|
||||
pgstat_report_wait_end();
|
||||
if (readBytes != cp.length)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
|
Reference in New Issue
Block a user