mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +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:
@@ -54,6 +54,7 @@
|
||||
#include "access/slru.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/xlog.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "miscadmin.h"
|
||||
@@ -675,13 +676,16 @@ SlruPhysicalReadPage(SlruCtl ctl, int pageno, int slotno)
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_READ);
|
||||
if (read(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
slru_errcause = SLRU_READ_FAILED;
|
||||
slru_errno = errno;
|
||||
CloseTransientFile(fd);
|
||||
return false;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (CloseTransientFile(fd))
|
||||
{
|
||||
@@ -834,8 +838,10 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_WRITE);
|
||||
if (write(fd, shared->page_buffer[slotno], BLCKSZ) != BLCKSZ)
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
/* if write didn't set errno, assume problem is no disk space */
|
||||
if (errno == 0)
|
||||
errno = ENOSPC;
|
||||
@@ -845,6 +851,7 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
|
||||
CloseTransientFile(fd);
|
||||
return false;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
/*
|
||||
* If not part of Flush, need to fsync now. We assume this happens
|
||||
@@ -852,13 +859,16 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
|
||||
*/
|
||||
if (!fdata)
|
||||
{
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_SYNC);
|
||||
if (ctl->do_fsync && pg_fsync(fd))
|
||||
{
|
||||
pgstat_report_wait_end();
|
||||
slru_errcause = SLRU_FSYNC_FAILED;
|
||||
slru_errno = errno;
|
||||
CloseTransientFile(fd);
|
||||
return false;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (CloseTransientFile(fd))
|
||||
{
|
||||
@@ -1126,6 +1136,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
|
||||
ok = true;
|
||||
for (i = 0; i < fdata.num_files; i++)
|
||||
{
|
||||
pgstat_report_wait_start(WAIT_EVENT_SLRU_FLUSH_SYNC);
|
||||
if (ctl->do_fsync && pg_fsync(fdata.fd[i]))
|
||||
{
|
||||
slru_errcause = SLRU_FSYNC_FAILED;
|
||||
@@ -1133,6 +1144,7 @@ SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
|
||||
pageno = fdata.segno[i] * SLRU_PAGES_PER_SEGMENT;
|
||||
ok = false;
|
||||
}
|
||||
pgstat_report_wait_end();
|
||||
|
||||
if (CloseTransientFile(fdata.fd[i]))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user