diff options
author | Robert Haas <rhaas@postgresql.org> | 2015-06-25 15:52:13 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2015-06-25 16:55:02 -0400 |
commit | d66b67fe21e11d8f1c7ac7d8445f8468fbc9222f (patch) | |
tree | 942b420ef1ed76fc1436099bccc554f777e26a02 /src | |
parent | 834aa56ea16ff4a7e217a1115797078398d85cc8 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/init/postinit.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 9ae956759e9..dfa9231a42b 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -779,7 +779,7 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, /* take database name from the caller, just for paranoia */ strlcpy(dbname, in_dbname, sizeof(dbname)); } - else + else if (OidIsValid(dboid)) { /* caller specified database by OID */ HeapTuple tuple; @@ -799,6 +799,18 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, if (out_dbname) strcpy(out_dbname, dbname); } + else + { + /* + * If this is a background worker not bound to any particular + * database, we're done now. Everything that follows only makes + * sense if we are bound to a specific database. We do need to + * close the transaction we started before returning. + */ + if (!bootstrap) + CommitTransactionCommand(); + return; + } /* * Now, take a writer's lock on the database we are trying to connect to. |