From ea0382e3706ab25935c733fd452d828832e4675f Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 26 Apr 2008 22:47:40 +0000 Subject: Code review for recent patch to terminate online backup during shutdown: do CancelBackup at a sane place, fix some oversights in the state transitions, allow only superusers to connect while we are waiting for backup mode to end. --- src/backend/utils/init/postinit.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/init/postinit.c') diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 6c29ea19174..695db95c726 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.182 2008/03/26 21:10:39 alvherre Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.183 2008/04/26 22:47:40 tgl Exp $ * * *------------------------------------------------------------------------- @@ -26,6 +26,7 @@ #include "catalog/pg_database.h" #include "catalog/pg_tablespace.h" #include "libpq/hba.h" +#include "libpq/libpq-be.h" #include "mb/pg_wchar.h" #include "miscadmin.h" #include "pgstat.h" @@ -577,6 +578,16 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, if (!bootstrap) CheckMyDatabase(dbname, am_superuser); + /* + * If we're trying to shut down, only superusers can connect. + */ + if (!am_superuser && + MyProcPort != NULL && + MyProcPort->canAcceptConnections == CAC_WAITBACKUP) + ereport(FATAL, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + errmsg("must be superuser to connect during database shutdown"))); + /* * Check a normal user hasn't connected to a superuser reserved slot. */ -- cgit v1.2.3