diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/init/miscinit.c | 19 | ||||
-rw-r--r-- | src/backend/utils/init/postinit.c | 6 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index d74b5ccb30d..0d5ffb0a8e5 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -231,6 +231,7 @@ static int SecurityRestrictionContext = 0; static bool SetRoleIsActive = false; + /* * GetUserId - get the current effective user ID. * @@ -389,6 +390,24 @@ SetUserIdAndContext(Oid userid, bool sec_def_context) /* + * Check if the authenticated user is a replication role + */ +bool +is_authenticated_user_replication_role(void) +{ + bool result = false; + HeapTuple utup; + + utup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(AuthenticatedUserId)); + if (HeapTupleIsValid(utup)) + { + result = ((Form_pg_authid) GETSTRUCT(utup))->rolreplication; + ReleaseSysCache(utup); + } + return result; +} + +/* * Initialize user identity during normal backend startup */ void diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index db06cda46e8..eaaf27ffa51 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -658,11 +658,11 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, { Assert(!bootstrap); - /* must have authenticated as a superuser */ - if (!am_superuser) + /* must have authenticated as a replication role */ + if (!is_authenticated_user_replication_role()) ereport(FATAL, (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), - errmsg("must be superuser to start walsender"))); + errmsg("must be replication role to start walsender"))); /* process any options passed in the startup packet */ if (MyProcPort != NULL) |