diff options
author | Robert Haas <rhaas@postgresql.org> | 2015-06-25 15:52:13 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2015-06-25 15:52:13 -0400 |
commit | f7bb7f0625771bc71869cdadafcf54450b2db08f (patch) | |
tree | 005479a9baabcee2b976c0ef0d45cb6361b1b636 | |
parent | 5d1ff6bd559ea8df1b7302e245e690b01b9a4fa4 (diff) | |
download | postgresql-f7bb7f0625771bc71869cdadafcf54450b2db08f.tar.gz postgresql-f7bb7f0625771bc71869cdadafcf54450b2db08f.zip |
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.
-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 2fba6b772dc..0e7b5fad2dd 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -827,7 +827,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; @@ -847,6 +847,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. |