diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-08 14:55:14 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-08 14:55:14 -0400 |
commit | 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch) | |
tree | 6591af757bd9df12549279b4b87f01e0ce98bd79 /src/bin/scripts/reindexdb.c | |
parent | 5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff) |
Improve frontend error logging style.
Get rid of the separate "FATAL" log level, as it was applied
so inconsistently as to be meaningless. This mostly involves
s/pg_log_fatal/pg_log_error/g.
Create a macro pg_fatal() to handle the common use-case of
pg_log_error() immediately followed by exit(1). Various
modules had already invented either this or equivalent macros;
standardize on pg_fatal() and apply it where possible.
Invent the ability to add "detail" and "hint" messages to a
frontend message, much as we have long had in the backend.
Except where rewording was needed to convert existing coding
to detail/hint style, I have (mostly) resisted the temptation
to change existing message wording.
Patch by me. Design and patch reviewed at various stages by
Robert Haas, Kyotaro Horiguchi, Peter Eisentraut and
Daniel Gustafsson.
Discussion: https://postgr.es/m/1363732.1636496441@sss.pgh.pa.us
Diffstat (limited to 'src/bin/scripts/reindexdb.c')
-rw-r--r-- | src/bin/scripts/reindexdb.c | 65 |
1 files changed, 17 insertions, 48 deletions
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index c292d432033..f3b03ec3256 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -170,7 +170,8 @@ main(int argc, char *argv[]) tablespace = pg_strdup(optarg); break; default: - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + /* getopt_long already emitted a complaint */ + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } } @@ -189,7 +190,7 @@ main(int argc, char *argv[]) { pg_log_error("too many command-line arguments (first is \"%s\")", argv[optind]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } @@ -205,30 +206,15 @@ main(int argc, char *argv[]) if (alldb) { if (dbname) - { - pg_log_error("cannot reindex all databases and a specific one at the same time"); - exit(1); - } + pg_fatal("cannot reindex all databases and a specific one at the same time"); if (syscatalog) - { - pg_log_error("cannot reindex all databases and system catalogs at the same time"); - exit(1); - } + pg_fatal("cannot reindex all databases and system catalogs at the same time"); if (schemas.head != NULL) - { - pg_log_error("cannot reindex specific schema(s) in all databases"); - exit(1); - } + pg_fatal("cannot reindex specific schema(s) in all databases"); if (tables.head != NULL) - { - pg_log_error("cannot reindex specific table(s) in all databases"); - exit(1); - } + pg_fatal("cannot reindex specific table(s) in all databases"); if (indexes.head != NULL) - { - pg_log_error("cannot reindex specific index(es) in all databases"); - exit(1); - } + pg_fatal("cannot reindex specific index(es) in all databases"); cparams.dbname = maintenance_db; @@ -238,26 +224,14 @@ main(int argc, char *argv[]) else if (syscatalog) { if (schemas.head != NULL) - { - pg_log_error("cannot reindex specific schema(s) and system catalogs at the same time"); - exit(1); - } + pg_fatal("cannot reindex specific schema(s) and system catalogs at the same time"); if (tables.head != NULL) - { - pg_log_error("cannot reindex specific table(s) and system catalogs at the same time"); - exit(1); - } + pg_fatal("cannot reindex specific table(s) and system catalogs at the same time"); if (indexes.head != NULL) - { - pg_log_error("cannot reindex specific index(es) and system catalogs at the same time"); - exit(1); - } + pg_fatal("cannot reindex specific index(es) and system catalogs at the same time"); if (concurrentCons > 1) - { - pg_log_error("cannot use multiple jobs to reindex system catalogs"); - exit(1); - } + pg_fatal("cannot use multiple jobs to reindex system catalogs"); if (dbname == NULL) { @@ -283,10 +257,7 @@ main(int argc, char *argv[]) * depending on the same relation. */ if (concurrentCons > 1 && indexes.head != NULL) - { - pg_log_error("cannot use multiple jobs to reindex indexes"); - exit(1); - } + pg_fatal("cannot use multiple jobs to reindex indexes"); if (dbname == NULL) { @@ -349,17 +320,15 @@ reindex_one_database(ConnParams *cparams, ReindexType type, if (concurrently && PQserverVersion(conn) < 120000) { PQfinish(conn); - pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s", - "concurrently", "12"); - exit(1); + pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", + "concurrently", "12"); } if (tablespace && PQserverVersion(conn) < 140000) { PQfinish(conn); - pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s", - "tablespace", "14"); - exit(1); + pg_fatal("cannot use the \"%s\" option on server versions older than PostgreSQL %s", + "tablespace", "14"); } if (!parallel) |