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:53:59 -0400 |
commit | 8364510a463a06375d237de19dcae929e7fb8360 (patch) | |
tree | bbcf4e094f66946986cba11f8330744bbcab2413 | |
parent | e118555cf92c06f16893e577363b6764ed2339e3 (diff) | |
download | postgresql-8364510a463a06375d237de19dcae929e7fb8360.tar.gz postgresql-8364510a463a06375d237de19dcae929e7fb8360.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 3ebd72cc343..3e18215334b 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -798,7 +798,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; @@ -818,6 +818,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. |