aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-02-11 14:14:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-02-11 14:14:22 -0500
commitd18643c4a6d5ac41b012abc5d11fb5a7ccddf6c5 (patch)
tree6a72cc98933386cf3a1b8330bfb83619cb5d7b88
parentc319991bcad02a2e99ddac3f42762b0f6fa8d52a (diff)
downloadpostgresql-d18643c4a6d5ac41b012abc5d11fb5a7ccddf6c5.tar.gz
postgresql-d18643c4a6d5ac41b012abc5d11fb5a7ccddf6c5.zip
Shift the responsibility for emitting "database system is shut down".
Historically this message has been emitted at the end of ShutdownXLOG(). That's not an insane place for it in a standalone backend, but in the postmaster environment we've grown a fair amount of stuff that happens later, including archiver/walsender shutdown, stats collector shutdown, etc. Recent buildfarm experimentation showed that on slower machines there could be many seconds' delay between finishing ShutdownXLOG() and actual postmaster exit. That's fairly confusing, both for testing purposes and for DBAs. Hence, move the code that prints this message into UnlinkLockFiles(), so that it comes out just after we remove the postmaster's pidfile. That is a more appropriate definition of "is shut down" from the point of view of "pg_ctl stop", for example. In general, removing the pidfile should be the last externally-visible action of either a postmaster or a standalone backend; compare commit d73d14c271653dff10c349738df79ea03b85236c for instance. So this seems like a reasonably future-proof approach.
-rw-r--r--src/backend/access/transam/xlog.c4
-rw-r--r--src/backend/utils/init/miscinit.c11
2 files changed, 11 insertions, 4 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a2846c41b58..07a7679479c 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -7948,10 +7948,6 @@ ShutdownXLOG(int code, Datum arg)
ShutdownCommitTs();
ShutdownSUBTRANS();
ShutdownMultiXact();
-
- /* Don't be chatty in standalone mode */
- ereport(IsPostmasterEnvironment ? LOG : NOTICE,
- (errmsg("database system is shut down")));
}
/*
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index b7bab56099f..603a2565b65 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -724,6 +724,17 @@ UnlinkLockFiles(int status, Datum arg)
}
/* Since we're about to exit, no need to reclaim storage */
lock_files = NIL;
+
+ /*
+ * Lock file removal should always be the last externally visible action
+ * of a postmaster or standalone backend, while we won't come here at all
+ * when exiting postmaster child processes. Therefore, this is a good
+ * place to log completion of shutdown. We could alternatively teach
+ * proc_exit() to do it, but that seems uglier. In a standalone backend,
+ * use NOTICE elevel to be less chatty.
+ */
+ ereport(IsPostmasterEnvironment ? LOG : NOTICE,
+ (errmsg("database system is shut down")));
}
/*