aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init/postinit.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2010-04-26 10:52:00 +0000
committerRobert Haas <rhaas@postgresql.org>2010-04-26 10:52:00 +0000
commitab93cd9b053446dfb64f66bfac97787eb74c1172 (patch)
tree9e92067351b65515032082e674efc6d746d6ab89 /src/backend/utils/init/postinit.c
parent22da73198f87e04dc0f978dd2507ebf5c7ae6ee8 (diff)
downloadpostgresql-ab93cd9b053446dfb64f66bfac97787eb74c1172.tar.gz
postgresql-ab93cd9b053446dfb64f66bfac97787eb74c1172.zip
When we're restricting who can connect, don't allow new walsenders.
Normal superuser processes are allowed to connect even when the database system is shutting down, or when fewer than superuser_reserved_connection slots remain. This is intended to make sure an administrator can log in and troubleshoot, so don't extend these same courtesies to users connecting for replication.
Diffstat (limited to 'src/backend/utils/init/postinit.c')
-rw-r--r--src/backend/utils/init/postinit.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index b812c40ac0e..dab7694f700 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.211 2010/04/21 00:51:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.212 2010/04/26 10:52:00 rhaas Exp $
*
*
*-------------------------------------------------------------------------
@@ -618,6 +618,37 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
}
/*
+ * If we're trying to shut down, only superusers can connect, and
+ * new replication connections are not allowed.
+ */
+ if ((!am_superuser || am_walsender) &&
+ MyProcPort != NULL &&
+ MyProcPort->canAcceptConnections == CAC_WAITBACKUP)
+ {
+ if (am_walsender)
+ ereport(FATAL,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("new replication connections are not allowed during database shutdown")));
+ else
+ ereport(FATAL,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("must be superuser to connect during database shutdown")));
+ }
+
+ /*
+ * The last few connections slots are reserved for superusers.
+ * Although replication connections currently require superuser
+ * privileges, we don't allow them to consume the reserved slots,
+ * which are intended for interactive use.
+ */
+ if ((!am_superuser || am_walsender) &&
+ ReservedBackends > 0 &&
+ !HaveNFreeProcs(ReservedBackends))
+ ereport(FATAL,
+ (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
+ errmsg("remaining connection slots are reserved for non-replication superuser connections")));
+
+ /*
* If walsender, we're done here --- we don't want to connect to any
* particular database.
*/
@@ -779,26 +810,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
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.
- */
- if (!am_superuser &&
- ReservedBackends > 0 &&
- !HaveNFreeProcs(ReservedBackends))
- ereport(FATAL,
- (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
- errmsg("connection limit exceeded for non-superusers")));
-
- /*
* Now process any command-line switches that were included in the startup
* packet, if we are in a regular backend. We couldn't do this before
* because we didn't know if client is a superuser.