diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/initdb/initdb.c | 25 | ||||
| -rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 68 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dump.c | 3 | ||||
| -rw-r--r-- | src/bin/pg_dump/pg_dumpall.c | 2 | ||||
| -rw-r--r-- | src/bin/psql/tab-complete.c | 3 | ||||
| -rw-r--r-- | src/bin/scripts/createdb.c | 11 | ||||
| -rw-r--r-- | src/bin/scripts/dropdb.c | 5 |
7 files changed, 62 insertions, 55 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 3b321494e4..56a396bddd 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -1595,6 +1595,7 @@ setup_collation(void) size_t len; int enc; bool skip; + char *quoted_locale; char alias[NAMEDATALEN]; len = strlen(localebuf); @@ -1645,8 +1646,10 @@ setup_collation(void) count++; - PG_CMD_PRINTF2("INSERT INTO tmp_pg_collation (locale, encoding) VALUES ('%s', %d);\n", - escape_quotes(localebuf), enc); + quoted_locale = escape_quotes(localebuf); + + PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n", + quoted_locale, quoted_locale, enc); /* * Generate aliases such as "en_US" in addition to "en_US.utf8" for @@ -1654,29 +1657,33 @@ setup_collation(void) * only, so this doesn't clash with "en_US" for LATIN1, say. */ if (normalize_locale_name(alias, localebuf)) - PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('%s', '%s', %d);\n", - escape_quotes(alias), escape_quotes(localebuf), enc); + PG_CMD_PRINTF3("INSERT INTO tmp_pg_collation VALUES (E'%s', E'%s', %d);\n", + escape_quotes(alias), quoted_locale, enc); } /* Add an SQL-standard name */ - PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation (collname, locale, encoding) VALUES ('ucs_basic', 'C', %d);\n", PG_UTF8); + PG_CMD_PRINTF1("INSERT INTO tmp_pg_collation VALUES ('ucs_basic', 'C', %d);\n", PG_UTF8); /* * When copying collations to the final location, eliminate aliases that * conflict with an existing locale name for the same encoding. For * example, "br_FR.iso88591" is normalized to "br_FR", both for encoding * LATIN1. But the unnormalized locale "br_FR" already exists for LATIN1. - * Prefer the collation that matches the OS locale name, else the first + * Prefer the alias that matches the OS locale name, else the first locale * name by sort order (arbitrary choice to be deterministic). + * + * Also, eliminate any aliases that conflict with pg_collation's + * hard-wired entries for "C" etc. */ PG_CMD_PUTS("INSERT INTO pg_collation (collname, collnamespace, collowner, collencoding, collcollate, collctype) " - " SELECT DISTINCT ON (final_collname, collnamespace, encoding)" - " COALESCE(collname, locale) AS final_collname, " + " SELECT DISTINCT ON (collname, encoding)" + " collname, " " (SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog') AS collnamespace, " " (SELECT relowner FROM pg_class WHERE relname = 'pg_collation') AS collowner, " " encoding, locale, locale " " FROM tmp_pg_collation" - " ORDER BY final_collname, collnamespace, encoding, (collname = locale) DESC, locale;\n"); + " WHERE NOT EXISTS (SELECT 1 FROM pg_collation WHERE collname = tmp_pg_collation.collname)" + " ORDER BY collname, encoding, (collname = locale) DESC, locale;\n"); pclose(locale_a_handle); PG_CMD_CLOSE; diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index a5d9c2e652..3feb3ee548 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -118,23 +118,23 @@ xmalloc0(int size) static void usage(void) { - printf(_("%s takes base backups of running PostgreSQL servers\n\n"), + printf(_("%s takes a base backup of a running PostgreSQL server.\n\n"), progname); printf(_("Usage:\n")); printf(_(" %s [OPTION]...\n"), progname); printf(_("\nOptions controlling the output:\n")); - printf(_(" -D, --pgdata=directory receive base backup into directory\n")); - printf(_(" -F, --format=p|t output format (plain, tar)\n")); - printf(_(" -x, --xlog include required WAL files in backup\n")); - printf(_(" -Z, --compress=0-9 compress tar output\n")); + printf(_(" -D, --pgdata=DIRECTORY receive base backup into directory\n")); + printf(_(" -F, --format=p|t output format (plain, tar)\n")); + printf(_(" -x, --xlog include required WAL files in backup\n")); + printf(_(" -Z, --compress=0-9 compress tar output\n")); printf(_("\nGeneral options:\n")); printf(_(" -c, --checkpoint=fast|spread\n" - " set fast or spread checkpointing\n")); - printf(_(" -l, --label=label set backup label\n")); - printf(_(" -P, --progress show progress information\n")); - printf(_(" -v, --verbose output verbose messages\n")); - printf(_(" -?, --help show this help, then exit\n")); - printf(_(" -V, --version output version information, then exit\n")); + " set fast or spread checkpointing\n")); + printf(_(" -l, --label=LABEL set backup label\n")); + printf(_(" -P, --progress show progress information\n")); + printf(_(" -v, --verbose output verbose messages\n")); + printf(_(" --help show this help, then exit\n")); + printf(_(" --version output version information, then exit\n")); printf(_("\nConnection options:\n")); printf(_(" -h, --host=HOSTNAME database server host or socket directory\n")); printf(_(" -p, --port=PORT database server port number\n")); @@ -337,7 +337,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_COPY_OUT) { - fprintf(stderr, _("%s: could not get COPY data stream: %s\n"), + fprintf(stderr, _("%s: could not get COPY data stream: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -398,7 +398,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) } else if (r == -2) { - fprintf(stderr, _("%s: could not read COPY data: %s\n"), + fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -467,7 +467,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_COPY_OUT) { - fprintf(stderr, _("%s: could not get COPY data stream: %s\n"), + fprintf(stderr, _("%s: could not get COPY data stream: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -496,7 +496,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) } else if (r == -2) { - fprintf(stderr, _("%s: could not read COPY data: %s\n"), + fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -510,7 +510,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) */ if (r != 512) { - fprintf(stderr, _("%s: Invalid tar block header size: %i\n"), + fprintf(stderr, _("%s: invalid tar block header size: %i\n"), progname, r); disconnect_and_exit(1); } @@ -518,7 +518,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) if (sscanf(copybuf + 124, "%11o", ¤t_len_left) != 1) { - fprintf(stderr, _("%s: could not parse file size!\n"), + fprintf(stderr, _("%s: could not parse file size\n"), progname); disconnect_and_exit(1); } @@ -526,7 +526,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) /* Set permissions on the file */ if (sscanf(©buf[100], "%07o ", &filemode) != 1) { - fprintf(stderr, _("%s: could not parse file mode!\n"), + fprintf(stderr, _("%s: could not parse file mode\n"), progname); disconnect_and_exit(1); } @@ -581,7 +581,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) } else { - fprintf(stderr, _("%s: unknown link indicator \"%c\"\n"), + fprintf(stderr, _("%s: unrecognized link indicator \"%c\"\n"), progname, copybuf[156]); disconnect_and_exit(1); } @@ -659,7 +659,7 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum) if (file != NULL) { - fprintf(stderr, _("%s: last file was never finished!\n"), progname); + fprintf(stderr, _("%s: last file was never finished\n"), progname); disconnect_and_exit(1); } @@ -740,7 +740,7 @@ GetConnection(void) if (PQstatus(tmpconn) != CONNECTION_OK) { - fprintf(stderr, _("%s: could not connect to server: %s\n"), + fprintf(stderr, _("%s: could not connect to server: %s"), progname, PQerrorMessage(tmpconn)); exit(1); } @@ -780,7 +780,7 @@ BaseBackup(void) if (PQsendQuery(conn, current_path) == 0) { - fprintf(stderr, _("%s: could not start base backup: %s\n"), + fprintf(stderr, _("%s: could not start base backup: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -791,13 +791,13 @@ BaseBackup(void) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, _("%s: could not initiate base backup: %s\n"), + fprintf(stderr, _("%s: could not initiate base backup: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } if (PQntuples(res) != 1) { - fprintf(stderr, _("%s: no start point returned from server.\n"), + fprintf(stderr, _("%s: no start point returned from server\n"), progname); disconnect_and_exit(1); } @@ -813,13 +813,13 @@ BaseBackup(void) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, _("%s: could not get backup header: %s\n"), + fprintf(stderr, _("%s: could not get backup header: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } if (PQntuples(res) < 1) { - fprintf(stderr, _("%s: no data returned from server.\n"), progname); + fprintf(stderr, _("%s: no data returned from server\n"), progname); disconnect_and_exit(1); } @@ -847,7 +847,7 @@ BaseBackup(void) */ if (format == 't' && strcmp(basedir, "-") == 0 && PQntuples(res) > 1) { - fprintf(stderr, _("%s: can only write single tablespace to stdout, database has %i.\n"), + fprintf(stderr, _("%s: can only write single tablespace to stdout, database has %i\n"), progname, PQntuples(res)); disconnect_and_exit(1); } @@ -876,13 +876,13 @@ BaseBackup(void) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, _("%s: could not get end xlog position from server.\n"), + fprintf(stderr, _("%s: could not get end xlog position from server\n"), progname); disconnect_and_exit(1); } if (PQntuples(res) != 1) { - fprintf(stderr, _("%s: no end point returned from server.\n"), + fprintf(stderr, _("%s: no end point returned from server\n"), progname); disconnect_and_exit(1); } @@ -894,7 +894,7 @@ BaseBackup(void) res = PQgetResult(conn); if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, _("%s: final receive failed: %s\n"), + fprintf(stderr, _("%s: final receive failed: %s"), progname, PQerrorMessage(conn)); disconnect_and_exit(1); } @@ -905,7 +905,7 @@ BaseBackup(void) PQfinish(conn); if (verbose) - fprintf(stderr, "%s: base backup completed.\n", progname); + fprintf(stderr, "%s: base backup completed\n", progname); } @@ -1003,12 +1003,6 @@ main(int argc, char **argv) dbhost = xstrdup(optarg); break; case 'p': - if (atoi(optarg) <= 0) - { - fprintf(stderr, _("%s: invalid port number \"%s\"\n"), - progname, optarg); - exit(1); - } dbport = xstrdup(optarg); break; case 'U': diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index afc7fd7032..e474a6980d 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -863,7 +863,7 @@ help(const char *progname) printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n")); printf(_(" --role=ROLENAME do SET ROLE before dump\n")); printf(_(" --no-security-label do not dump security label assignments\n")); - printf(_(" --no-unlogged-table-data do not dump unlogged table data\n")); + printf(_(" --no-unlogged-table-data do not dump unlogged table data\n")); printf(_(" --use-set-session-authorization\n" " use SET SESSION AUTHORIZATION commands instead of\n" " ALTER OWNER commands to set ownership\n")); @@ -11804,7 +11804,6 @@ dumpTable(Archive *fout, TableInfo *tbinfo) namecopy = strdup(fmtId(tbinfo->dobj.name)); dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, (tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" : - (tbinfo->relkind == RELKIND_FOREIGN_TABLE) ? "FOREIGN TABLE" : "TABLE", namecopy, NULL, tbinfo->dobj.name, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index 963ae54aea..41a330763f 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -554,7 +554,7 @@ help(void) printf(_(" --quote-all-identifiers quote all identifiers, even if not keywords\n")); printf(_(" --role=ROLENAME do SET ROLE before dump\n")); printf(_(" --no-security-label do not dump security label assignments\n")); - printf(_(" --no-unlogged-table-data do not dump unlogged table data\n")); + printf(_(" --no-unlogged-table-data do not dump unlogged table data\n")); printf(_(" --use-set-session-authorization\n" " use SET SESSION AUTHORIZATION commands instead of\n" " ALTER OWNER commands to set ownership\n")); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 3ef2fa421d..9a7eca0766 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2234,7 +2234,6 @@ psql_completion(char *text, int start, int end) " UNION SELECT 'DATABASE'" " UNION SELECT 'FOREIGN DATA WRAPPER'" " UNION SELECT 'FOREIGN SERVER'" - " UNION SELECT 'FOREIGN TABLE'" " UNION SELECT 'FUNCTION'" " UNION SELECT 'LANGUAGE'" " UNION SELECT 'LARGE OBJECT'" @@ -2246,7 +2245,7 @@ psql_completion(char *text, int start, int end) pg_strcasecmp(prev_wd, "FOREIGN") == 0) { static const char *const list_privilege_foreign[] = - {"DATA WRAPPER", "SERVER", "TABLE", NULL}; + {"DATA WRAPPER", "SERVER", NULL}; COMPLETE_WITH_LIST(list_privilege_foreign); } diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index 9b72eac79b..544f2f64b3 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 1cf18fd5d8..48f73ae25e 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); |
