Skip to content

Commit 7ff7711

Browse files
committed
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.
1 parent 87631ac commit 7ff7711

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/bin/scripts/createdb.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ main(int argc, char *argv[])
192192

193193
appendPQExpBuffer(&sql, ";\n");
194194

195+
/*
196+
* Connect to the 'postgres' database by default, except have
197+
* the 'postgres' user use 'template1' so he can create the
198+
* 'postgres' database.
199+
*/
195200
conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
196201
host, port, username, prompt_password, progname);
197202

@@ -208,12 +213,9 @@ main(int argc, char *argv[])
208213
}
209214

210215
PQclear(result);
211-
PQfinish(conn);
212216

213217
if (comment)
214218
{
215-
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
216-
217219
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
218220
appendStringLiteralConn(&sql, comment, conn);
219221
appendPQExpBuffer(&sql, ";\n");
@@ -231,9 +233,10 @@ main(int argc, char *argv[])
231233
}
232234

233235
PQclear(result);
234-
PQfinish(conn);
235236
}
236237

238+
PQfinish(conn);
239+
237240
exit(0);
238241
}
239242

src/bin/scripts/dropdb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ main(int argc, char *argv[])
113113
appendPQExpBuffer(&sql, "DROP DATABASE %s;\n",
114114
fmtId(dbname));
115115

116+
/*
117+
* Connect to the 'postgres' database by default, except have
118+
* the 'postgres' user use 'template1' so he can drop the
119+
* 'postgres' database.
120+
*/
116121
conn = connectDatabase(strcmp(dbname, "postgres") == 0 ? "template1" : "postgres",
117122
host, port, username, prompt_password, progname);
118123

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy