mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
Create and use wait events for read, write, and fsync operations.
Previous commits, notably53be0b1addand6f3bd98ebf, 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:
@@ -38,6 +38,7 @@
|
||||
#include "access/xlog.h"
|
||||
#include "access/xlog_internal.h"
|
||||
#include "access/xlogdefs.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/fd.h"
|
||||
|
||||
/*
|
||||
@@ -338,7 +339,9 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
|
||||
for (;;)
|
||||
{
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_READ);
|
||||
nbytes = (int) read(srcfd, buffer, sizeof(buffer));
|
||||
pgstat_report_wait_end();
|
||||
if (nbytes < 0 || errno != 0)
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
@@ -346,6 +349,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
|
||||
if (nbytes == 0)
|
||||
break;
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_WRITE);
|
||||
if ((int) write(fd, buffer, nbytes) != nbytes)
|
||||
{
|
||||
int save_errno = errno;
|
||||
@@ -365,6 +369,7 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write to file \"%s\": %m", tmppath)));
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
}
|
||||
CloseTransientFile(srcfd);
|
||||
}
|
||||
@@ -400,10 +405,12 @@ writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
|
||||
errmsg("could not write to file \"%s\": %m", tmppath)));
|
||||
}
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_SYNC);
|
||||
if (pg_fsync(fd) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (CloseTransientFile(fd))
|
||||
ereport(ERROR,
|
||||
@@ -460,6 +467,7 @@ writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
|
||||
errmsg("could not create file \"%s\": %m", tmppath)));
|
||||
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE);
|
||||
if ((int) write(fd, content, size) != size)
|
||||
{
|
||||
int save_errno = errno;
|
||||
@@ -475,11 +483,14 @@ writeTimeLineHistoryFile(TimeLineID tli, char *content, int size)
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write to file \"%s\": %m", tmppath)));
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
pgstat_report_wait_start(WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC);
|
||||
if (pg_fsync(fd) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not fsync file \"%s\": %m", tmppath)));
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (CloseTransientFile(fd))
|
||||
ereport(ERROR,
|
||||
|
||||
Reference in New Issue
Block a user