1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Add new function BackgroundWorkerInitializeConnectionByOid.

Sometimes it's useful for a background worker to be able to initialize
its database connection by OID rather than by name, so provide a way
to do that.
This commit is contained in:
Robert Haas
2015-02-02 16:23:59 -05:00
parent 2488eff889
commit 5d2f957f3f
9 changed files with 56 additions and 22 deletions

View File

@ -453,11 +453,10 @@ has_rolreplication(Oid roleid)
* Initialize user identity during normal backend startup
*/
void
InitializeSessionUserId(const char *rolename)
InitializeSessionUserId(const char *rolename, Oid roleid)
{
HeapTuple roleTup;
Form_pg_authid rform;
Oid roleid;
/*
* Don't do scans if we're bootstrapping, none of the system catalogs
@ -468,7 +467,10 @@ InitializeSessionUserId(const char *rolename)
/* call only once */
AssertState(!OidIsValid(AuthenticatedUserId));
roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(rolename));
if (rolename != NULL)
roleTup = SearchSysCache1(AUTHNAME, PointerGetDatum(rolename));
else
roleTup = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
if (!HeapTupleIsValid(roleTup))
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),