@@ -523,6 +523,9 @@ BaseInit(void)
523523 * name can be returned to the caller in out_dbname. If out_dbname isn't
524524 * NULL, it must point to a buffer of size NAMEDATALEN.
525525 *
526+ * Similarly, the username can be passed by name, using the username parameter,
527+ * or by OID using the useroid parameter.
528+ *
526529 * In bootstrap mode no parameters are used. The autovacuum launcher process
527530 * doesn't use any parameters either, because it only goes far enough to be
528531 * able to read pg_database; it doesn't connect to any particular database.
@@ -537,7 +540,7 @@ BaseInit(void)
537540 */
538541void
539542InitPostgres (const char * in_dbname ,Oid dboid ,const char * username ,
540- char * out_dbname )
543+ Oid useroid , char * out_dbname )
541544{
542545bool bootstrap = IsBootstrapProcessingMode ();
543546bool am_superuser ;
@@ -692,18 +695,18 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
692695(errcode (ERRCODE_UNDEFINED_OBJECT ),
693696errmsg ("no roles are defined in this database system" ),
694697errhint ("You should immediately run CREATE USER \"%s\" SUPERUSER;." ,
695- username )));
698+ username != NULL ? username : "postgres" )));
696699}
697700else if (IsBackgroundWorker )
698701{
699- if (username == NULL )
702+ if (username == NULL && ! OidIsValid ( useroid ) )
700703{
701704InitializeSessionUserIdStandalone ();
702705am_superuser = true;
703706}
704707else
705708{
706- InitializeSessionUserId (username );
709+ InitializeSessionUserId (username , useroid );
707710am_superuser = superuser ();
708711}
709712}
@@ -712,7 +715,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
712715/* normal multiuser case */
713716Assert (MyProcPort != NULL );
714717PerformAuthentication (MyProcPort );
715- InitializeSessionUserId (username );
718+ InitializeSessionUserId (username , useroid );
716719am_superuser = superuser ();
717720}
718721