From: Bruce Momjian Date: Tue, 10 May 2011 23:44:15 +0000 (-0400) Subject: For create/dropdb, only connect once to the server since we now have a X-Git-Tag: REL9_1_BETA2~136 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ff7711919287a93f348023d77f9611633c9627c;p=thirdparty%2Fpostgresql.git For create/dropdb, only connect once to the server since we now have a shared description table for pg_database comments. Also update comments about database name selection. --- diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index 9b72eac79b7..544f2f64b3d 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -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); } diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index 1cf18fd5d89..48f73ae25e8 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -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);