For create/dropdb, only connect once to the server since we now have a
authorBruce Momjian <bruce@momjian.us>
Tue, 10 May 2011 23:44:15 +0000 (19:44 -0400)
committerBruce Momjian <bruce@momjian.us>
Tue, 10 May 2011 23:44:47 +0000 (19:44 -0400)
shared description table for pg_database comments.

Also update comments about database name selection.

src/bin/scripts/createdb.c
src/bin/scripts/dropdb.c

index 9b72eac79b7c3dc8123b718bdb1faae00d1a54b0..544f2f64b3db5bb9a706387222af27e5059ff144 100644 (file)
@@ -192,6 +192,11 @@ main(int argc, char *argv[])
 
    appendPQExpBuffer(&sql, ";\n");
 
+    /*
+     * Connect to the 'postgres' database by default, except have
+     * the 'postgres' user use 'template1' so he can create the
+     * 'postgres' database.
+     */
    conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
                           host, port, username, prompt_password, progname);
 
@@ -208,12 +213,9 @@ main(int argc, char *argv[])
    }
 
    PQclear(result);
-   PQfinish(conn);
 
    if (comment)
    {
-       conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
-
        printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
        appendStringLiteralConn(&sql, comment, conn);
        appendPQExpBuffer(&sql, ";\n");
@@ -231,9 +233,10 @@ main(int argc, char *argv[])
        }
 
        PQclear(result);
-       PQfinish(conn);
    }
 
+   PQfinish(conn);
+
    exit(0);
 }
 
index 1cf18fd5d89533042f953e08c519d7d81e788046..48f73ae25e85e60f6d35a217c5878a0d96d370ca 100644 (file)
@@ -113,6 +113,11 @@ main(int argc, char *argv[])
    appendPQExpBuffer(&sql, "DROP DATABASE %s;\n",
                      fmtId(dbname));
 
+    /*
+     * Connect to the 'postgres' database by default, except have
+     * the 'postgres' user use 'template1' so he can drop the
+     * 'postgres' database.
+     */
    conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
                           host, port, username, prompt_password, progname);