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

Commit f7bb7f0

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 5d1ff6b commit f7bb7f0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/backend/utils/init/postinit.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
827827
/* take database name from the caller, just for paranoia */
828828
strlcpy(dbname, in_dbname, sizeof(dbname));
829829
}
830-
else
830+
else if (OidIsValid(dboid))
831831
{
832832
/* caller specified database by OID */
833833
HeapTuple tuple;
@@ -847,6 +847,18 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
847847
if (out_dbname)
848848
strcpy(out_dbname, dbname);
849849
}
850+
else
851+
{
852+
/*
853+
* If this is a background worker not bound to any particular
854+
* database, we're done now. Everything that follows only makes
855+
* sense if we are bound to a specific database. We do need to
856+
* close the transaction we started before returning.
857+
*/
858+
if (!bootstrap)
859+
CommitTransactionCommand();
860+
return;
861+
}
850862

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

0 commit comments

Comments
 (0)