]> granicus.if.org Git - postgresql/commitdiff
Allow background workers to connect to no particular database.
authorRobert Haas <rhaas@postgresql.org>
Thu, 25 Jun 2015 19:52:13 +0000 (15:52 -0400)
committerRobert Haas <rhaas@postgresql.org>
Thu, 25 Jun 2015 20:53:59 +0000 (16:53 -0400)
The documentation claims that this is supported, but it didn't
actually work.  Fix that.

Reported by Pavel Stehule; patch by me.

src/backend/utils/init/postinit.c

index 3ebd72cc3436198f40f405c9523670947104f209..3e18215334bd6b77b1c77632c657a74d2d685d96 100644 (file)
@@ -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.