Skip to content

Commit 8364510

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 e118555 commit 8364510

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
@@ -798,7 +798,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
798798
/* take database name from the caller, just for paranoia */
799799
strlcpy(dbname, in_dbname, sizeof(dbname));
800800
}
801-
else
801+
else if (OidIsValid(dboid))
802802
{
803803
/* caller specified database by OID */
804804
HeapTuple tuple;
@@ -818,6 +818,18 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
818818
if (out_dbname)
819819
strcpy(out_dbname, dbname);
820820
}
821+
else
822+
{
823+
/*
824+
* If this is a background worker not bound to any particular
825+
* database, we're done now. Everything that follows only makes
826+
* sense if we are bound to a specific database. We do need to
827+
* close the transaction we started before returning.
828+
*/
829+
if (!bootstrap)
830+
CommitTransactionCommand();
831+
return;
832+
}
821833

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

0 commit comments

Comments
 (0)