Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d66b67f

Browse files
committed
Allow background workers to connect to no particular database.
The documentation claims that this is supported, but it didn't actually work. Fix that. Reported by Pavel Stehule; patch by me.
1 parent 834aa56 commit d66b67f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/backend/utils/init/postinit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
779779
/* take database name from the caller, just for paranoia */
780780
strlcpy(dbname, in_dbname, sizeof(dbname));
781781
}
782-
else
782+
else if (OidIsValid(dboid))
783783
{
784784
/* caller specified database by OID */
785785
HeapTuple tuple;
@@ -799,6 +799,18 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
799799
if (out_dbname)
800800
strcpy(out_dbname, dbname);
801801
}
802+
else
803+
{
804+
/*
805+
* If this is a background worker not bound to any particular
806+
* database, we're done now. Everything that follows only makes
807+
* sense if we are bound to a specific database. We do need to
808+
* close the transaction we started before returning.
809+
*/
810+
if (!bootstrap)
811+
CommitTransactionCommand();
812+
return;
813+
}
802814

803815
/*
804816
* Now, take a writer's lock on the database we are trying to connect to.

0 commit comments

Comments
 (0)