1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Report progress of startup operations that take a long time.

Users sometimes get concerned whe they start the server and it
emits a few messages and then doesn't emit any more messages for
a long time. Generally, what's happening is either that the
system is taking a long time to apply WAL, or it's taking a
long time to reset unlogged relations, or it's taking a long
time to fsync the data directory, but it's not easy to tell
which is the case.

To fix that, add a new 'log_startup_progress_interval' setting,
by default 10s. When an operation that is known to be potentially
long-running takes more than this amount of time, we'll log a
status update each time this interval elapses.

To avoid undesirable log chatter, don't log anything about WAL
replay when in standby mode.

Nitin Jadhav and Robert Haas, reviewed by Amul Sul, Bharath
Rupireddy, Justin Pryzby, Michael Paquier, and Álvaro Herrera.

Discussion: https://postgr.es/m/CA+TgmoaHQrgDFOBwgY16XCoMtXxsrVGFB2jNCvb7-ubuEe1MGg@mail.gmail.com
Discussion: https://postgr.es/m/CAMm1aWaHF7VE69572_OLQ+MgpT5RUiUDgF1x5RrtkJBLdpRj3Q@mail.gmail.com
This commit is contained in:
Robert Haas
2021-10-25 11:51:57 -04:00
parent 732e6677a6
commit 9ce346eabf
10 changed files with 181 additions and 3 deletions

View File

@ -96,6 +96,7 @@
#include "pgstat.h"
#include "port/pg_iovec.h"
#include "portability/mem.h"
#include "postmaster/startup.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "utils/guc.h"
@ -3381,6 +3382,9 @@ do_syncfs(const char *path)
{
int fd;
ereport_startup_progress("syncing data directory (syncfs), elapsed time: %ld.%02d s, current path: %s",
path);
fd = OpenTransientFile(path, O_RDONLY);
if (fd < 0)
{
@ -3465,6 +3469,9 @@ SyncDataDirectory(void)
* directories.
*/
/* Prepare to report progress syncing the data directory via syncfs. */
begin_startup_progress_phase();
/* Sync the top level pgdata directory. */
do_syncfs(".");
/* If any tablespaces are configured, sync each of those. */
@ -3487,18 +3494,24 @@ SyncDataDirectory(void)
}
#endif /* !HAVE_SYNCFS */
#ifdef PG_FLUSH_DATA_WORKS
/* Prepare to report progress of the pre-fsync phase. */
begin_startup_progress_phase();
/*
* If possible, hint to the kernel that we're soon going to fsync the data
* directory and its contents. Errors in this step are even less
* interesting than normal, so log them only at DEBUG1.
*/
#ifdef PG_FLUSH_DATA_WORKS
walkdir(".", pre_sync_fname, false, DEBUG1);
if (xlog_is_symlink)
walkdir("pg_wal", pre_sync_fname, false, DEBUG1);
walkdir("pg_tblspc", pre_sync_fname, true, DEBUG1);
#endif
/* Prepare to report progress syncing the data directory via fsync. */
begin_startup_progress_phase();
/*
* Now we do the fsync()s in the same order.
*
@ -3601,6 +3614,9 @@ pre_sync_fname(const char *fname, bool isdir, int elevel)
if (isdir)
return;
ereport_startup_progress("syncing data directory (pre-fsync), elapsed time: %ld.%02d s, current path: %s",
fname);
fd = OpenTransientFile(fname, O_RDONLY | PG_BINARY);
if (fd < 0)
@ -3630,6 +3646,9 @@ pre_sync_fname(const char *fname, bool isdir, int elevel)
static void
datadir_fsync_fname(const char *fname, bool isdir, int elevel)
{
ereport_startup_progress("syncing data directory (fsync), elapsed time: %ld.%02d s, current path: %s",
fname);
/*
* We want to silently ignoring errors about unreadable files. Pass that
* desire on to fsync_fname_ext().