diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/main/main.c | 2 | ||||
-rw-r--r-- | src/backend/port/sysv_shmem.c | 1 | ||||
-rw-r--r-- | src/backend/postmaster/postmaster.c | 30 | ||||
-rw-r--r-- | src/backend/utils/init/miscinit.c | 29 |
4 files changed, 50 insertions, 12 deletions
diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 09f99486e01..87b7d3bf65c 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -169,7 +169,7 @@ main(int argc, char *argv[]) } if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) { - puts("postgres (PostgreSQL) " PG_VERSION); + fputs(PG_BACKEND_VERSIONSTR, stdout); exit(0); } diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 273d1313b00..e8cf6d3e936 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -38,6 +38,7 @@ #include "storage/ipc.h" #include "storage/pg_shmem.h" #include "utils/guc.h" +#include "utils/pidfile.h" /* diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 2874f635af3..5f4dd689410 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -125,6 +125,7 @@ #include "utils/datetime.h" #include "utils/dynamic_loader.h" #include "utils/memutils.h" +#include "utils/pidfile.h" #include "utils/ps_status.h" #include "utils/timeout.h" #include "utils/varlena.h" @@ -1341,6 +1342,12 @@ PostmasterMain(int argc, char *argv[]) #endif /* + * Report postmaster status in the postmaster.pid file, to allow pg_ctl to + * see what's happening. + */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STARTING); + + /* * We're ready to rock and roll... */ StartupPID = StartupDataBase(); @@ -2608,6 +2615,9 @@ pmdie(SIGNAL_ARGS) Shutdown = SmartShutdown; ereport(LOG, (errmsg("received smart shutdown request"))); + + /* Report status */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STOPPING); #ifdef USE_SYSTEMD sd_notify(0, "STOPPING=1"); #endif @@ -2663,6 +2673,9 @@ pmdie(SIGNAL_ARGS) Shutdown = FastShutdown; ereport(LOG, (errmsg("received fast shutdown request"))); + + /* Report status */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STOPPING); #ifdef USE_SYSTEMD sd_notify(0, "STOPPING=1"); #endif @@ -2727,6 +2740,9 @@ pmdie(SIGNAL_ARGS) Shutdown = ImmediateShutdown; ereport(LOG, (errmsg("received immediate shutdown request"))); + + /* Report status */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STOPPING); #ifdef USE_SYSTEMD sd_notify(0, "STOPPING=1"); #endif @@ -2872,6 +2888,8 @@ reaper(SIGNAL_ARGS) ereport(LOG, (errmsg("database system is ready to accept connections"))); + /* Report status */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_READY); #ifdef USE_SYSTEMD sd_notify(0, "READY=1"); #endif @@ -5005,10 +5023,18 @@ sigusr1_handler(SIGNAL_ARGS) if (XLogArchivingAlways()) PgArchPID = pgarch_start(); -#ifdef USE_SYSTEMD + /* + * If we aren't planning to enter hot standby mode later, treat + * RECOVERY_STARTED as meaning we're out of startup, and report status + * accordingly. + */ if (!EnableHotStandby) + { + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_STANDBY); +#ifdef USE_SYSTEMD sd_notify(0, "READY=1"); #endif + } pmState = PM_RECOVERY; } @@ -5024,6 +5050,8 @@ sigusr1_handler(SIGNAL_ARGS) ereport(LOG, (errmsg("database system is ready to accept read only connections"))); + /* Report status */ + AddToDataDirLockFile(LOCK_FILE_LINE_PM_STATUS, PM_STATUS_READY); #ifdef USE_SYSTEMD sd_notify(0, "READY=1"); #endif diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 49a6afafe7f..afbf8f86919 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -47,6 +47,7 @@ #include "utils/builtins.h" #include "utils/guc.h" #include "utils/memutils.h" +#include "utils/pidfile.h" #include "utils/syscache.h" #include "utils/varlena.h" @@ -1149,8 +1150,9 @@ TouchSocketLockFiles(void) * * Note: because we don't truncate the file, if we were to rewrite a line * with less data than it had before, there would be garbage after the last - * line. We don't ever actually do that, so not worth adding another kernel - * call to cover the possibility. + * line. While we could fix that by adding a truncate call, that would make + * the file update non-atomic, which we'd rather avoid. Therefore, callers + * should endeavor never to shorten a line once it's been written. */ void AddToDataDirLockFile(int target_line, const char *str) @@ -1193,19 +1195,26 @@ AddToDataDirLockFile(int target_line, const char *str) srcptr = srcbuffer; for (lineno = 1; lineno < target_line; lineno++) { - if ((srcptr = strchr(srcptr, '\n')) == NULL) - { - elog(LOG, "incomplete data in \"%s\": found only %d newlines while trying to add line %d", - DIRECTORY_LOCK_FILE, lineno - 1, target_line); - close(fd); - return; - } - srcptr++; + char *eol = strchr(srcptr, '\n'); + + if (eol == NULL) + break; /* not enough lines in file yet */ + srcptr = eol + 1; } memcpy(destbuffer, srcbuffer, srcptr - srcbuffer); destptr = destbuffer + (srcptr - srcbuffer); /* + * Fill in any missing lines before the target line, in case lines are + * added to the file out of order. + */ + for (; lineno < target_line; lineno++) + { + if (destptr < destbuffer + sizeof(destbuffer)) + *destptr++ = '\n'; + } + + /* * Write or rewrite the target line. */ snprintf(destptr, destbuffer + sizeof(destbuffer) - destptr, "%s\n", str); |