Improve frontend error logging style.
authorTom Lane <[email protected]>
Fri, 8 Apr 2022 18:55:14 +0000 (14:55 -0400)
committerTom Lane <[email protected]>
Fri, 8 Apr 2022 18:55:14 +0000 (14:55 -0400)
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

77 files changed:
contrib/oid2name/oid2name.c
contrib/vacuumlo/vacuumlo.c
src/bin/initdb/initdb.c
src/bin/pg_amcheck/pg_amcheck.c
src/bin/pg_archivecleanup/pg_archivecleanup.c
src/bin/pg_basebackup/bbstreamer_file.c
src/bin/pg_basebackup/bbstreamer_gzip.c
src/bin/pg_basebackup/bbstreamer_inject.c
src/bin/pg_basebackup/bbstreamer_lz4.c
src/bin/pg_basebackup/bbstreamer_tar.c
src/bin/pg_basebackup/bbstreamer_zstd.c
src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_receivewal.c
src/bin/pg_basebackup/pg_recvlogical.c
src/bin/pg_basebackup/receivelog.c
src/bin/pg_basebackup/streamutil.c
src/bin/pg_basebackup/walmethods.c
src/bin/pg_checksums/pg_checksums.c
src/bin/pg_controldata/pg_controldata.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/common.c
src/bin/pg_dump/compress_io.c
src/bin/pg_dump/nls.mk
src/bin/pg_dump/parallel.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_backup_directory.c
src/bin/pg_dump/pg_backup_null.c
src/bin/pg_dump/pg_backup_tar.c
src/bin/pg_dump/pg_backup_utils.c
src/bin/pg_dump/pg_backup_utils.h
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump_sort.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c
src/bin/pg_dump/t/003_pg_dump_with_server.pl
src/bin/pg_resetwal/pg_resetwal.c
src/bin/pg_rewind/nls.mk
src/bin/pg_rewind/pg_rewind.c
src/bin/pg_rewind/pg_rewind.h
src/bin/pg_rewind/t/009_growing_files.pl
src/bin/pg_rewind/timeline.c
src/bin/pg_test_fsync/pg_test_fsync.c
src/bin/pg_upgrade/pg_upgrade.h
src/bin/pg_verifybackup/pg_verifybackup.c
src/bin/pg_verifybackup/t/005_bad_manifest.pl
src/bin/pg_waldump/nls.mk
src/bin/pg_waldump/pg_waldump.c
src/bin/pgbench/pgbench.c
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/help.c
src/bin/psql/mainloop.c
src/bin/psql/startup.c
src/bin/psql/t/001_basic.pl
src/bin/scripts/clusterdb.c
src/bin/scripts/createdb.c
src/bin/scripts/createuser.c
src/bin/scripts/dropdb.c
src/bin/scripts/dropuser.c
src/bin/scripts/pg_isready.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c
src/common/controldata_utils.c
src/common/file_utils.c
src/common/logging.c
src/common/restricted_token.c
src/fe_utils/archive.c
src/fe_utils/connect_utils.c
src/fe_utils/parallel_slot.c
src/fe_utils/query_utils.c
src/fe_utils/recovery_gen.c
src/include/common/logging.h
src/include/lib/simplehash.h
src/nls-global.mk

index 65cce4999366b26750902b85eaddf1b297795b4b..a62a5eedb12224559d55b79ff0ae93c0aafb6a5e 100644 (file)
@@ -182,16 +182,17 @@ get_opts(int argc, char **argv, struct options *my_opts)
                                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);
                }
        }
 
        if (optind < argc)
        {
-               fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
-                               progname, argv[optind]);
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error("too many command-line arguments (first is \"%s\")",
+                                        argv[optind]);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 }
@@ -328,11 +329,8 @@ sql_conn(struct options *my_opts)
                conn = PQconnectdbParams(keywords, values, true);
 
                if (!conn)
-               {
-                       pg_log_error("could not connect to database %s",
-                                                my_opts->dbname);
-                       exit(1);
-               }
+                       pg_fatal("could not connect to database %s",
+                                        my_opts->dbname);
 
                if (PQstatus(conn) == CONNECTION_BAD &&
                        PQconnectionNeedsPassword(conn) &&
@@ -359,7 +357,7 @@ sql_conn(struct options *my_opts)
                                         PQerrorMessage(conn));
                PQclear(res);
                PQfinish(conn);
-               exit(-1);
+               exit(1);
        }
        PQclear(res);
 
@@ -390,11 +388,11 @@ sql_exec(PGconn *conn, const char *todo, bool quiet)
        if (!res || PQresultStatus(res) > 2)
        {
                pg_log_error("query failed: %s", PQerrorMessage(conn));
-               pg_log_error("query was: %s", todo);
+               pg_log_error_detail("Query was: %s", todo);
 
                PQclear(res);
                PQfinish(conn);
-               exit(-1);
+               exit(1);
        }
 
        /* get the number of fields */
index d15edca454f5bc6a71e409f68dab645180b08908..b7c8f2c805e41e9242a625589d684c3586e499fd 100644 (file)
@@ -492,19 +492,13 @@ main(int argc, char **argv)
        {
                switch (c)
                {
-                       case '?':
-                               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
-                               exit(1);
                        case 'h':
                                param.pg_host = pg_strdup(optarg);
                                break;
                        case 'l':
                                param.transaction_limit = strtol(optarg, NULL, 10);
                                if (param.transaction_limit < 0)
-                               {
-                                       pg_log_error("transaction limit must not be negative (0 disables)");
-                                       exit(1);
-                               }
+                                       pg_fatal("transaction limit must not be negative (0 disables)");
                                break;
                        case 'n':
                                param.dry_run = 1;
@@ -513,10 +507,7 @@ main(int argc, char **argv)
                        case 'p':
                                port = strtol(optarg, NULL, 10);
                                if ((port < 1) || (port > 65535))
-                               {
-                                       pg_log_error("invalid port number: %s", optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid port number: %s", optarg);
                                param.pg_port = pg_strdup(optarg);
                                break;
                        case 'U':
@@ -532,7 +523,8 @@ main(int argc, char **argv)
                                param.pg_prompt = TRI_YES;
                                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);
                }
        }
@@ -541,7 +533,7 @@ main(int argc, char **argv)
        if (optind >= argc)
        {
                pg_log_error("missing required argument: database name");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
index bbca1236d95c8d9366b68c2b9b8d8d59c1ecd1f1..ab826da6505fcffe427174a80f55e73dcc37d3c6 100644 (file)
@@ -331,10 +331,7 @@ escape_quotes(const char *src)
        char       *result = escape_single_quotes_ascii(src);
 
        if (!result)
-       {
-               pg_log_error("out of memory");
-               exit(1);
-       }
+               pg_fatal("out of memory");
        return result;
 }
 
@@ -464,10 +461,7 @@ readfile(const char *path)
        int                     n;
 
        if ((infile = fopen(path, "r")) == NULL)
-       {
-               pg_log_error("could not open file \"%s\" for reading: %m", path);
-               exit(1);
-       }
+               pg_fatal("could not open file \"%s\" for reading: %m", path);
 
        initStringInfo(&line);
 
@@ -508,24 +502,15 @@ writefile(char *path, char **lines)
        char      **line;
 
        if ((out_file = fopen(path, "w")) == NULL)
-       {
-               pg_log_error("could not open file \"%s\" for writing: %m", path);
-               exit(1);
-       }
+               pg_fatal("could not open file \"%s\" for writing: %m", path);
        for (line = lines; *line != NULL; line++)
        {
                if (fputs(*line, out_file) < 0)
-               {
-                       pg_log_error("could not write file \"%s\": %m", path);
-                       exit(1);
-               }
+                       pg_fatal("could not write file \"%s\": %m", path);
                free(*line);
        }
        if (fclose(out_file))
-       {
-               pg_log_error("could not write file \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not close file \"%s\": %m", path);
 }
 
 /*
@@ -611,9 +596,7 @@ get_id(void)
        if (geteuid() == 0)                     /* 0 is root's uid */
        {
                pg_log_error("cannot be run as root");
-               fprintf(stderr,
-                               _("Please log in (using, e.g., \"su\") as the (unprivileged) user that will\n"
-                                 "own the server process.\n"));
+               pg_log_error_hint("Please log in (using, e.g., \"su\") as the (unprivileged) user that will own the server process.");
                exit(1);
        }
 #endif
@@ -645,9 +628,8 @@ get_encoding_id(const char *encoding_name)
                if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
                        return enc;
        }
-       pg_log_error("\"%s\" is not a valid server encoding name",
-                                encoding_name ? encoding_name : "(null)");
-       exit(1);
+       pg_fatal("\"%s\" is not a valid server encoding name",
+                        encoding_name ? encoding_name : "(null)");
 }
 
 /*
@@ -791,25 +773,19 @@ check_input(char *path)
                if (errno == ENOENT)
                {
                        pg_log_error("file \"%s\" does not exist", path);
-                       fprintf(stderr,
-                                       _("This might mean you have a corrupted installation or identified\n"
-                                         "the wrong directory with the invocation option -L.\n"));
+                       pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
                }
                else
                {
                        pg_log_error("could not access file \"%s\": %m", path);
-                       fprintf(stderr,
-                                       _("This might mean you have a corrupted installation or identified\n"
-                                         "the wrong directory with the invocation option -L.\n"));
+                       pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
                }
                exit(1);
        }
        if (!S_ISREG(statbuf.st_mode))
        {
                pg_log_error("file \"%s\" is not a regular file", path);
-               fprintf(stderr,
-                               _("This might mean you have a corrupted installation or identified\n"
-                                 "the wrong directory with the invocation option -L.\n"));
+               pg_log_error_hint("This might mean you have a corrupted installation or identified the wrong directory with the invocation option -L.");
                exit(1);
        }
 }
@@ -830,16 +806,10 @@ write_version_file(const char *extrapath)
                path = psprintf("%s/%s/PG_VERSION", pg_data, extrapath);
 
        if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
-       {
-               pg_log_error("could not open file \"%s\" for writing: %m", path);
-               exit(1);
-       }
+               pg_fatal("could not open file \"%s\" for writing: %m", path);
        if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
                fclose(version_file))
-       {
-               pg_log_error("could not write file \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not write file \"%s\": %m", path);
        free(path);
 }
 
@@ -856,15 +826,9 @@ set_null_conf(void)
        path = psprintf("%s/postgresql.conf", pg_data);
        conf_file = fopen(path, PG_BINARY_W);
        if (conf_file == NULL)
-       {
-               pg_log_error("could not open file \"%s\" for writing: %m", path);
-               exit(1);
-       }
+               pg_fatal("could not open file \"%s\" for writing: %m", path);
        if (fclose(conf_file))
-       {
-               pg_log_error("could not write file \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not write file \"%s\": %m", path);
        free(path);
 }
 
@@ -1218,10 +1182,7 @@ setup_config(void)
 
        writefile(path, conflines);
        if (chmod(path, pg_file_create_mode) != 0)
-       {
-               pg_log_error("could not change permissions of \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not change permissions of \"%s\": %m", path);
 
        /*
         * create the automatic configuration file to store the configuration
@@ -1237,10 +1198,7 @@ setup_config(void)
 
        writefile(path, autoconflines);
        if (chmod(path, pg_file_create_mode) != 0)
-       {
-               pg_log_error("could not change permissions of \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not change permissions of \"%s\": %m", path);
 
        free(conflines);
 
@@ -1323,10 +1281,7 @@ setup_config(void)
 
        writefile(path, conflines);
        if (chmod(path, pg_file_create_mode) != 0)
-       {
-               pg_log_error("could not change permissions of \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not change permissions of \"%s\": %m", path);
 
        free(conflines);
 
@@ -1338,10 +1293,7 @@ setup_config(void)
 
        writefile(path, conflines);
        if (chmod(path, pg_file_create_mode) != 0)
-       {
-               pg_log_error("could not change permissions of \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not change permissions of \"%s\": %m", path);
 
        free(conflines);
 
@@ -1375,9 +1327,7 @@ bootstrap_template1(void)
        {
                pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
                                         bki_file, PG_VERSION);
-               fprintf(stderr,
-                               _("Check your installation or specify the correct path "
-                                 "using the option -L.\n"));
+               pg_log_error_hint("Specify the correct path using the option -L.");
                exit(1);
        }
 
@@ -1503,21 +1453,17 @@ get_su_pwd(void)
                FILE       *pwf = fopen(pwfilename, "r");
 
                if (!pwf)
-               {
-                       pg_log_error("could not open file \"%s\" for reading: %m",
-                                                pwfilename);
-                       exit(1);
-               }
+                       pg_fatal("could not open file \"%s\" for reading: %m",
+                                        pwfilename);
                pwd1 = pg_get_line(pwf, NULL);
                if (!pwd1)
                {
                        if (ferror(pwf))
-                               pg_log_error("could not read password from file \"%s\": %m",
-                                                        pwfilename);
+                               pg_fatal("could not read password from file \"%s\": %m",
+                                                pwfilename);
                        else
-                               pg_log_error("password file \"%s\" is empty",
-                                                        pwfilename);
-                       exit(1);
+                               pg_fatal("password file \"%s\" is empty",
+                                                pwfilename);
                }
                fclose(pwf);
 
@@ -2065,10 +2011,7 @@ check_locale_name(int category, const char *locale, char **canonname)
 
        save = setlocale(category, NULL);
        if (!save)
-       {
-               pg_log_error("setlocale() failed");
-               exit(1);
-       }
+               pg_fatal("setlocale() failed");
 
        /* save may be pointing at a modifiable scratch variable, so copy it. */
        save = pg_strdup(save);
@@ -2086,17 +2029,14 @@ check_locale_name(int category, const char *locale, char **canonname)
 
        /* restore old value. */
        if (!setlocale(category, save))
-       {
-               pg_log_error("failed to restore old locale \"%s\"", save);
-               exit(1);
-       }
+               pg_fatal("failed to restore old locale \"%s\"", save);
        free(save);
 
        /* complain if locale wasn't valid */
        if (res == NULL)
        {
                if (*locale)
-                       pg_log_error("invalid locale name \"%s\"", locale);
+                       pg_fatal("invalid locale name \"%s\"", locale);
                else
                {
                        /*
@@ -2107,9 +2047,8 @@ check_locale_name(int category, const char *locale, char **canonname)
                         * setlocale's behavior is implementation-specific, it's hard to
                         * be sure what it didn't like.  Print a safe generic message.
                         */
-                       pg_log_error("invalid locale settings; check LANG and LC_* environment variables");
+                       pg_fatal("invalid locale settings; check LANG and LC_* environment variables");
                }
-               exit(1);
        }
 }
 
@@ -2135,15 +2074,14 @@ check_locale_encoding(const char *locale, int user_enc)
                  user_enc == PG_SQL_ASCII))
        {
                pg_log_error("encoding mismatch");
-               fprintf(stderr,
-                               _("The encoding you selected (%s) and the encoding that the\n"
-                                 "selected locale uses (%s) do not match.  This would lead to\n"
-                                 "misbehavior in various character string processing functions.\n"
-                                 "Rerun %s and either do not specify an encoding explicitly,\n"
-                                 "or choose a matching combination.\n"),
-                               pg_encoding_to_char(user_enc),
-                               pg_encoding_to_char(locale_enc),
-                               progname);
+               pg_log_error_detail("The encoding you selected (%s) and the encoding that the "
+                                                       "selected locale uses (%s) do not match. This would lead to "
+                                                       "misbehavior in various character string processing functions.",
+                                                       pg_encoding_to_char(user_enc),
+                                                       pg_encoding_to_char(locale_enc));
+               pg_log_error_hint("Rerun %s and either do not specify an encoding explicitly, "
+                                                 "or choose a matching combination.",
+                                                 progname);
                return false;
        }
        return true;
@@ -2203,18 +2141,14 @@ setlocales(void)
        if (locale_provider == COLLPROVIDER_ICU)
        {
                if (!icu_locale)
-               {
-                       pg_log_error("ICU locale must be specified");
-                       exit(1);
-               }
+                       pg_fatal("ICU locale must be specified");
 
                /*
                 * In supported builds, the ICU locale ID will be checked by the
-                * backend when performing the post-boostrap initialization.
+                * backend during post-bootstrap initialization.
                 */
 #ifndef USE_ICU
-               pg_log_error("ICU is not supported in this build");
-               exit(1);
+               pg_fatal("ICU is not supported in this build");
 #endif
        }
 }
@@ -2295,9 +2229,8 @@ check_authmethod_valid(const char *authmethod, const char *const *valid_methods,
                                return;
        }
 
-       pg_log_error("invalid authentication method \"%s\" for \"%s\" connections",
-                                authmethod, conntype);
-       exit(1);
+       pg_fatal("invalid authentication method \"%s\" for \"%s\" connections",
+                        authmethod, conntype);
 }
 
 static void
@@ -2310,10 +2243,7 @@ check_need_password(const char *authmethodlocal, const char *authmethodhost)
                 strcmp(authmethodhost, "password") == 0 ||
                 strcmp(authmethodhost, "scram-sha-256") == 0) &&
                !(pwprompt || pwfilename))
-       {
-               pg_log_error("must specify a password for the superuser to enable password authentication");
-               exit(1);
-       }
+               pg_fatal("must specify a password for the superuser to enable password authentication");
 }
 
 
@@ -2333,10 +2263,9 @@ setup_pgdata(void)
                else
                {
                        pg_log_error("no data directory specified");
-                       fprintf(stderr,
-                                       _("You must identify the directory where the data for this database system\n"
-                                         "will reside.  Do this with either the invocation option -D or the\n"
-                                         "environment variable PGDATA.\n"));
+                       pg_log_error_hint("You must identify the directory where the data for this database system "
+                                                         "will reside.  Do this with either the invocation option -D or the "
+                                                         "environment variable PGDATA.");
                        exit(1);
                }
        }
@@ -2351,10 +2280,7 @@ setup_pgdata(void)
         * have embedded spaces.
         */
        if (setenv("PGDATA", pg_data, 1) != 0)
-       {
-               pg_log_error("could not set environment");
-               exit(1);
-       }
+               pg_fatal("could not set environment");
 }
 
 
@@ -2372,16 +2298,11 @@ setup_bin_paths(const char *argv0)
                        strlcpy(full_path, progname, sizeof(full_path));
 
                if (ret == -1)
-                       pg_log_error("The program \"%s\" is needed by %s but was not found in the\n"
-                                                "same directory as \"%s\".\n"
-                                                "Check your installation.",
-                                                "postgres", progname, full_path);
+                       pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"",
+                                        "postgres", progname, full_path);
                else
-                       pg_log_error("The program \"%s\" was found by \"%s\"\n"
-                                                "but was not the same version as %s.\n"
-                                                "Check your installation.",
-                                                "postgres", full_path, progname);
-               exit(1);
+                       pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s",
+                                        "postgres", full_path, progname);
        }
 
        /* store binary directory */
@@ -2395,10 +2316,7 @@ setup_bin_paths(const char *argv0)
                get_share_path(backend_exec, share_path);
        }
        else if (!is_absolute_path(share_path))
-       {
-               pg_log_error("input file location must be an absolute path");
-               exit(1);
-       }
+               pg_fatal("input file location must be an absolute path");
 
        canonicalize_path(share_path);
 }
@@ -2449,9 +2367,8 @@ setup_locale_encoding(void)
                        /* Couldn't recognize the locale's codeset */
                        pg_log_error("could not find suitable encoding for locale \"%s\"",
                                                 lc_ctype);
-                       fprintf(stderr, _("Rerun %s with the -E option.\n"), progname);
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Rerun %s with the -E option.", progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
                else if (!pg_valid_server_encoding_id(ctype_enc))
@@ -2470,10 +2387,10 @@ setup_locale_encoding(void)
 #else
                        pg_log_error("locale \"%s\" requires unsupported encoding \"%s\"",
                                                 lc_ctype, pg_encoding_to_char(ctype_enc));
-                       fprintf(stderr,
-                                       _("Encoding \"%s\" is not allowed as a server-side encoding.\n"
-                                         "Rerun %s with a different locale selection.\n"),
-                                       pg_encoding_to_char(ctype_enc), progname);
+                       pg_log_error_detail("Encoding \"%s\" is not allowed as a server-side encoding.",
+                                                               pg_encoding_to_char(ctype_enc));
+                       pg_log_error_hint("Rerun %s with a different locale selection.",
+                                                         progname);
                        exit(1);
 #endif
                }
@@ -2616,10 +2533,7 @@ create_data_directory(void)
                        fflush(stdout);
 
                        if (pg_mkdir_p(pg_data, pg_dir_create_mode) != 0)
-                       {
-                               pg_log_error("could not create directory \"%s\": %m", pg_data);
-                               exit(1);
-                       }
+                               pg_fatal("could not create directory \"%s\": %m", pg_data);
                        else
                                check_ok();
 
@@ -2633,11 +2547,8 @@ create_data_directory(void)
                        fflush(stdout);
 
                        if (chmod(pg_data, pg_dir_create_mode) != 0)
-                       {
-                               pg_log_error("could not change permissions of directory \"%s\": %m",
-                                                        pg_data);
-                               exit(1);
-                       }
+                               pg_fatal("could not change permissions of directory \"%s\": %m",
+                                                pg_data);
                        else
                                check_ok();
 
@@ -2652,17 +2563,15 @@ create_data_directory(void)
                        if (ret != 4)
                                warn_on_mount_point(ret);
                        else
-                               fprintf(stderr,
-                                               _("If you want to create a new database system, either remove or empty\n"
-                                                 "the directory \"%s\" or run %s\n"
-                                                 "with an argument other than \"%s\".\n"),
-                                               pg_data, progname, pg_data);
+                               pg_log_error_hint("If you want to create a new database system, either remove or empty "
+                                                                 "the directory \"%s\" or run %s "
+                                                                 "with an argument other than \"%s\".",
+                                                                 pg_data, progname, pg_data);
                        exit(1);                        /* no further message needed */
 
                default:
                        /* Trouble accessing directory */
-                       pg_log_error("could not access directory \"%s\": %m", pg_data);
-                       exit(1);
+                       pg_fatal("could not access directory \"%s\": %m", pg_data);
        }
 }
 
@@ -2683,10 +2592,7 @@ create_xlog_or_symlink(void)
                /* clean up xlog directory name, check it's absolute */
                canonicalize_path(xlog_dir);
                if (!is_absolute_path(xlog_dir))
-               {
-                       pg_log_error("WAL directory location must be an absolute path");
-                       exit(1);
-               }
+                       pg_fatal("WAL directory location must be an absolute path");
 
                /* check if the specified xlog directory exists/is empty */
                switch ((ret = pg_check_dir(xlog_dir)))
@@ -2698,11 +2604,8 @@ create_xlog_or_symlink(void)
                                fflush(stdout);
 
                                if (pg_mkdir_p(xlog_dir, pg_dir_create_mode) != 0)
-                               {
-                                       pg_log_error("could not create directory \"%s\": %m",
-                                                                xlog_dir);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not create directory \"%s\": %m",
+                                                        xlog_dir);
                                else
                                        check_ok();
 
@@ -2716,11 +2619,8 @@ create_xlog_or_symlink(void)
                                fflush(stdout);
 
                                if (chmod(xlog_dir, pg_dir_create_mode) != 0)
-                               {
-                                       pg_log_error("could not change permissions of directory \"%s\": %m",
-                                                                xlog_dir);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not change permissions of directory \"%s\": %m",
+                                                        xlog_dir);
                                else
                                        check_ok();
 
@@ -2735,39 +2635,29 @@ create_xlog_or_symlink(void)
                                if (ret != 4)
                                        warn_on_mount_point(ret);
                                else
-                                       fprintf(stderr,
-                                                       _("If you want to store the WAL there, either remove or empty the directory\n"
-                                                         "\"%s\".\n"),
-                                                       xlog_dir);
+                                       pg_log_error_hint("If you want to store the WAL there, either remove or empty the directory \"%s\".",
+                                                                         xlog_dir);
                                exit(1);
 
                        default:
                                /* Trouble accessing directory */
-                               pg_log_error("could not access directory \"%s\": %m", xlog_dir);
-                               exit(1);
+                               pg_fatal("could not access directory \"%s\": %m", xlog_dir);
                }
 
 #ifdef HAVE_SYMLINK
                if (symlink(xlog_dir, subdirloc) != 0)
-               {
-                       pg_log_error("could not create symbolic link \"%s\": %m",
-                                                subdirloc);
-                       exit(1);
-               }
+                       pg_fatal("could not create symbolic link \"%s\": %m",
+                                        subdirloc);
 #else
-               pg_log_error("symlinks are not supported on this platform");
-               exit(1);
+               pg_fatal("symlinks are not supported on this platform");
 #endif
        }
        else
        {
                /* Without -X option, just make the subdirectory normally */
                if (mkdir(subdirloc, pg_dir_create_mode) < 0)
-               {
-                       pg_log_error("could not create directory \"%s\": %m",
-                                                subdirloc);
-                       exit(1);
-               }
+                       pg_fatal("could not create directory \"%s\": %m",
+                                        subdirloc);
        }
 
        free(subdirloc);
@@ -2778,15 +2668,12 @@ void
 warn_on_mount_point(int error)
 {
        if (error == 2)
-               fprintf(stderr,
-                               _("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.\n"));
+               pg_log_error_detail("It contains a dot-prefixed/invisible file, perhaps due to it being a mount point.");
        else if (error == 3)
-               fprintf(stderr,
-                               _("It contains a lost+found directory, perhaps due to it being a mount point.\n"));
+               pg_log_error_detail("It contains a lost+found directory, perhaps due to it being a mount point.");
 
-       fprintf(stderr,
-                       _("Using a mount point directly as the data directory is not recommended.\n"
-                         "Create a subdirectory under the mount point.\n"));
+       pg_log_error_hint("Using a mount point directly as the data directory is not recommended.\n"
+                                         "Create a subdirectory under the mount point.");
 }
 
 
@@ -2825,10 +2712,7 @@ initialize_data_directory(void)
                 * pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
                 */
                if (mkdir(path, pg_dir_create_mode) < 0)
-               {
-                       pg_log_error("could not create directory \"%s\": %m", path);
-                       exit(1);
-               }
+                       pg_fatal("could not create directory \"%s\": %m", path);
 
                free(path);
        }
@@ -3096,18 +2980,14 @@ main(int argc, char *argv[])
                                else if (strcmp(optarg, "libc") == 0)
                                        locale_provider = COLLPROVIDER_LIBC;
                                else
-                               {
-                                       pg_log_error("unrecognized locale provider: %s", optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("unrecognized locale provider: %s", optarg);
                                break;
                        case 16:
                                icu_locale = pg_strdup(optarg);
                                break;
                        default:
                                /* getopt_long already emitted a complaint */
-                               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                               progname);
+                               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                                exit(1);
                }
        }
@@ -3127,17 +3007,13 @@ 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);
        }
 
        if (icu_locale && locale_provider != COLLPROVIDER_ICU)
-       {
-               pg_log_error("%s cannot be specified unless locale provider \"%s\" is chosen",
-                                        "--icu-locale", "icu");
-               exit(1);
-       }
+               pg_fatal("%s cannot be specified unless locale provider \"%s\" is chosen",
+                                "--icu-locale", "icu");
 
        atexit(cleanup_directories_atexit);
 
@@ -3148,10 +3024,7 @@ main(int argc, char *argv[])
 
                /* must check that directory is readable */
                if (pg_check_dir(pg_data) <= 0)
-               {
-                       pg_log_error("could not access directory \"%s\": %m", pg_data);
-                       exit(1);
-               }
+                       pg_fatal("could not access directory \"%s\": %m", pg_data);
 
                fputs(_("syncing data to disk ... "), stdout);
                fflush(stdout);
@@ -3161,10 +3034,7 @@ main(int argc, char *argv[])
        }
 
        if (pwprompt && pwfilename)
-       {
-               pg_log_error("password prompt and password file cannot be specified together");
-               exit(1);
-       }
+               pg_fatal("password prompt and password file cannot be specified together");
 
        check_authmethod_unspecified(&authmethodlocal);
        check_authmethod_unspecified(&authmethodhost);
@@ -3186,15 +3056,9 @@ main(int argc, char *argv[])
 
                /* verify that wal segment size is valid */
                if (endptr == str_wal_segment_size_mb || *endptr != '\0')
-               {
-                       pg_log_error("argument of --wal-segsize must be a number");
-                       exit(1);
-               }
+                       pg_fatal("argument of --wal-segsize must be a number");
                if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
-               {
-                       pg_log_error("argument of --wal-segsize must be a power of 2 between 1 and 1024");
-                       exit(1);
-               }
+                       pg_fatal("argument of --wal-segsize must be a power of 2 between 1 and 1024");
        }
 
        get_restricted_token();
@@ -3208,10 +3072,7 @@ main(int argc, char *argv[])
                username = effective_user;
 
        if (strncmp(username, "pg_", 3) == 0)
-       {
-               pg_log_error("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
-               exit(1);
-       }
+               pg_fatal("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
 
        printf(_("The files belonging to this database system will be owned "
                         "by user \"%s\".\n"
@@ -3254,8 +3115,8 @@ main(int argc, char *argv[])
        {
                printf("\n");
                pg_log_warning("enabling \"trust\" authentication for local connections");
-               fprintf(stderr, _("You can change this by editing pg_hba.conf or using the option -A, or\n"
-                                                 "--auth-local and --auth-host, the next time you run initdb.\n"));
+               pg_log_warning_hint("You can change this by editing pg_hba.conf or using the option -A, or "
+                                                       "--auth-local and --auth-host, the next time you run initdb.");
        }
 
        if (!noinstructions)
index 6607f72938214cdebc2d3e2d1ea3b9005dd2e0ef..90471e096d27d6667ddec897fdfb6b150f3b5160 100644 (file)
@@ -202,9 +202,9 @@ static void compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
 
 #define log_no_match(...) do { \
                if (opts.strict_names) \
-                       pg_log_generic(PG_LOG_ERROR, __VA_ARGS__); \
+                       pg_log_error(__VA_ARGS__); \
                else \
-                       pg_log_generic(PG_LOG_WARNING, __VA_ARGS__); \
+                       pg_log_warning(__VA_ARGS__); \
        } while(0)
 
 #define FREE_AND_SET_NULL(x) do { \
@@ -396,39 +396,24 @@ main(int argc, char *argv[])
                                else if (pg_strcasecmp(optarg, "none") == 0)
                                        opts.skip = "none";
                                else
-                               {
-                                       pg_log_error("invalid argument for option %s", "--skip");
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid argument for option %s", "--skip");
                                break;
                        case 7:
                                errno = 0;
                                optval = strtoul(optarg, &endptr, 10);
                                if (endptr == optarg || *endptr != '\0' || errno != 0)
-                               {
-                                       pg_log_error("invalid start block");
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid start block");
                                if (optval > MaxBlockNumber)
-                               {
-                                       pg_log_error("start block out of bounds");
-                                       exit(1);
-                               }
+                                       pg_fatal("start block out of bounds");
                                opts.startblock = optval;
                                break;
                        case 8:
                                errno = 0;
                                optval = strtoul(optarg, &endptr, 10);
                                if (endptr == optarg || *endptr != '\0' || errno != 0)
-                               {
-                                       pg_log_error("invalid end block");
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid end block");
                                if (optval > MaxBlockNumber)
-                               {
-                                       pg_log_error("end block out of bounds");
-                                       exit(1);
-                               }
+                                       pg_fatal("end block out of bounds");
                                opts.endblock = optval;
                                break;
                        case 9:
@@ -450,18 +435,14 @@ main(int argc, char *argv[])
                                        opts.install_schema = 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);
                }
        }
 
        if (opts.endblock >= 0 && opts.endblock < opts.startblock)
-       {
-               pg_log_error("end block precedes start block");
-               exit(1);
-       }
+               pg_fatal("end block precedes start block");
 
        /*
         * A single non-option arguments specifies a database name or connection
@@ -477,7 +458,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);
        }
 
@@ -495,19 +476,13 @@ main(int argc, char *argv[])
        if (opts.alldb)
        {
                if (db != NULL)
-               {
-                       pg_log_error("cannot specify a database name with --all");
-                       exit(1);
-               }
+                       pg_fatal("cannot specify a database name with --all");
                cparams.dbname = maintenance_db;
        }
        else if (db != NULL)
        {
                if (opts.dbpattern)
-               {
-                       pg_log_error("cannot specify both a database name and database patterns");
-                       exit(1);
-               }
+                       pg_fatal("cannot specify both a database name and database patterns");
                cparams.dbname = db;
        }
 
@@ -535,7 +510,7 @@ main(int argc, char *argv[])
        {
                if (conn != NULL)
                        disconnectDatabase(conn);
-               pg_log_error("no databases to check");
+               pg_log_warning("no databases to check");
                exit(0);
        }
 
@@ -593,7 +568,7 @@ main(int argc, char *argv[])
                        /* Querying the catalog failed. */
                        pg_log_error("database \"%s\": %s",
                                                 PQdb(conn), PQerrorMessage(conn));
-                       pg_log_info("query was: %s", amcheck_sql);
+                       pg_log_error_detail("Query was: %s", amcheck_sql);
                        PQclear(result);
                        disconnectDatabase(conn);
                        exit(1);
@@ -669,8 +644,7 @@ main(int argc, char *argv[])
        {
                if (conn != NULL)
                        disconnectDatabase(conn);
-               pg_log_error("no relations to check");
-               exit(1);
+               pg_fatal("no relations to check");
        }
        progress_report(reltotal, relprogress, pagestotal, pageschecked,
                                        NULL, true, false);
@@ -919,7 +893,7 @@ run_command(ParallelSlot *slot, const char *sql)
                pg_log_error("error sending command to database \"%s\": %s",
                                         PQdb(slot->connection),
                                         PQerrorMessage(slot->connection));
-               pg_log_error("command was: %s", sql);
+               pg_log_error_detail("Command was: %s", sql);
                exit(1);
        }
 }
@@ -1123,9 +1097,9 @@ verify_btree_slot_handler(PGresult *res, PGconn *conn, void *context)
                        pg_log_warning("btree index \"%s.%s.%s\": btree checking function returned unexpected number of rows: %d",
                                                   rel->datinfo->datname, rel->nspname, rel->relname, ntups);
                        if (opts.verbose)
-                               pg_log_info("query was: %s", rel->sql);
-                       pg_log_warning("Are %s's and amcheck's versions compatible?",
-                                                  progname);
+                               pg_log_warning_detail("Query was: %s", rel->sql);
+                       pg_log_warning_hint("Are %s's and amcheck's versions compatible?",
+                                                               progname);
                        progress_since_last_stderr = false;
                }
        }
@@ -1648,7 +1622,7 @@ compile_database_list(PGconn *conn, SimplePtrList *databases,
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
                pg_log_error("query failed: %s", PQerrorMessage(conn));
-               pg_log_info("query was: %s", sql.data);
+               pg_log_error_detail("Query was: %s", sql.data);
                disconnectDatabase(conn);
                exit(1);
        }
@@ -1673,11 +1647,8 @@ compile_database_list(PGconn *conn, SimplePtrList *databases,
                         */
                        fatal = opts.strict_names;
                        if (pattern_id >= opts.include.len)
-                       {
-                               pg_log_error("internal error: received unexpected database pattern_id %d",
-                                                        pattern_id);
-                               exit(1);
-                       }
+                               pg_fatal("internal error: received unexpected database pattern_id %d",
+                                                pattern_id);
                        log_no_match("no connectable databases to check matching \"%s\"",
                                                 opts.include.data[pattern_id].pattern);
                }
@@ -2096,7 +2067,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
                pg_log_error("query failed: %s", PQerrorMessage(conn));
-               pg_log_info("query was: %s", sql.data);
+               pg_log_error_detail("Query was: %s", sql.data);
                disconnectDatabase(conn);
                exit(1);
        }
@@ -2136,11 +2107,8 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrList *relations,
                         */
 
                        if (pattern_id >= opts.include.len)
-                       {
-                               pg_log_error("internal error: received unexpected relation pattern_id %d",
-                                                        pattern_id);
-                               exit(1);
-                       }
+                               pg_fatal("internal error: received unexpected relation pattern_id %d",
+                                                pattern_id);
 
                        opts.include.data[pattern_id].matched = true;
                }
index 6c3e7f4e010c7683bf94eb1090d70b371d6c1580..064cbb222f257bef54aa83f356a14f311cad3c35 100644 (file)
@@ -148,33 +148,21 @@ CleanupPriorWALFiles(void)
 
                                rc = unlink(WALFilePath);
                                if (rc != 0)
-                               {
-                                       pg_log_error("could not remove file \"%s\": %m",
-                                                                WALFilePath);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not remove file \"%s\": %m",
+                                                        WALFilePath);
                        }
                }
 
                if (errno)
-               {
-                       pg_log_error("could not read archive location \"%s\": %m",
-                                                archiveLocation);
-                       exit(1);
-               }
+                       pg_fatal("could not read archive location \"%s\": %m",
+                                        archiveLocation);
                if (closedir(xldir))
-               {
-                       pg_log_error("could not close archive location \"%s\": %m",
-                                                archiveLocation);
-                       exit(1);
-               }
-       }
-       else
-       {
-               pg_log_error("could not open archive location \"%s\": %m",
+                       pg_fatal("could not close archive location \"%s\": %m",
                                         archiveLocation);
-               exit(1);
        }
+       else
+               pg_fatal("could not open archive location \"%s\": %m",
+                                archiveLocation);
 }
 
 /*
@@ -247,7 +235,7 @@ SetWALFileNameForCleanup(void)
        if (!fnameOK)
        {
                pg_log_error("invalid file name argument");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(2);
        }
 }
@@ -321,9 +309,9 @@ main(int argc, char **argv)
                                                                                                         * from xlogfile names */
                                break;
                        default:
-                               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+                               /* getopt already emitted a complaint */
+                               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                                exit(2);
-                               break;
                }
        }
 
@@ -342,7 +330,7 @@ main(int argc, char **argv)
        else
        {
                pg_log_error("must specify archive location");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(2);
        }
 
@@ -354,14 +342,14 @@ main(int argc, char **argv)
        else
        {
                pg_log_error("must specify oldest kept WAL file");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(2);
        }
 
        if (optind < argc)
        {
                pg_log_error("too many command-line arguments");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(2);
        }
 
index d721f87891ba276ed2275309b78268d95bf0c83a..393e9f340ced603e279fb926d03df60a02c1f762 100644 (file)
@@ -90,10 +90,7 @@ bbstreamer_plain_writer_new(char *pathname, FILE *file)
        {
                streamer->file = fopen(pathname, "wb");
                if (streamer->file == NULL)
-               {
-                       pg_log_error("could not create file \"%s\": %m", pathname);
-                       exit(1);
-               }
+                       pg_fatal("could not create file \"%s\": %m", pathname);
                streamer->should_close_file = true;
        }
 
@@ -121,9 +118,8 @@ bbstreamer_plain_writer_content(bbstreamer *streamer,
                /* if write didn't set errno, assume problem is no disk space */
                if (errno == 0)
                        errno = ENOSPC;
-               pg_log_error("could not write to file \"%s\": %m",
-                                        mystreamer->pathname);
-               exit(1);
+               pg_fatal("could not write to file \"%s\": %m",
+                                mystreamer->pathname);
        }
 }
 
@@ -139,11 +135,8 @@ bbstreamer_plain_writer_finalize(bbstreamer *streamer)
        mystreamer = (bbstreamer_plain_writer *) streamer;
 
        if (mystreamer->should_close_file && fclose(mystreamer->file) != 0)
-       {
-               pg_log_error("could not close file \"%s\": %m",
-                                        mystreamer->pathname);
-               exit(1);
-       }
+               pg_fatal("could not close file \"%s\": %m",
+                                mystreamer->pathname);
 
        mystreamer->file = NULL;
        mystreamer->should_close_file = false;
@@ -262,9 +255,8 @@ bbstreamer_extractor_content(bbstreamer *streamer, bbstreamer_member *member,
                                /* if write didn't set errno, assume problem is no disk space */
                                if (errno == 0)
                                        errno = ENOSPC;
-                               pg_log_error("could not write to file \"%s\": %m",
-                                                        mystreamer->filename);
-                               exit(1);
+                               pg_fatal("could not write to file \"%s\": %m",
+                                                mystreamer->filename);
                        }
                        break;
 
@@ -280,8 +272,7 @@ bbstreamer_extractor_content(bbstreamer *streamer, bbstreamer_member *member,
 
                default:
                        /* Shouldn't happen. */
-                       pg_log_error("unexpected state while extracting archive");
-                       exit(1);
+                       pg_fatal("unexpected state while extracting archive");
        }
 }
 
@@ -304,20 +295,14 @@ extract_directory(const char *filename, mode_t mode)
                           pg_str_endswith(filename, "/pg_xlog") ||
                           pg_str_endswith(filename, "/archive_status")) &&
                          errno == EEXIST))
-               {
-                       pg_log_error("could not create directory \"%s\": %m",
-                                                filename);
-                       exit(1);
-               }
+                       pg_fatal("could not create directory \"%s\": %m",
+                                        filename);
        }
 
 #ifndef WIN32
        if (chmod(filename, mode))
-       {
-               pg_log_error("could not set permissions on directory \"%s\": %m",
-                                        filename);
-               exit(1);
-       }
+               pg_fatal("could not set permissions on directory \"%s\": %m",
+                                filename);
 #endif
 }
 
@@ -335,11 +320,8 @@ static void
 extract_link(const char *filename, const char *linktarget)
 {
        if (symlink(linktarget, filename) != 0)
-       {
-               pg_log_error("could not create symbolic link from \"%s\" to \"%s\": %m",
-                                        filename, linktarget);
-               exit(1);
-       }
+               pg_fatal("could not create symbolic link from \"%s\" to \"%s\": %m",
+                                filename, linktarget);
 }
 
 /*
@@ -354,18 +336,12 @@ create_file_for_extract(const char *filename, mode_t mode)
 
        file = fopen(filename, "wb");
        if (file == NULL)
-       {
-               pg_log_error("could not create file \"%s\": %m", filename);
-               exit(1);
-       }
+               pg_fatal("could not create file \"%s\": %m", filename);
 
 #ifndef WIN32
        if (chmod(filename, mode))
-       {
-               pg_log_error("could not set permissions on file \"%s\": %m",
-                                        filename);
-               exit(1);
-       }
+               pg_fatal("could not set permissions on file \"%s\": %m",
+                                filename);
 #endif
 
        return file;
index 760619fcd7435882f0540eae15195d23f9f7bcb2..d5b38ec4bcd85ece6bf58428d4c8d9cbe28277ac 100644 (file)
@@ -92,43 +92,30 @@ bbstreamer_gzip_writer_new(char *pathname, FILE *file,
        {
                streamer->gzfile = gzopen(pathname, "wb");
                if (streamer->gzfile == NULL)
-               {
-                       pg_log_error("could not create compressed file \"%s\": %m",
-                                                pathname);
-                       exit(1);
-               }
+                       pg_fatal("could not create compressed file \"%s\": %m",
+                                        pathname);
        }
        else
        {
                int                     fd = dup(fileno(file));
 
                if (fd < 0)
-               {
-                       pg_log_error("could not duplicate stdout: %m");
-                       exit(1);
-               }
+                       pg_fatal("could not duplicate stdout: %m");
 
                streamer->gzfile = gzdopen(fd, "wb");
                if (streamer->gzfile == NULL)
-               {
-                       pg_log_error("could not open output file: %m");
-                       exit(1);
-               }
+                       pg_fatal("could not open output file: %m");
        }
 
        if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0 &&
                gzsetparams(streamer->gzfile, compress->level,
                                        Z_DEFAULT_STRATEGY) != Z_OK)
-       {
-               pg_log_error("could not set compression level %d: %s",
-                                        compress->level, get_gz_error(streamer->gzfile));
-               exit(1);
-       }
+               pg_fatal("could not set compression level %d: %s",
+                                compress->level, get_gz_error(streamer->gzfile));
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support compression");
-       exit(1);
+       pg_fatal("this build does not support gzip compression");
 #endif
 }
 
@@ -154,9 +141,8 @@ bbstreamer_gzip_writer_content(bbstreamer *streamer,
                /* if write didn't set errno, assume problem is no disk space */
                if (errno == 0)
                        errno = ENOSPC;
-               pg_log_error("could not write to compressed file \"%s\": %s",
-                                        mystreamer->pathname, get_gz_error(mystreamer->gzfile));
-               exit(1);
+               pg_fatal("could not write to compressed file \"%s\": %s",
+                                mystreamer->pathname, get_gz_error(mystreamer->gzfile));
        }
 }
 
@@ -179,11 +165,8 @@ bbstreamer_gzip_writer_finalize(bbstreamer *streamer)
 
        errno = 0;                                      /* in case gzclose() doesn't set it */
        if (gzclose(mystreamer->gzfile) != 0)
-       {
-               pg_log_error("could not close compressed file \"%s\": %m",
-                                        mystreamer->pathname);
-               exit(1);
-       }
+               pg_fatal("could not close compressed file \"%s\": %m",
+                                mystreamer->pathname);
 
        mystreamer->gzfile = NULL;
 }
@@ -260,15 +243,11 @@ bbstreamer_gzip_decompressor_new(bbstreamer *next)
         * possible value for safety.
         */
        if (inflateInit2(zs, 15 + 16) != Z_OK)
-       {
-               pg_log_error("could not initialize compression library");
-               exit(1);
-       }
+               pg_fatal("could not initialize compression library");
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support compression");
-       exit(1);
+       pg_fatal("this build does not support gzip compression");
 #endif
 }
 
index 79c378d96e69a2db2ae0de8882f74cd2754622e3..cc804f1091cd1be6c713c8c9428e5d6f36e3e9d1 100644 (file)
@@ -186,8 +186,7 @@ bbstreamer_recovery_injector_content(bbstreamer *streamer,
 
                default:
                        /* Shouldn't happen. */
-                       pg_log_error("unexpected state while injecting recovery settings");
-                       exit(1);
+                       pg_fatal("unexpected state while injecting recovery settings");
        }
 
        bbstreamer_content(mystreamer->base.bbs_next, &mystreamer->member,
index 2ffe2241b41aa12d788b05b246c5770772e767e9..93f8344ea350d611608b1f369364e3ca1d08b929 100644 (file)
@@ -93,13 +93,12 @@ bbstreamer_lz4_compressor_new(bbstreamer *next, bc_specification *compress)
 
        ctxError = LZ4F_createCompressionContext(&streamer->cctx, LZ4F_VERSION);
        if (LZ4F_isError(ctxError))
-                       pg_log_error("could not create lz4 compression context: %s",
-                                                LZ4F_getErrorName(ctxError));
+               pg_log_error("could not create lz4 compression context: %s",
+                                        LZ4F_getErrorName(ctxError));
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support compression");
-       exit(1);
+       pg_fatal("this build does not support lz4 compression");
 #endif
 }
 
@@ -291,16 +290,12 @@ bbstreamer_lz4_decompressor_new(bbstreamer *next)
        /* Initialize internal stream state for decompression */
        ctxError = LZ4F_createDecompressionContext(&streamer->dctx, LZ4F_VERSION);
        if (LZ4F_isError(ctxError))
-       {
-               pg_log_error("could not initialize compression library: %s",
-                               LZ4F_getErrorName(ctxError));
-               exit(1);
-       }
+               pg_fatal("could not initialize compression library: %s",
+                                LZ4F_getErrorName(ctxError));
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support compression");
-       exit(1);
+       pg_fatal("this build does not support lz4 compression");
 #endif
 }
 
index 6ab981156e9d58d50ce2cef422acfe00a9b60e6f..fcbad579df12e2c458328487799b71b9611a6ab2 100644 (file)
@@ -241,16 +241,12 @@ bbstreamer_tar_parser_content(bbstreamer *streamer, bbstreamer_member *member,
                                 */
                                bbstreamer_buffer_bytes(streamer, &data, &len, len);
                                if (len > 2 * TAR_BLOCK_SIZE)
-                               {
-                                       pg_log_error("tar file trailer exceeds 2 blocks");
-                                       exit(1);
-                               }
+                                       pg_fatal("tar file trailer exceeds 2 blocks");
                                return;
 
                        default:
                                /* Shouldn't happen. */
-                               pg_log_error("unexpected state while parsing tar archive");
-                               exit(1);
+                               pg_fatal("unexpected state while parsing tar archive");
                }
        }
 }
@@ -297,10 +293,7 @@ bbstreamer_tar_header(bbstreamer_tar_parser *mystreamer)
         */
        strlcpy(member->pathname, &buffer[0], MAXPGPATH);
        if (member->pathname[0] == '\0')
-       {
-               pg_log_error("tar member has empty name");
-               exit(1);
-       }
+               pg_fatal("tar member has empty name");
        member->size = read_tar_number(&buffer[124], 12);
        member->mode = read_tar_number(&buffer[100], 8);
        member->uid = read_tar_number(&buffer[108], 8);
@@ -332,10 +325,7 @@ bbstreamer_tar_parser_finalize(bbstreamer *streamer)
        if (mystreamer->next_context != BBSTREAMER_ARCHIVE_TRAILER &&
                (mystreamer->next_context != BBSTREAMER_MEMBER_HEADER ||
                 mystreamer->base.bbs_buffer.len > 0))
-       {
-               pg_log_error("COPY stream ended before last file was finished");
-               exit(1);
-       }
+               pg_fatal("COPY stream ended before last file was finished");
 
        /* Send the archive trailer, even if empty. */
        bbstreamer_content(streamer->bbs_next, NULL,
index f94c5c041d3d339d306b869dea9759b2d2794c5b..e2c76503cc715d71d2d69317872050885aa95b32 100644 (file)
@@ -82,10 +82,7 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
 
        streamer->cctx = ZSTD_createCCtx();
        if (!streamer->cctx)
-       {
-               pg_log_error("could not create zstd compression context");
-               exit(1);
-       }
+               pg_fatal("could not create zstd compression context");
 
        /* Set compression level, if specified */
        if ((compress->options & BACKUP_COMPRESSION_OPTION_LEVEL) != 0)
@@ -93,11 +90,8 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
                ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_compressionLevel,
                                                                         compress->level);
                if (ZSTD_isError(ret))
-               {
-                       pg_log_error("could not set zstd compression level to %d: %s",
-                                                compress->level, ZSTD_getErrorName(ret));
-                       exit(1);
-               }
+                       pg_fatal("could not set zstd compression level to %d: %s",
+                                        compress->level, ZSTD_getErrorName(ret));
        }
 
        /* Set # of workers, if specified */
@@ -111,11 +105,8 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
                ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_nbWorkers,
                                                                         compress->workers);
                if (ZSTD_isError(ret))
-               {
-                       pg_log_error("could not set compression worker count to %d: %s",
-                                                compress->workers, ZSTD_getErrorName(ret));
-                       exit(1);
-               }
+                       pg_fatal("could not set compression worker count to %d: %s",
+                                        compress->workers, ZSTD_getErrorName(ret));
        }
 
        /* Initialize the ZSTD output buffer. */
@@ -125,8 +116,7 @@ bbstreamer_zstd_compressor_new(bbstreamer *next, bc_specification *compress)
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support zstd compression");
-       exit(1);
+       pg_fatal("this build does not support zstd compression");
 #endif
 }
 
@@ -271,10 +261,7 @@ bbstreamer_zstd_decompressor_new(bbstreamer *next)
 
        streamer->dctx = ZSTD_createDCtx();
        if (!streamer->dctx)
-       {
-               pg_log_error("could not create zstd decompression context");
-               exit(1);
-       }
+               pg_fatal("could not create zstd decompression context");
 
        /* Initialize the ZSTD output buffer. */
        streamer->zstd_outBuf.dst = streamer->base.bbs_buffer.data;
@@ -283,8 +270,7 @@ bbstreamer_zstd_decompressor_new(bbstreamer *next)
 
        return &streamer->base;
 #else
-       pg_log_error("this build does not support compression");
-       exit(1);
+       pg_fatal("this build does not support zstd compression");
 #endif
 }
 
@@ -328,7 +314,8 @@ bbstreamer_zstd_decompressor_content(bbstreamer *streamer,
                                                                        &mystreamer->zstd_outBuf, &inBuf);
 
                if (ZSTD_isError(ret))
-                       pg_log_error("could not decompress data: %s", ZSTD_getErrorName(ret));
+                       pg_log_error("could not decompress data: %s",
+                                                ZSTD_getErrorName(ret));
        }
 }
 
index ed8d084d6298eab53556ca610e738afc4d5a939d..65dcfff0a031d424fb2e102fc2b95c63b9975967 100644 (file)
@@ -322,20 +322,14 @@ tablespace_list_append(const char *arg)
        for (arg_ptr = arg; *arg_ptr; arg_ptr++)
        {
                if (dst_ptr - dst >= MAXPGPATH)
-               {
-                       pg_log_error("directory name too long");
-                       exit(1);
-               }
+                       pg_fatal("directory name too long");
 
                if (*arg_ptr == '\\' && *(arg_ptr + 1) == '=')
                        ;                                       /* skip backslash escaping = */
                else if (*arg_ptr == '=' && (arg_ptr == arg || *(arg_ptr - 1) != '\\'))
                {
                        if (*cell->new_dir)
-                       {
-                               pg_log_error("multiple \"=\" signs in tablespace mapping");
-                               exit(1);
-                       }
+                               pg_fatal("multiple \"=\" signs in tablespace mapping");
                        else
                                dst = dst_ptr = cell->new_dir;
                }
@@ -344,10 +338,7 @@ tablespace_list_append(const char *arg)
        }
 
        if (!*cell->old_dir || !*cell->new_dir)
-       {
-               pg_log_error("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
-               exit(1);
-       }
+               pg_fatal("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
 
        /*
         * This check isn't absolutely necessary.  But all tablespaces are created
@@ -356,18 +347,12 @@ tablespace_list_append(const char *arg)
         * consistent with the new_dir check.
         */
        if (!is_absolute_path(cell->old_dir))
-       {
-               pg_log_error("old directory is not an absolute path in tablespace mapping: %s",
-                                        cell->old_dir);
-               exit(1);
-       }
+               pg_fatal("old directory is not an absolute path in tablespace mapping: %s",
+                                cell->old_dir);
 
        if (!is_absolute_path(cell->new_dir))
-       {
-               pg_log_error("new directory is not an absolute path in tablespace mapping: %s",
-                                        cell->new_dir);
-               exit(1);
-       }
+               pg_fatal("new directory is not an absolute path in tablespace mapping: %s",
+                                cell->new_dir);
 
        /*
         * Comparisons done with these values should involve similarly
@@ -483,17 +468,11 @@ reached_end_position(XLogRecPtr segendpos, uint32 timeline,
                        MemSet(xlogend, 0, sizeof(xlogend));
                        r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
                        if (r < 0)
-                       {
-                               pg_log_error("could not read from ready pipe: %m");
-                               exit(1);
-                       }
+                               pg_fatal("could not read from ready pipe: %m");
 
                        if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
-                       {
-                               pg_log_error("could not parse write-ahead log location \"%s\"",
-                                                        xlogend);
-                               exit(1);
-                       }
+                               pg_fatal("could not parse write-ahead log location \"%s\"",
+                                                xlogend);
                        xlogendptr = ((uint64) hi) << 32 | lo;
                        has_xlogendptr = 1;
 
@@ -639,11 +618,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
 
        /* Convert the starting position */
        if (sscanf(startpos, "%X/%X", &hi, &lo) != 2)
-       {
-               pg_log_error("could not parse write-ahead log location \"%s\"",
-                                        startpos);
-               exit(1);
-       }
+               pg_fatal("could not parse write-ahead log location \"%s\"",
+                                startpos);
        param->startptr = ((uint64) hi) << 32 | lo;
        /* Round off to even segment position */
        param->startptr -= XLogSegmentOffset(param->startptr, WalSegSz);
@@ -651,10 +627,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
 #ifndef WIN32
        /* Create our background pipe */
        if (pipe(bgpipe) < 0)
-       {
-               pg_log_error("could not create pipe for background process: %m");
-               exit(1);
-       }
+               pg_fatal("could not create pipe for background process: %m");
 #endif
 
        /* Get a second connection */
@@ -709,10 +682,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
                                 "pg_xlog" : "pg_wal");
 
                if (pg_mkdir_p(statusdir, pg_dir_create_mode) != 0 && errno != EEXIST)
-               {
-                       pg_log_error("could not create directory \"%s\": %m", statusdir);
-                       exit(1);
-               }
+                       pg_fatal("could not create directory \"%s\": %m", statusdir);
        }
 
        /*
@@ -735,10 +705,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
                exit(ret);
        }
        else if (bgchild < 0)
-       {
-               pg_log_error("could not create background process: %m");
-               exit(1);
-       }
+               pg_fatal("could not create background process: %m");
 
        /*
         * Else we are in the parent process and all is well.
@@ -747,10 +714,7 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
 #else                                                  /* WIN32 */
        bgchild = _beginthreadex(NULL, 0, (void *) LogStreamerMain, param, 0, NULL);
        if (bgchild == 0)
-       {
-               pg_log_error("could not create background thread: %m");
-               exit(1);
-       }
+               pg_fatal("could not create background thread: %m");
 #endif
 }
 
@@ -770,10 +734,7 @@ verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found)
                         * Does not exist, so create
                         */
                        if (pg_mkdir_p(dirname, pg_dir_create_mode) == -1)
-                       {
-                               pg_log_error("could not create directory \"%s\": %m", dirname);
-                               exit(1);
-                       }
+                               pg_fatal("could not create directory \"%s\": %m", dirname);
                        if (created)
                                *created = true;
                        return;
@@ -792,15 +753,13 @@ verify_dir_is_empty_or_create(char *dirname, bool *created, bool *found)
                        /*
                         * Exists, not empty
                         */
-                       pg_log_error("directory \"%s\" exists but is not empty", dirname);
-                       exit(1);
+                       pg_fatal("directory \"%s\" exists but is not empty", dirname);
                case -1:
 
                        /*
                         * Access problem
                         */
-                       pg_log_error("could not access directory \"%s\": %m", dirname);
-                       exit(1);
+                       pg_fatal("could not access directory \"%s\": %m", dirname);
        }
 }
 
@@ -929,23 +888,16 @@ parse_max_rate(char *src)
        errno = 0;
        result = strtod(src, &after_num);
        if (src == after_num)
-       {
-               pg_log_error("transfer rate \"%s\" is not a valid value", src);
-               exit(1);
-       }
+               pg_fatal("transfer rate \"%s\" is not a valid value", src);
        if (errno != 0)
-       {
-               pg_log_error("invalid transfer rate \"%s\": %m", src);
-               exit(1);
-       }
+               pg_fatal("invalid transfer rate \"%s\": %m", src);
 
        if (result <= 0)
        {
                /*
                 * Reject obviously wrong values here.
                 */
-               pg_log_error("transfer rate must be greater than zero");
-               exit(1);
+               pg_fatal("transfer rate must be greater than zero");
        }
 
        /*
@@ -975,27 +927,18 @@ parse_max_rate(char *src)
                after_num++;
 
        if (*after_num != '\0')
-       {
-               pg_log_error("invalid --max-rate unit: \"%s\"", suffix);
-               exit(1);
-       }
+               pg_fatal("invalid --max-rate unit: \"%s\"", suffix);
 
        /* Valid integer? */
        if ((uint64) result != (uint64) ((uint32) result))
-       {
-               pg_log_error("transfer rate \"%s\" exceeds integer range", src);
-               exit(1);
-       }
+               pg_fatal("transfer rate \"%s\" exceeds integer range", src);
 
        /*
         * The range is checked on the server side too, but avoid the server
         * connection if a nonsensical value was passed.
         */
        if (result < MAX_RATE_LOWER || result > MAX_RATE_UPPER)
-       {
-               pg_log_error("transfer rate \"%s\" is out of range", src);
-               exit(1);
-       }
+               pg_fatal("transfer rate \"%s\" is out of range", src);
 
        return (int32) result;
 }
@@ -1091,11 +1034,8 @@ ReceiveCopyData(PGconn *conn, WriteDataCallback callback,
        /* Get the COPY data stream. */
        res = PQgetResult(conn);
        if (PQresultStatus(res) != PGRES_COPY_OUT)
-       {
-               pg_log_error("could not get COPY data stream: %s",
-                                        PQerrorMessage(conn));
-               exit(1);
-       }
+               pg_fatal("could not get COPY data stream: %s",
+                                PQerrorMessage(conn));
        PQclear(res);
 
        /* Loop over chunks until done. */
@@ -1111,17 +1051,11 @@ ReceiveCopyData(PGconn *conn, WriteDataCallback callback,
                        break;
                }
                else if (r == -2)
-               {
-                       pg_log_error("could not read COPY data: %s",
-                                                PQerrorMessage(conn));
-                       exit(1);
-               }
+                       pg_fatal("could not read COPY data: %s",
+                                        PQerrorMessage(conn));
 
                if (bgchild_exited)
-               {
-                       pg_log_error("background process terminated unexpectedly");
-                       exit(1);
-               }
+                       pg_fatal("background process terminated unexpectedly");
 
                (*callback) (r, copybuf, callback_data);
 
@@ -1209,13 +1143,13 @@ CreateBackupStreamer(char *archive_name, char *spclocation,
        if (must_parse_archive && !is_tar && !is_compressed_tar)
        {
                pg_log_error("unable to parse archive: %s", archive_name);
-               pg_log_info("only tar archives can be parsed");
+               pg_log_error_detail("Only tar archives can be parsed.");
                if (format == 'p')
-                       pg_log_info("plain format requires pg_basebackup to parse the archive");
+                       pg_log_error_detail("Plain format requires pg_basebackup to parse the archive.");
                if (inject_manifest)
-                       pg_log_info("using - as the output directory requires pg_basebackup to parse the archive");
+                       pg_log_error_detail("Using - as the output directory requires pg_basebackup to parse the archive.");
                if (writerecoveryconf)
-                       pg_log_info("the -R option requires pg_basebackup to parse the archive");
+                       pg_log_error_detail("The -R option requires pg_basebackup to parse the archive.");
                exit(1);
        }
 
@@ -1427,10 +1361,7 @@ ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
                                /* Sanity check. */
                                if (state->manifest_buffer != NULL ||
                                        state->manifest_file !=NULL)
-                               {
-                                       pg_log_error("archives should precede manifest");
-                                       exit(1);
-                               }
+                                       pg_fatal("archives should precede manifest");
 
                                /* Parse the rest of the CopyData message. */
                                archive_name = GetCopyDataString(r, copybuf, &cursor);
@@ -1445,11 +1376,8 @@ ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
                                if (archive_name[0] == '\0' || archive_name[0] == '.' ||
                                        strchr(archive_name, '/') != NULL ||
                                        strchr(archive_name, '\\') != NULL)
-                               {
-                                       pg_log_error("invalid archive name: \"%s\"",
-                                                                archive_name);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid archive name: \"%s\"",
+                                                        archive_name);
 
                                /*
                                 * An empty spclocation is treated as NULL. We expect this
@@ -1509,9 +1437,8 @@ ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
                                                 */
                                                if (errno == 0)
                                                        errno = ENOSPC;
-                                               pg_log_error("could not write to file \"%s\": %m",
-                                                                        state->manifest_filename);
-                                               exit(1);
+                                               pg_fatal("could not write to file \"%s\": %m",
+                                                                state->manifest_filename);
                                        }
                                }
                                else if (state->streamer != NULL)
@@ -1521,10 +1448,7 @@ ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
                                                                           r - 1, BBSTREAMER_UNKNOWN);
                                }
                                else
-                               {
-                                       pg_log_error("unexpected payload data");
-                                       exit(1);
-                               }
+                                       pg_fatal("unexpected payload data");
                                break;
                        }
 
@@ -1577,11 +1501,8 @@ ReceiveArchiveStreamChunk(size_t r, char *copybuf, void *callback_data)
                                                state->manifest_file =
                                                        fopen(state->manifest_filename, "wb");
                                                if (state->manifest_file == NULL)
-                                               {
-                                                       pg_log_error("could not create file \"%s\": %m",
-                                                                                state->manifest_filename);
-                                                       exit(1);
-                                               }
+                                                       pg_fatal("could not create file \"%s\": %m",
+                                                                        state->manifest_filename);
                                        }
                                }
                                break;
@@ -1670,11 +1591,10 @@ static void
 ReportCopyDataParseError(size_t r, char *copybuf)
 {
        if (r == 0)
-               pg_log_error("empty COPY message");
+               pg_fatal("empty COPY message");
        else
-               pg_log_error("malformed COPY message of type %d, length %zu",
-                                        copybuf[0], r);
-       exit(1);
+               pg_fatal("malformed COPY message of type %d, length %zu",
+                                copybuf[0], r);
 }
 
 /*
@@ -1720,10 +1640,7 @@ ReceiveTarFile(PGconn *conn, char *archive_name, char *spclocation,
                initPQExpBuffer(&buf);
                ReceiveBackupManifestInMemory(conn, &buf);
                if (PQExpBufferDataBroken(buf))
-               {
-                       pg_log_error("out of memory");
-                       exit(1);
-               }
+                       pg_fatal("out of memory");
 
                /* Inject it into the output tarfile. */
                bbstreamer_inject_file(manifest_inject_streamer, "backup_manifest",
@@ -1793,10 +1710,7 @@ ReceiveBackupManifest(PGconn *conn)
                         "%s/backup_manifest.tmp", basedir);
        state.file = fopen(state.filename, "wb");
        if (state.file == NULL)
-       {
-               pg_log_error("could not create file \"%s\": %m", state.filename);
-               exit(1);
-       }
+               pg_fatal("could not create file \"%s\": %m", state.filename);
 
        ReceiveCopyData(conn, ReceiveBackupManifestChunk, &state);
 
@@ -1817,8 +1731,7 @@ ReceiveBackupManifestChunk(size_t r, char *copybuf, void *callback_data)
                /* if write didn't set errno, assume problem is no disk space */
                if (errno == 0)
                        errno = ENOSPC;
-               pg_log_error("could not write to file \"%s\": %m", state->filename);
-               exit(1);
+               pg_fatal("could not write to file \"%s\": %m", state->filename);
        }
 }
 
@@ -1878,9 +1791,8 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
        {
                const char *serverver = PQparameterStatus(conn, "server_version");
 
-               pg_log_error("incompatible server version %s",
-                                        serverver ? serverver : "'unknown'");
-               exit(1);
+               pg_fatal("incompatible server version %s",
+                                serverver ? serverver : "'unknown'");
        }
        if (serverMajor >= 1500)
                use_new_option_syntax = true;
@@ -1963,16 +1875,10 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
                char       *colon;
 
                if (serverMajor < 1500)
-               {
-                       pg_log_error("backup targets are not supported by this server version");
-                       exit(1);
-               }
+                       pg_fatal("backup targets are not supported by this server version");
 
                if (writerecoveryconf)
-               {
-                       pg_log_error("recovery configuration cannot be written when a backup target is used");
-                       exit(1);
-               }
+                       pg_fatal("recovery configuration cannot be written when a backup target is used");
 
                AppendPlainCommandOption(&buf, use_new_option_syntax, "TABLESPACE_MAP");
 
@@ -1999,10 +1905,7 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
        if (compressloc == COMPRESS_LOCATION_SERVER)
        {
                if (!use_new_option_syntax)
-               {
-                       pg_log_error("server does not support server-side compression");
-                       exit(1);
-               }
+                       pg_fatal("server does not support server-side compression");
                AppendStringCommandOption(&buf, use_new_option_syntax,
                                                                  "COMPRESSION", compression_algorithm);
                if (compression_detail != NULL)
@@ -2029,28 +1932,19 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
                basebkp = psprintf("BASE_BACKUP %s", buf.data);
 
        if (PQsendQuery(conn, basebkp) == 0)
-       {
-               pg_log_error("could not send replication command \"%s\": %s",
-                                        "BASE_BACKUP", PQerrorMessage(conn));
-               exit(1);
-       }
+               pg_fatal("could not send replication command \"%s\": %s",
+                                "BASE_BACKUP", PQerrorMessage(conn));
 
        /*
         * Get the starting WAL location
         */
        res = PQgetResult(conn);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
-       {
-               pg_log_error("could not initiate base backup: %s",
-                                        PQerrorMessage(conn));
-               exit(1);
-       }
+               pg_fatal("could not initiate base backup: %s",
+                                PQerrorMessage(conn));
        if (PQntuples(res) != 1)
-       {
-               pg_log_error("server returned unexpected response to BASE_BACKUP command; got %d rows and %d fields, expected %d rows and %d fields",
-                                        PQntuples(res), PQnfields(res), 1, 2);
-               exit(1);
-       }
+               pg_fatal("server returned unexpected response to BASE_BACKUP command; got %d rows and %d fields, expected %d rows and %d fields",
+                                PQntuples(res), PQnfields(res), 1, 2);
 
        strlcpy(xlogstart, PQgetvalue(res, 0, 0), sizeof(xlogstart));
 
@@ -2078,16 +1972,10 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
         */
        res = PQgetResult(conn);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
-       {
-               pg_log_error("could not get backup header: %s",
-                                        PQerrorMessage(conn));
-               exit(1);
-       }
+               pg_fatal("could not get backup header: %s",
+                                PQerrorMessage(conn));
        if (PQntuples(res) < 1)
-       {
-               pg_log_error("no data returned from server");
-               exit(1);
-       }
+               pg_fatal("no data returned from server");
 
        /*
         * Sum up the total size, for progress reporting
@@ -2122,11 +2010,8 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
        writing_to_stdout = format == 't' && basedir != NULL &&
                strcmp(basedir, "-") == 0;
        if (writing_to_stdout && PQntuples(res) > 1)
-       {
-               pg_log_error("can only write single tablespace to stdout, database has %d",
-                                        PQntuples(res));
-               exit(1);
-       }
+               pg_fatal("can only write single tablespace to stdout, database has %d",
+                                PQntuples(res));
 
        /*
         * If we're streaming WAL, start the streaming session before we start
@@ -2221,16 +2106,10 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
         */
        res = PQgetResult(conn);
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
-       {
-               pg_log_error("backup failed: %s",
-                                        PQerrorMessage(conn));
-               exit(1);
-       }
+               pg_fatal("backup failed: %s",
+                                PQerrorMessage(conn));
        if (PQntuples(res) != 1)
-       {
-               pg_log_error("no write-ahead log end position returned from server");
-               exit(1);
-       }
+               pg_fatal("no write-ahead log end position returned from server");
        strlcpy(xlogend, PQgetvalue(res, 0, 0), sizeof(xlogend));
        if (verbose && includewal != NO_WAL)
                pg_log_info("write-ahead log end point: %s", xlogend);
@@ -2277,28 +2156,16 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
 
 #ifndef WIN32
                if (write(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
-               {
-                       pg_log_info("could not send command to background pipe: %m");
-                       exit(1);
-               }
+                       pg_fatal("could not send command to background pipe: %m");
 
                /* Just wait for the background process to exit */
                r = waitpid(bgchild, &status, 0);
                if (r == (pid_t) -1)
-               {
-                       pg_log_error("could not wait for child process: %m");
-                       exit(1);
-               }
+                       pg_fatal("could not wait for child process: %m");
                if (r != bgchild)
-               {
-                       pg_log_error("child %d died, expected %d", (int) r, (int) bgchild);
-                       exit(1);
-               }
+                       pg_fatal("child %d died, expected %d", (int) r, (int) bgchild);
                if (status != 0)
-               {
-                       pg_log_error("%s", wait_result_to_str(status));
-                       exit(1);
-               }
+                       pg_fatal("%s", wait_result_to_str(status));
                /* Exited normally, we're happy! */
 #else                                                  /* WIN32 */
 
@@ -2308,11 +2175,8 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
                 * it's there.
                 */
                if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
-               {
-                       pg_log_error("could not parse write-ahead log location \"%s\"",
-                                                xlogend);
-                       exit(1);
-               }
+                       pg_fatal("could not parse write-ahead log location \"%s\"",
+                                        xlogend);
                xlogendptr = ((uint64) hi) << 32 | lo;
                InterlockedIncrement(&has_xlogendptr);
 
@@ -2321,21 +2185,16 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
                        WAIT_OBJECT_0)
                {
                        _dosmaperr(GetLastError());
-                       pg_log_error("could not wait for child thread: %m");
-                       exit(1);
+                       pg_fatal("could not wait for child thread: %m");
                }
                if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
                {
                        _dosmaperr(GetLastError());
-                       pg_log_error("could not get child thread exit status: %m");
-                       exit(1);
+                       pg_fatal("could not get child thread exit status: %m");
                }
                if (status != 0)
-               {
-                       pg_log_error("child thread exited with error %u",
-                                                (unsigned int) status);
-                       exit(1);
-               }
+                       pg_fatal("child thread exited with error %u",
+                                        (unsigned int) status);
                /* Exited normally, we're happy */
 #endif
        }
@@ -2402,11 +2261,8 @@ BaseBackup(char *compression_algorithm, char *compression_detail,
                else
                {
                        if (rename(tmp_filename, filename) != 0)
-                       {
-                               pg_log_error("could not rename file \"%s\" to \"%s\": %m",
-                                                        tmp_filename, filename);
-                               exit(1);
-                       }
+                               pg_fatal("could not rename file \"%s\" to \"%s\": %m",
+                                                tmp_filename, filename);
                }
        }
 
@@ -2500,11 +2356,8 @@ main(int argc, char **argv)
                                else if (strcmp(optarg, "t") == 0 || strcmp(optarg, "tar") == 0)
                                        format = 't';
                                else
-                               {
-                                       pg_log_error("invalid output format \"%s\", must be \"plain\" or \"tar\"",
-                                                                optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid output format \"%s\", must be \"plain\" or \"tar\"",
+                                                        optarg);
                                break;
                        case 'r':
                                maxrate = parse_max_rate(optarg);
@@ -2547,11 +2400,8 @@ main(int argc, char **argv)
                                        includewal = STREAM_WAL;
                                }
                                else
-                               {
-                                       pg_log_error("invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"",
-                                                                optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"",
+                                                        optarg);
                                break;
                        case 1:
                                xlog_dir = pg_strdup(optarg);
@@ -2580,11 +2430,8 @@ main(int argc, char **argv)
                                else if (pg_strcasecmp(optarg, "spread") == 0)
                                        fastcheckpoint = false;
                                else
-                               {
-                                       pg_log_error("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
-                                                                optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
+                                                        optarg);
                                break;
                        case 'd':
                                connection_string = pg_strdup(optarg);
@@ -2633,12 +2480,8 @@ main(int argc, char **argv)
                                manifest_checksums = pg_strdup(optarg);
                                break;
                        default:
-
-                               /*
-                                * getopt_long already emitted a complaint
-                                */
-                               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);
                }
        }
@@ -2650,8 +2493,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);
        }
 
@@ -2673,8 +2515,7 @@ main(int argc, char **argv)
        if (backup_target != NULL && format != '\0')
        {
                pg_log_error("cannot specify both format and backup target");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
        if (format == '\0')
@@ -2686,15 +2527,13 @@ main(int argc, char **argv)
        if (basedir == NULL && backup_target == NULL)
        {
                pg_log_error("must specify output directory or backup target");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
        if (basedir != NULL && backup_target != NULL)
        {
                pg_log_error("cannot specify both output directory and backup target");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2723,20 +2562,14 @@ main(int argc, char **argv)
                char       *error_detail;
 
                if (!parse_bc_algorithm(compression_algorithm, &alg))
-               {
-                       pg_log_error("unrecognized compression algorithm \"%s\"",
-                                                compression_algorithm);
-                       exit(1);
-               }
+                       pg_fatal("unrecognized compression algorithm \"%s\"",
+                                        compression_algorithm);
 
                parse_bc_specification(alg, compression_detail, &client_compress);
                error_detail = validate_bc_specification(&client_compress);
                if (error_detail != NULL)
-               {
-                       pg_log_error("invalid compression specification: %s",
-                                                error_detail);
-                       exit(1);
-               }
+                       pg_fatal("invalid compression specification: %s",
+                                        error_detail);
        }
        else
        {
@@ -2752,8 +2585,7 @@ main(int argc, char **argv)
        if (backup_target != NULL && compressloc == COMPRESS_LOCATION_CLIENT)
        {
                pg_log_error("client-side compression is not possible when a backup target is specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2764,8 +2596,7 @@ main(int argc, char **argv)
                client_compress.algorithm != BACKUP_COMPRESSION_NONE)
        {
                pg_log_error("only tar mode backups can be compressed");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2775,23 +2606,20 @@ main(int argc, char **argv)
        if (backup_target != NULL && includewal == STREAM_WAL)
        {
                pg_log_error("WAL cannot be streamed when a backup target is specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
        if (format == 't' && includewal == STREAM_WAL && strcmp(basedir, "-") == 0)
        {
                pg_log_error("cannot stream write-ahead logs in tar mode to stdout");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (replication_slot && includewal != STREAM_WAL)
        {
                pg_log_error("replication slots can only be used with WAL streaming");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2803,8 +2631,7 @@ main(int argc, char **argv)
                if (replication_slot)
                {
                        pg_log_error("--no-slot cannot be used with slot name");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
                temp_replication_slot = false;
@@ -2816,8 +2643,7 @@ main(int argc, char **argv)
                {
                        pg_log_error("%s needs a slot to be specified using --slot",
                                                 "--create-slot");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
 
@@ -2825,8 +2651,7 @@ main(int argc, char **argv)
                {
                        pg_log_error("%s and %s are incompatible options",
                                                 "--create-slot", "--no-slot");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
        }
@@ -2839,15 +2664,13 @@ main(int argc, char **argv)
                if (backup_target != NULL)
                {
                        pg_log_error("WAL directory location cannot be specified along with a backup target");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
                if (format != 'p')
                {
                        pg_log_error("WAL directory location can only be specified in plain mode");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
 
@@ -2856,8 +2679,7 @@ main(int argc, char **argv)
                if (!is_absolute_path(xlog_dir))
                {
                        pg_log_error("WAL directory location must be an absolute path");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                       progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
        }
@@ -2869,8 +2691,7 @@ main(int argc, char **argv)
        {
                pg_log_error("%s and %s are incompatible options",
                                         "--progress", "--no-estimate-size");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2881,8 +2702,7 @@ main(int argc, char **argv)
        {
                pg_log_error("%s and %s are incompatible options",
                                         "--no-manifest", "--manifest-checksums");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2890,8 +2710,7 @@ main(int argc, char **argv)
        {
                pg_log_error("%s and %s are incompatible options",
                                         "--no-manifest", "--manifest-force-encode");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -2959,13 +2778,9 @@ main(int argc, char **argv)
 
 #ifdef HAVE_SYMLINK
                if (symlink(xlog_dir, linkloc) != 0)
-               {
-                       pg_log_error("could not create symbolic link \"%s\": %m", linkloc);
-                       exit(1);
-               }
+                       pg_fatal("could not create symbolic link \"%s\": %m", linkloc);
 #else
-               pg_log_error("symlinks are not supported on this platform");
-               exit(1);
+               pg_fatal("symlinks are not supported on this platform");
 #endif
                free(linkloc);
        }
index 8d2c1e6ce01cbcf272f1ff0b1ba0d8f4fa3e8ee4..23e04741fd5f7accc61ca426b04d7cabd4411b3b 100644 (file)
@@ -239,10 +239,7 @@ get_destination_dir(char *dest_folder)
        Assert(dest_folder != NULL);
        dir = opendir(dest_folder);
        if (dir == NULL)
-       {
-               pg_log_error("could not open directory \"%s\": %m", dest_folder);
-               exit(1);
-       }
+               pg_fatal("could not open directory \"%s\": %m", dest_folder);
 
        return dir;
 }
@@ -256,10 +253,7 @@ close_destination_dir(DIR *dest_dir, char *dest_folder)
 {
        Assert(dest_dir != NULL && dest_folder != NULL);
        if (closedir(dest_dir))
-       {
-               pg_log_error("could not close directory \"%s\": %m", dest_folder);
-               exit(1);
-       }
+               pg_fatal("could not close directory \"%s\": %m", dest_folder);
 }
 
 
@@ -322,10 +316,7 @@ FindStreamingStart(uint32 *tli)
 
                        snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
                        if (stat(fullpath, &statbuf) != 0)
-                       {
-                               pg_log_error("could not stat file \"%s\": %m", fullpath);
-                               exit(1);
-                       }
+                               pg_fatal("could not stat file \"%s\": %m", fullpath);
 
                        if (statbuf.st_size != WalSegSz)
                        {
@@ -346,27 +337,20 @@ FindStreamingStart(uint32 *tli)
 
                        fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
                        if (fd < 0)
-                       {
-                               pg_log_error("could not open compressed file \"%s\": %m",
-                                                        fullpath);
-                               exit(1);
-                       }
+                               pg_fatal("could not open compressed file \"%s\": %m",
+                                                fullpath);
                        if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
-                       {
-                               pg_log_error("could not seek in compressed file \"%s\": %m",
-                                                        fullpath);
-                               exit(1);
-                       }
+                               pg_fatal("could not seek in compressed file \"%s\": %m",
+                                                fullpath);
                        r = read(fd, (char *) buf, sizeof(buf));
                        if (r != sizeof(buf))
                        {
                                if (r < 0)
-                                       pg_log_error("could not read compressed file \"%s\": %m",
-                                                                fullpath);
+                                       pg_fatal("could not read compressed file \"%s\": %m",
+                                                        fullpath);
                                else
-                                       pg_log_error("could not read compressed file \"%s\": read %d of %zu",
-                                                                fullpath, r, sizeof(buf));
-                               exit(1);
+                                       pg_fatal("could not read compressed file \"%s\": read %d of %zu",
+                                                        fullpath, r, sizeof(buf));
                        }
 
                        close(fd);
@@ -399,18 +383,12 @@ FindStreamingStart(uint32 *tli)
 
                        fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
                        if (fd < 0)
-                       {
-                               pg_log_error("could not open file \"%s\": %m", fullpath);
-                               exit(1);
-                       }
+                               pg_fatal("could not open file \"%s\": %m", fullpath);
 
                        status = LZ4F_createDecompressionContext(&ctx, LZ4F_VERSION);
                        if (LZ4F_isError(status))
-                       {
-                               pg_log_error("could not create LZ4 decompression context: %s",
-                                                        LZ4F_getErrorName(status));
-                               exit(1);
-                       }
+                               pg_fatal("could not create LZ4 decompression context: %s",
+                                                LZ4F_getErrorName(status));
 
                        outbuf = pg_malloc0(LZ4_CHUNK_SZ);
                        readbuf = pg_malloc0(LZ4_CHUNK_SZ);
@@ -421,10 +399,7 @@ FindStreamingStart(uint32 *tli)
 
                                r = read(fd, readbuf, LZ4_CHUNK_SZ);
                                if (r < 0)
-                               {
-                                       pg_log_error("could not read file \"%s\": %m", fullpath);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not read file \"%s\": %m", fullpath);
 
                                /* Done reading the file */
                                if (r == 0)
@@ -442,12 +417,9 @@ FindStreamingStart(uint32 *tli)
                                        status = LZ4F_decompress(ctx, outbuf, &out_size,
                                                                                         readp, &read_size, &dec_opt);
                                        if (LZ4F_isError(status))
-                                       {
-                                               pg_log_error("could not decompress file \"%s\": %s",
-                                                                        fullpath,
-                                                                        LZ4F_getErrorName(status));
-                                               exit(1);
-                                       }
+                                               pg_fatal("could not decompress file \"%s\": %s",
+                                                                fullpath,
+                                                                LZ4F_getErrorName(status));
 
                                        readp += read_size;
                                        uncompressed_size += out_size;
@@ -468,11 +440,8 @@ FindStreamingStart(uint32 *tli)
 
                        status = LZ4F_freeDecompressionContext(ctx);
                        if (LZ4F_isError(status))
-                       {
-                               pg_log_error("could not free LZ4 decompression context: %s",
-                                                        LZ4F_getErrorName(status));
-                               exit(1);
-                       }
+                               pg_fatal("could not free LZ4 decompression context: %s",
+                                                LZ4F_getErrorName(status));
 
                        if (uncompressed_size != WalSegSz)
                        {
@@ -483,8 +452,8 @@ FindStreamingStart(uint32 *tli)
 #else
                        pg_log_error("could not check file \"%s\"",
                                                 dirent->d_name);
-                       pg_log_error("this build does not support compression with %s",
-                                                "LZ4");
+                       pg_log_error_detail("This build does not support compression with %s.",
+                                                               "LZ4");
                        exit(1);
 #endif
                }
@@ -501,10 +470,7 @@ FindStreamingStart(uint32 *tli)
        }
 
        if (errno)
-       {
-               pg_log_error("could not read directory \"%s\": %m", basedir);
-               exit(1);
-       }
+               pg_fatal("could not read directory \"%s\": %m", basedir);
 
        close_destination_dir(dir, basedir);
 
@@ -752,10 +718,7 @@ main(int argc, char **argv)
                                break;
                        case 'E':
                                if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
-                               {
-                                       pg_log_error("could not parse end position \"%s\"", optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not parse end position \"%s\"", optarg);
                                endpos = ((uint64) hi) << 32 | lo;
                                break;
                        case 'n':
@@ -793,19 +756,12 @@ main(int argc, char **argv)
                                else if (pg_strcasecmp(optarg, "none") == 0)
                                        compression_method = COMPRESSION_NONE;
                                else
-                               {
-                                       pg_log_error("invalid value \"%s\" for option %s",
-                                                                optarg, "--compression-method");
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid value \"%s\" for option %s",
+                                                        optarg, "--compression-method");
                                break;
                        default:
-
-                               /*
-                                * getopt_long already emitted a complaint
-                                */
-                               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);
                }
        }
@@ -817,16 +773,14 @@ 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);
        }
 
        if (do_drop_slot && do_create_slot)
        {
                pg_log_error("cannot use --create-slot together with --drop-slot");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -835,16 +789,14 @@ main(int argc, char **argv)
                /* translator: second %s is an option name */
                pg_log_error("%s needs a slot to be specified using --slot",
                                         do_drop_slot ? "--drop-slot" : "--create-slot");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (synchronous && !do_sync)
        {
                pg_log_error("cannot use --synchronous together with --no-sync");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -854,8 +806,7 @@ main(int argc, char **argv)
        if (basedir == NULL && !do_drop_slot && !do_create_slot)
        {
                pg_log_error("no target directory specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -870,8 +821,7 @@ main(int argc, char **argv)
                        {
                                pg_log_error("cannot use --compress with --compression-method=%s",
                                                         "none");
-                               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                               progname);
+                               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                                exit(1);
                        }
                        break;
@@ -883,9 +833,8 @@ main(int argc, char **argv)
                                compresslevel = Z_DEFAULT_COMPRESSION;
                        }
 #else
-                       pg_log_error("this build does not support compression with %s",
-                                                "gzip");
-                       exit(1);
+                       pg_fatal("this build does not support compression with %s",
+                                        "gzip");
 #endif
                        break;
                case COMPRESSION_LZ4:
@@ -894,20 +843,17 @@ main(int argc, char **argv)
                        {
                                pg_log_error("cannot use --compress with --compression-method=%s",
                                                         "lz4");
-                               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                                               progname);
+                               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                                exit(1);
                        }
 #else
-                       pg_log_error("this build does not support compression with %s",
-                                                "LZ4");
-                       exit(1);
+                       pg_fatal("this build does not support compression with %s",
+                                        "LZ4");
 #endif
                        break;
                case COMPRESSION_ZSTD:
-                       pg_log_error("compression with %s is not yet supported", "ZSTD");
-                       exit(1);
-
+                       pg_fatal("compression with %s is not yet supported", "ZSTD");
+                       break;
        }
 
 
@@ -951,11 +897,8 @@ main(int argc, char **argv)
         * be defined in this context.
         */
        if (db_name)
-       {
-               pg_log_error("replication connection using slot \"%s\" is unexpectedly database specific",
-                                        replication_slot);
-               exit(1);
-       }
+               pg_fatal("replication connection using slot \"%s\" is unexpectedly database specific",
+                                replication_slot);
 
        /*
         * Set umask so that directories/files are created with the same
@@ -1013,10 +956,7 @@ main(int argc, char **argv)
                        exit(0);
                }
                else if (noloop)
-               {
-                       pg_log_error("disconnected");
-                       exit(1);
-               }
+                       pg_fatal("disconnected");
                else
                {
                        /* translator: check source for value for %d */
index cc35d16f32a9392009f77f606f6941b4f5bf3141..b59ff23f6125e732b57a9dc8015a70d3f2ec23af 100644 (file)
@@ -193,10 +193,7 @@ OutputFsync(TimestampTz now)
                return true;
 
        if (fsync(outfd) != 0)
-       {
-               pg_log_fatal("could not fsync file \"%s\": %m", outfile);
-               exit(1);
-       }
+               pg_fatal("could not fsync file \"%s\": %m", outfile);
 
        return true;
 }
@@ -780,18 +777,12 @@ main(int argc, char **argv)
 /* replication options */
                        case 'I':
                                if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
-                               {
-                                       pg_log_error("could not parse start position \"%s\"", optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not parse start position \"%s\"", optarg);
                                startpos = ((uint64) hi) << 32 | lo;
                                break;
                        case 'E':
                                if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
-                               {
-                                       pg_log_error("could not parse end position \"%s\"", optarg);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not parse end position \"%s\"", optarg);
                                endpos = ((uint64) hi) << 32 | lo;
                                break;
                        case 'o':
@@ -842,12 +833,8 @@ main(int argc, char **argv)
                                break;
 
                        default:
-
-                               /*
-                                * getopt_long already emitted a complaint
-                                */
-                               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);
                }
        }
@@ -859,8 +846,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);
        }
 
@@ -870,64 +856,56 @@ main(int argc, char **argv)
        if (replication_slot == NULL)
        {
                pg_log_error("no slot specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (do_start_slot && outfile == NULL)
        {
                pg_log_error("no target file specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (!do_drop_slot && dbname == NULL)
        {
                pg_log_error("no database specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (!do_drop_slot && !do_create_slot && !do_start_slot)
        {
                pg_log_error("at least one action needs to be specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (do_drop_slot && (do_create_slot || do_start_slot))
        {
                pg_log_error("cannot use --create-slot or --start together with --drop-slot");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (startpos != InvalidXLogRecPtr && (do_create_slot || do_drop_slot))
        {
                pg_log_error("cannot use --create-slot or --drop-slot together with --startpos");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (endpos != InvalidXLogRecPtr && !do_start_slot)
        {
                pg_log_error("--endpos may only be specified with --start");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        if (two_phase && !do_create_slot)
        {
                pg_log_error("--two-phase may only be specified with --create-slot");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
@@ -958,10 +936,7 @@ main(int argc, char **argv)
                exit(1);
 
        if (db_name == NULL)
-       {
-               pg_log_error("could not establish database-specific replication connection");
-               exit(1);
-       }
+               pg_fatal("could not establish database-specific replication connection");
 
        /*
         * Set umask so that directories/files are created with the same
@@ -1011,10 +986,7 @@ main(int argc, char **argv)
                        exit(0);
                }
                else if (noloop)
-               {
-                       pg_log_error("disconnected");
-                       exit(1);
-               }
+                       pg_fatal("disconnected");
                else
                {
                        /* translator: check source for value for %d */
index d39e4b11a1adf9c0d001ce22988c1bdce5b7b32d..42d50931d32dee9a360c0085f70e533fb9801fa3 100644 (file)
@@ -140,7 +140,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
                        /* fsync file in case of a previous crash */
                        if (stream->walmethod->sync(f) != 0)
                        {
-                               pg_log_fatal("could not fsync existing write-ahead log file \"%s\": %s",
+                               pg_log_error("could not fsync existing write-ahead log file \"%s\": %s",
                                                         fn, stream->walmethod->getlasterror());
                                stream->walmethod->close(f, CLOSE_UNLINK);
                                exit(1);
@@ -778,11 +778,8 @@ HandleCopyStream(PGconn *conn, StreamCtl *stream,
                if (stream->synchronous && lastFlushPosition < blockpos && walfile != NULL)
                {
                        if (stream->walmethod->sync(walfile) != 0)
-                       {
-                               pg_log_fatal("could not fsync file \"%s\": %s",
-                                                        current_walfile_name, stream->walmethod->getlasterror());
-                               exit(1);
-                       }
+                               pg_fatal("could not fsync file \"%s\": %s",
+                                                current_walfile_name, stream->walmethod->getlasterror());
                        lastFlushPosition = blockpos;
 
                        /*
@@ -1030,11 +1027,8 @@ ProcessKeepaliveMsg(PGconn *conn, StreamCtl *stream, char *copybuf, int len,
                         * shutdown of the server.
                         */
                        if (stream->walmethod->sync(walfile) != 0)
-                       {
-                               pg_log_fatal("could not fsync file \"%s\": %s",
-                                                        current_walfile_name, stream->walmethod->getlasterror());
-                               exit(1);
-                       }
+                               pg_fatal("could not fsync file \"%s\": %s",
+                                                current_walfile_name, stream->walmethod->getlasterror());
                        lastFlushPosition = blockpos;
                }
 
index 4a6afd1a068e418fe43089a0a29afca7b9fc9c95..86c0493a949166f281073c547e5d7bb71d0ef913 100644 (file)
@@ -88,10 +88,7 @@ GetConnection(void)
        {
                conn_opts = PQconninfoParse(connection_string, &err_msg);
                if (conn_opts == NULL)
-               {
-                       pg_log_error("%s", err_msg);
-                       exit(1);
-               }
+                       pg_fatal("%s", err_msg);
 
                for (conn_opt = conn_opts; conn_opt->keyword != NULL; conn_opt++)
                {
@@ -182,10 +179,7 @@ GetConnection(void)
                 * and PQconnectdbParams returns NULL, we call exit(1) directly.
                 */
                if (!tmpconn)
-               {
-                       pg_log_error("could not connect to server");
-                       exit(1);
-               }
+                       pg_fatal("could not connect to server");
 
                /* If we need a password and -w wasn't given, loop back and get one */
                if (PQstatus(tmpconn) == CONNECTION_BAD &&
index 1e0ff760ebaee008152ec83a7cda8a4a5a10ad5d..acd242d2c993c7a1e15872ae06a5211cbf385abf 100644 (file)
@@ -1195,9 +1195,8 @@ tar_close(Walfile f, WalCloseMethod method)
        if (tar_sync(f) < 0)
        {
                /* XXX this seems pretty bogus; why is only this case fatal? */
-               pg_log_fatal("could not fsync file \"%s\": %s",
-                                        tf->pathname, tar_getlasterror());
-               exit(1);
+               pg_fatal("could not fsync file \"%s\": %s",
+                                tf->pathname, tar_getlasterror());
        }
 
        /* Clean up and done */
index 5f0f5ee62d034320e388eece7677e98ce6fc3186..21dfe1b6ee5c560fea32ca1ea751ccba9b22b3cd 100644 (file)
@@ -197,10 +197,7 @@ scan_file(const char *fn, int segmentno)
        f = open(fn, PG_BINARY | flags, 0);
 
        if (f < 0)
-       {
-               pg_log_error("could not open file \"%s\": %m", fn);
-               exit(1);
-       }
+               pg_fatal("could not open file \"%s\": %m", fn);
 
        files_scanned++;
 
@@ -214,12 +211,11 @@ scan_file(const char *fn, int segmentno)
                if (r != BLCKSZ)
                {
                        if (r < 0)
-                               pg_log_error("could not read block %u in file \"%s\": %m",
-                                                        blockno, fn);
+                               pg_fatal("could not read block %u in file \"%s\": %m",
+                                                blockno, fn);
                        else
-                               pg_log_error("could not read block %u in file \"%s\": read %d of %d",
-                                                        blockno, fn, r, BLCKSZ);
-                       exit(1);
+                               pg_fatal("could not read block %u in file \"%s\": read %d of %d",
+                                                blockno, fn, r, BLCKSZ);
                }
                blocks_scanned++;
 
@@ -264,22 +260,18 @@ scan_file(const char *fn, int segmentno)
 
                        /* Seek back to beginning of block */
                        if (lseek(f, -BLCKSZ, SEEK_CUR) < 0)
-                       {
-                               pg_log_error("seek failed for block %u in file \"%s\": %m", blockno, fn);
-                               exit(1);
-                       }
+                               pg_fatal("seek failed for block %u in file \"%s\": %m", blockno, fn);
 
                        /* Write block with checksum */
                        w = write(f, buf.data, BLCKSZ);
                        if (w != BLCKSZ)
                        {
                                if (w < 0)
-                                       pg_log_error("could not write block %u in file \"%s\": %m",
-                                                                blockno, fn);
+                                       pg_fatal("could not write block %u in file \"%s\": %m",
+                                                        blockno, fn);
                                else
-                                       pg_log_error("could not write block %u in file \"%s\": wrote %d of %d",
-                                                                blockno, fn, w, BLCKSZ);
-                               exit(1);
+                                       pg_fatal("could not write block %u in file \"%s\": wrote %d of %d",
+                                                        blockno, fn, w, BLCKSZ);
                        }
                }
 
@@ -323,10 +315,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
        snprintf(path, sizeof(path), "%s/%s", basedir, subdir);
        dir = opendir(path);
        if (!dir)
-       {
-               pg_log_error("could not open directory \"%s\": %m", path);
-               exit(1);
-       }
+               pg_fatal("could not open directory \"%s\": %m", path);
        while ((de = readdir(dir)) != NULL)
        {
                char            fn[MAXPGPATH];
@@ -350,10 +339,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
 
                snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
                if (lstat(fn, &st) < 0)
-               {
-                       pg_log_error("could not stat file \"%s\": %m", fn);
-                       exit(1);
-               }
+                       pg_fatal("could not stat file \"%s\": %m", fn);
                if (S_ISREG(st.st_mode))
                {
                        char            fnonly[MAXPGPATH];
@@ -377,11 +363,8 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
                                *segmentpath++ = '\0';
                                segmentno = atoi(segmentpath);
                                if (segmentno == 0)
-                               {
-                                       pg_log_error("invalid segment number %d in file name \"%s\"",
-                                                                segmentno, fn);
-                                       exit(1);
-                               }
+                                       pg_fatal("invalid segment number %d in file name \"%s\"",
+                                                        segmentno, fn);
                        }
 
                        forkpath = strchr(fnonly, '_');
@@ -429,11 +412,8 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
                                                 path, de->d_name, TABLESPACE_VERSION_DIRECTORY);
 
                                if (lstat(tblspc_path, &tblspc_st) < 0)
-                               {
-                                       pg_log_error("could not stat file \"%s\": %m",
-                                                                tblspc_path);
-                                       exit(1);
-                               }
+                                       pg_fatal("could not stat file \"%s\": %m",
+                                                        tblspc_path);
 
                                /*
                                 * Move backwards once as the scan needs to happen for the
@@ -528,7 +508,8 @@ main(int argc, char *argv[])
                                showprogress = true;
                                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);
                }
        }
@@ -544,7 +525,7 @@ main(int argc, char *argv[])
                if (DataDir == NULL)
                {
                        pg_log_error("no data directory specified");
-                       fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+                       pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                        exit(1);
                }
        }
@@ -554,8 +535,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);
        }
 
@@ -563,30 +543,23 @@ main(int argc, char *argv[])
        if (mode != PG_MODE_CHECK && only_filenode)
        {
                pg_log_error("option -f/--filenode can only be used with --check");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
-                               progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
        /* Read the control file and check compatibility */
        ControlFile = get_controlfile(DataDir, &crc_ok);
        if (!crc_ok)
-       {
-               pg_log_error("pg_control CRC value is incorrect");
-               exit(1);
-       }
+               pg_fatal("pg_control CRC value is incorrect");
 
        if (ControlFile->pg_control_version != PG_CONTROL_VERSION)
-       {
-               pg_log_error("cluster is not compatible with this version of pg_checksums");
-               exit(1);
-       }
+               pg_fatal("cluster is not compatible with this version of pg_checksums");
 
        if (ControlFile->blcksz != BLCKSZ)
        {
                pg_log_error("database cluster is not compatible");
-               fprintf(stderr, _("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.\n"),
-                               ControlFile->blcksz, BLCKSZ);
+               pg_log_error_detail("The database cluster was initialized with block size %u, but pg_checksums was compiled with block size %u.",
+                                                       ControlFile->blcksz, BLCKSZ);
                exit(1);
        }
 
@@ -597,31 +570,19 @@ main(int argc, char *argv[])
         */
        if (ControlFile->state != DB_SHUTDOWNED &&
                ControlFile->state != DB_SHUTDOWNED_IN_RECOVERY)
-       {
-               pg_log_error("cluster must be shut down");
-               exit(1);
-       }
+               pg_fatal("cluster must be shut down");
 
        if (ControlFile->data_checksum_version == 0 &&
                mode == PG_MODE_CHECK)
-       {
-               pg_log_error("data checksums are not enabled in cluster");
-               exit(1);
-       }
+               pg_fatal("data checksums are not enabled in cluster");
 
        if (ControlFile->data_checksum_version == 0 &&
                mode == PG_MODE_DISABLE)
-       {
-               pg_log_error("data checksums are already disabled in cluster");
-               exit(1);
-       }
+               pg_fatal("data checksums are already disabled in cluster");
 
        if (ControlFile->data_checksum_version > 0 &&
                mode == PG_MODE_ENABLE)
-       {
-               pg_log_error("data checksums are already enabled in cluster");
-               exit(1);
-       }
+               pg_fatal("data checksums are already enabled in cluster");
 
        /* Operate on all files if checking or enabling checksums */
        if (mode == PG_MODE_CHECK || mode == PG_MODE_ENABLE)
index f911f98d946d83f1191abf35239d9b4455c5f52a..c390ec51ce9b427da2d17328a4944b65e9018897 100644 (file)
@@ -134,7 +134,8 @@ main(int argc, char *argv[])
                                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);
                }
        }
@@ -152,15 +153,14 @@ 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);
        }
 
        if (DataDir == NULL)
        {
                pg_log_error("no data directory specified");
-               fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
+               pg_log_error_hint("Try \"%s --help\" for more information.", progname);
                exit(1);
        }
 
index 3a9092a16a6e2d9471e32979742474c4446744ee..f605e02da887297ce879b305d4c4f72ff6dc0cd9 100644 (file)
@@ -886,14 +886,10 @@ find_other_exec_or_die(const char *argv0, const char *target, const char *versio
                        strlcpy(full_path, progname, sizeof(full_path));
 
                if (ret == -1)
-                       write_stderr(_("The program \"%s\" is needed by %s but was not found in the\n"
-                                                  "same directory as \"%s\".\n"
-                                                  "Check your installation.\n"),
+                       write_stderr(_("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"\n"),
                                                 target, progname, full_path);
                else
-                       write_stderr(_("The program \"%s\" was found by \"%s\"\n"
-                                                  "but was not the same version as %s.\n"
-                                                  "Check your installation.\n"),
+                       write_stderr(_("program \"%s\" was found by \"%s\" but was not the same version as %s\n"),
                                                 target, full_path, progname);
                exit(1);
        }
index b9a25442f5fd3bb9c0a95466b1c2274dd53ef1a2..794e6e7ce99e3397c330ca9d1bd01de3e6ca6c2c 100644 (file)
@@ -340,9 +340,9 @@ flagInhTables(Archive *fout, TableInfo *tblinfo, int numTables,
 
                        /* With partitions there can only be one parent */
                        if (tblinfo[i].numParents != 1)
-                               fatal("invalid number of parents %d for table \"%s\"",
-                                         tblinfo[i].numParents,
-                                         tblinfo[i].dobj.name);
+                               pg_fatal("invalid number of parents %d for table \"%s\"",
+                                                tblinfo[i].numParents,
+                                                tblinfo[i].dobj.name);
 
                        attachinfo = (TableAttachInfo *) palloc(sizeof(TableAttachInfo));
                        attachinfo->dobj.objType = DO_TABLE_ATTACH;
@@ -1001,13 +1001,10 @@ findParentsByOid(TableInfo *self,
 
                                parent = findTableByOid(inhinfo[i].inhparent);
                                if (parent == NULL)
-                               {
-                                       pg_log_error("failed sanity check, parent OID %u of table \"%s\" (OID %u) not found",
-                                                                inhinfo[i].inhparent,
-                                                                self->dobj.name,
-                                                                oid);
-                                       exit_nicely(1);
-                               }
+                                       pg_fatal("failed sanity check, parent OID %u of table \"%s\" (OID %u) not found",
+                                                        inhinfo[i].inhparent,
+                                                        self->dobj.name,
+                                                        oid);
                                self->parents[j++] = parent;
                        }
                }
@@ -1043,10 +1040,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
                        if (j > 0)
                        {
                                if (argNum >= arraysize)
-                               {
-                                       pg_log_error("could not parse numeric array \"%s\": too many numbers", str);
-                                       exit_nicely(1);
-                               }
+                                       pg_fatal("could not parse numeric array \"%s\": too many numbers", str);
                                temp[j] = '\0';
                                array[argNum++] = atooid(temp);
                                j = 0;
@@ -1058,10 +1052,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
                {
                        if (!(isdigit((unsigned char) s) || s == '-') ||
                                j >= sizeof(temp) - 1)
-                       {
-                               pg_log_error("could not parse numeric array \"%s\": invalid character in number", str);
-                               exit_nicely(1);
-                       }
+                               pg_fatal("could not parse numeric array \"%s\": invalid character in number", str);
                        temp[j++] = s;
                }
        }
index 9077fdb74dbc4c42033c30accadd57187157759e..62f940ff7aff00889b30b7abc466aa83e5bf4afd 100644 (file)
@@ -108,7 +108,7 @@ ParseCompressionOption(int compression, CompressionAlgorithm *alg, int *level)
                *alg = COMPR_ALG_NONE;
        else
        {
-               fatal("invalid compression code: %d", compression);
+               pg_fatal("invalid compression code: %d", compression);
                *alg = COMPR_ALG_NONE;  /* keep compiler quiet */
        }
 
@@ -131,7 +131,7 @@ AllocateCompressor(int compression, WriteFunc writeF)
 
 #ifndef HAVE_LIBZ
        if (alg == COMPR_ALG_LIBZ)
-               fatal("not built with zlib support");
+               pg_fatal("not built with zlib support");
 #endif
 
        cs = (CompressorState *) pg_malloc0(sizeof(CompressorState));
@@ -167,7 +167,7 @@ ReadDataFromArchive(ArchiveHandle *AH, int compression, ReadFunc readF)
 #ifdef HAVE_LIBZ
                ReadDataFromArchiveZlib(AH, readF);
 #else
-               fatal("not built with zlib support");
+               pg_fatal("not built with zlib support");
 #endif
        }
 }
@@ -185,7 +185,7 @@ WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
 #ifdef HAVE_LIBZ
                        WriteDataToArchiveZlib(AH, cs, data, dLen);
 #else
-                       fatal("not built with zlib support");
+                       pg_fatal("not built with zlib support");
 #endif
                        break;
                case COMPR_ALG_NONE:
@@ -233,8 +233,8 @@ InitCompressorZlib(CompressorState *cs, int level)
        cs->zlibOutSize = ZLIB_OUT_SIZE;
 
        if (deflateInit(zp, level) != Z_OK)
-               fatal("could not initialize compression library: %s",
-                         zp->msg);
+               pg_fatal("could not initialize compression library: %s",
+                                zp->msg);
 
        /* Just be paranoid - maybe End is called after Start, with no Write */
        zp->next_out = (void *) cs->zlibOut;
@@ -253,7 +253,7 @@ EndCompressorZlib(ArchiveHandle *AH, CompressorState *cs)
        DeflateCompressorZlib(AH, cs, true);
 
        if (deflateEnd(zp) != Z_OK)
-               fatal("could not close compression stream: %s", zp->msg);
+               pg_fatal("could not close compression stream: %s", zp->msg);
 
        free(cs->zlibOut);
        free(cs->zp);
@@ -270,7 +270,7 @@ DeflateCompressorZlib(ArchiveHandle *AH, CompressorState *cs, bool flush)
        {
                res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH);
                if (res == Z_STREAM_ERROR)
-                       fatal("could not compress data: %s", zp->msg);
+                       pg_fatal("could not compress data: %s", zp->msg);
                if ((flush && (zp->avail_out < cs->zlibOutSize))
                        || (zp->avail_out == 0)
                        || (zp->avail_in != 0)
@@ -330,8 +330,8 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
        out = pg_malloc(ZLIB_OUT_SIZE + 1);
 
        if (inflateInit(zp) != Z_OK)
-               fatal("could not initialize compression library: %s",
-                         zp->msg);
+               pg_fatal("could not initialize compression library: %s",
+                                zp->msg);
 
        /* no minimal chunk size for zlib */
        while ((cnt = readF(AH, &buf, &buflen)))
@@ -346,7 +346,7 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
 
                        res = inflate(zp, 0);
                        if (res != Z_OK && res != Z_STREAM_END)
-                               fatal("could not uncompress data: %s", zp->msg);
+                               pg_fatal("could not uncompress data: %s", zp->msg);
 
                        out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
                        ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
@@ -361,14 +361,14 @@ ReadDataFromArchiveZlib(ArchiveHandle *AH, ReadFunc readF)
                zp->avail_out = ZLIB_OUT_SIZE;
                res = inflate(zp, 0);
                if (res != Z_OK && res != Z_STREAM_END)
-                       fatal("could not uncompress data: %s", zp->msg);
+                       pg_fatal("could not uncompress data: %s", zp->msg);
 
                out[ZLIB_OUT_SIZE - zp->avail_out] = '\0';
                ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH);
        }
 
        if (inflateEnd(zp) != Z_OK)
-               fatal("could not close compression library: %s", zp->msg);
+               pg_fatal("could not close compression library: %s", zp->msg);
 
        free(buf);
        free(out);
@@ -501,7 +501,7 @@ cfopen_write(const char *path, const char *mode, int compression)
                fp = cfopen(fname, mode, compression);
                free_keep_errno(fname);
 #else
-               fatal("not built with zlib support");
+               pg_fatal("not built with zlib support");
                fp = NULL;                              /* keep compiler quiet */
 #endif
        }
@@ -544,7 +544,7 @@ cfopen(const char *path, const char *mode, int compression)
                        fp = NULL;
                }
 #else
-               fatal("not built with zlib support");
+               pg_fatal("not built with zlib support");
 #endif
        }
        else
@@ -581,8 +581,8 @@ cfread(void *ptr, int size, cfp *fp)
                        int                     errnum;
                        const char *errmsg = gzerror(fp->compressedfp, &errnum);
 
-                       fatal("could not read from input file: %s",
-                                 errnum == Z_ERRNO ? strerror(errno) : errmsg);
+                       pg_fatal("could not read from input file: %s",
+                                        errnum == Z_ERRNO ? strerror(errno) : errmsg);
                }
        }
        else
@@ -618,9 +618,9 @@ cfgetc(cfp *fp)
                if (ret == EOF)
                {
                        if (!gzeof(fp->compressedfp))
-                               fatal("could not read from input file: %s", strerror(errno));
+                               pg_fatal("could not read from input file: %s", strerror(errno));
                        else
-                               fatal("could not read from input file: end of file");
+                               pg_fatal("could not read from input file: end of file");
                }
        }
        else
index 6276fd443b171a1637901a52df58dad8e9103746..220d1ec75f16dd749767cd070e35014c587acdfb 100644 (file)
@@ -11,8 +11,7 @@ GETTEXT_FILES    = $(FRONTEND_COMMON_GETTEXT_FILES) \
                    ../../common/exec.c ../../common/fe_memutils.c \
                    ../../common/wait_error.c
 GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) \
-                   fatal simple_prompt \
+                   simple_prompt \
                    ExecuteSqlCommand:3 warn_or_exit_horribly:2
 GETTEXT_FLAGS    = $(FRONTEND_COMMON_GETTEXT_FLAGS) \
-    fatal:1:c-format \
     warn_or_exit_horribly:2:c-format
index bc5251be824a722ae6f24a7d8bdc0b0330575716..c9f6b86bb05f5d8716cf1953c0ed83aaac45e4b7 100644 (file)
@@ -250,10 +250,7 @@ init_parallel_dump_utils(void)
                /* Initialize socket access */
                err = WSAStartup(MAKEWORD(2, 2), &wsaData);
                if (err != 0)
-               {
-                       pg_log_error("%s() failed: error code %d", "WSAStartup", err);
-                       exit_nicely(1);
-               }
+                       pg_fatal("%s() failed: error code %d", "WSAStartup", err);
 
                parallel_init_done = true;
        }
@@ -393,7 +390,7 @@ archive_close_connection(int code, void *arg)
  *
  * Note that we don't expect to come here during normal exit (the workers
  * should be long gone, and the ParallelState too).  We're only here in a
- * fatal() situation, so intervening to cancel active commands is
+ * pg_fatal() situation, so intervening to cancel active commands is
  * appropriate.
  */
 static void
@@ -961,7 +958,7 @@ ParallelBackupStart(ArchiveHandle *AH)
 
                /* Create communication pipes for this worker */
                if (pgpipe(pipeMW) < 0 || pgpipe(pipeWM) < 0)
-                       fatal("could not create communication channels: %m");
+                       pg_fatal("could not create communication channels: %m");
 
                /* leader's ends of the pipes */
                slot->pipeRead = pipeWM[PIPE_READ];
@@ -1018,7 +1015,7 @@ ParallelBackupStart(ArchiveHandle *AH)
                else if (pid < 0)
                {
                        /* fork failed */
-                       fatal("could not create worker process: %m");
+                       pg_fatal("could not create worker process: %m");
                }
 
                /* In Leader after successful fork */
@@ -1148,8 +1145,8 @@ parseWorkerCommand(ArchiveHandle *AH, TocEntry **te, T_Action *act,
                Assert(*te != NULL);
        }
        else
-               fatal("unrecognized command received from leader: \"%s\"",
-                         msg);
+               pg_fatal("unrecognized command received from leader: \"%s\"",
+                                msg);
 }
 
 /*
@@ -1191,8 +1188,8 @@ parseWorkerResponse(ArchiveHandle *AH, TocEntry *te,
                AH->public.n_errors += n_errors;
        }
        else
-               fatal("invalid message received from worker: \"%s\"",
-                         msg);
+               pg_fatal("invalid message received from worker: \"%s\"",
+                                msg);
 
        return status;
 }
@@ -1323,10 +1320,10 @@ lockTableForWorker(ArchiveHandle *AH, TocEntry *te)
        res = PQexec(AH->connection, query->data);
 
        if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
-               fatal("could not obtain lock on relation \"%s\"\n"
-                         "This usually means that someone requested an ACCESS EXCLUSIVE lock "
-                         "on the table after the pg_dump parent process had gotten the "
-                         "initial ACCESS SHARE lock on the table.", qualId);
+               pg_fatal("could not obtain lock on relation \"%s\"\n"
+                                "This usually means that someone requested an ACCESS EXCLUSIVE lock "
+                                "on the table after the pg_dump parent process had gotten the "
+                                "initial ACCESS SHARE lock on the table.", qualId);
 
        PQclear(res);
        destroyPQExpBuffer(query);
@@ -1412,7 +1409,7 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait)
        {
                /* If do_wait is true, we must have detected EOF on some socket */
                if (do_wait)
-                       fatal("a worker process died unexpectedly");
+                       pg_fatal("a worker process died unexpectedly");
                return false;
        }
 
@@ -1429,8 +1426,8 @@ ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait)
                pstate->te[worker] = NULL;
        }
        else
-               fatal("invalid message received from worker: \"%s\"",
-                         msg);
+               pg_fatal("invalid message received from worker: \"%s\"",
+                                msg);
 
        /* Free the string returned from getMessageFromWorker */
        free(msg);
@@ -1534,7 +1531,7 @@ sendMessageToLeader(int pipefd[2], const char *str)
        int                     len = strlen(str) + 1;
 
        if (pipewrite(pipefd[PIPE_WRITE], str, len) != len)
-               fatal("could not write to the communication channel: %m");
+               pg_fatal("could not write to the communication channel: %m");
 }
 
 /*
@@ -1611,7 +1608,7 @@ getMessageFromWorker(ParallelState *pstate, bool do_wait, int *worker)
        }
 
        if (i < 0)
-               fatal("%s() failed: %m", "select");
+               pg_fatal("%s() failed: %m", "select");
 
        for (i = 0; i < pstate->numWorkers; i++)
        {
@@ -1652,7 +1649,7 @@ sendMessageToWorker(ParallelState *pstate, int worker, const char *str)
 
        if (pipewrite(pstate->parallelSlot[worker].pipeWrite, str, len) != len)
        {
-               fatal("could not write to the communication channel: %m");
+               pg_fatal("could not write to the communication channel: %m");
        }
 }
 
index d41a99d6ea7d9b71a6d7816e7ad64f8a17cf74c8..24e42fa5d7d79fcd6e19a1ba5ad9a9ca1d8f4e9c 100644 (file)
@@ -276,7 +276,7 @@ CloseArchive(Archive *AHX)
                res = fclose(AH->OF);
 
        if (res != 0)
-               fatal("could not close output file: %m");
+               pg_fatal("could not close output file: %m");
 }
 
 /* Public */
@@ -330,8 +330,8 @@ ProcessArchiveRestoreOptions(Archive *AHX)
                                        /* ok no matter which section we were in */
                                        break;
                                default:
-                                       fatal("unexpected section code %d",
-                                                 (int) te->section);
+                                       pg_fatal("unexpected section code %d",
+                                                        (int) te->section);
                                        break;
                        }
                }
@@ -367,11 +367,11 @@ RestoreArchive(Archive *AHX)
        {
                /* We haven't got round to making this work for all archive formats */
                if (AH->ClonePtr == NULL || AH->ReopenPtr == NULL)
-                       fatal("parallel restore is not supported with this archive file format");
+                       pg_fatal("parallel restore is not supported with this archive file format");
 
                /* Doesn't work if the archive represents dependencies as OIDs */
                if (AH->version < K_VERS_1_8)
-                       fatal("parallel restore is not supported with archives made by pre-8.0 pg_dump");
+                       pg_fatal("parallel restore is not supported with archives made by pre-8.0 pg_dump");
 
                /*
                 * It's also not gonna work if we can't reopen the input file, so
@@ -389,7 +389,7 @@ RestoreArchive(Archive *AHX)
                for (te = AH->toc->next; te != AH->toc; te = te->next)
                {
                        if (te->hadDumper && (te->reqs & REQ_DATA) != 0)
-                               fatal("cannot restore from compressed archive (compression not supported in this installation)");
+                               pg_fatal("cannot restore from compressed archive (compression not supported in this installation)");
                }
        }
 #endif
@@ -408,7 +408,7 @@ RestoreArchive(Archive *AHX)
        {
                pg_log_info("connecting to database for restore");
                if (AH->version < K_VERS_1_3)
-                       fatal("direct database connections are not supported in pre-1.3 archives");
+                       pg_fatal("direct database connections are not supported in pre-1.3 archives");
 
                /*
                 * We don't want to guess at whether the dump will successfully
@@ -1037,7 +1037,7 @@ WriteData(Archive *AHX, const void *data, size_t dLen)
        ArchiveHandle *AH = (ArchiveHandle *) AHX;
 
        if (!AH->currToc)
-               fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
+               pg_fatal("internal error -- WriteData cannot be called outside the context of a DataDumper routine");
 
        AH->WriteDataPtr(AH, data, dLen);
 }
@@ -1220,7 +1220,7 @@ StartBlob(Archive *AHX, Oid oid)
        ArchiveHandle *AH = (ArchiveHandle *) AHX;
 
        if (!AH->StartBlobPtr)
-               fatal("large-object output not supported in chosen format");
+               pg_fatal("large-object output not supported in chosen format");
 
        AH->StartBlobPtr(AH, AH->currToc, oid);
 
@@ -1311,13 +1311,13 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid, bool drop)
                {
                        loOid = lo_create(AH->connection, oid);
                        if (loOid == 0 || loOid != oid)
-                               fatal("could not create large object %u: %s",
-                                         oid, PQerrorMessage(AH->connection));
+                               pg_fatal("could not create large object %u: %s",
+                                                oid, PQerrorMessage(AH->connection));
                }
                AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
                if (AH->loFd == -1)
-                       fatal("could not open large object %u: %s",
-                                 oid, PQerrorMessage(AH->connection));
+                       pg_fatal("could not open large object %u: %s",
+                                        oid, PQerrorMessage(AH->connection));
        }
        else
        {
@@ -1372,7 +1372,7 @@ SortTocFromFile(Archive *AHX)
        /* Setup the file */
        fh = fopen(ropt->tocFile, PG_BINARY_R);
        if (!fh)
-               fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
+               pg_fatal("could not open TOC file \"%s\": %m", ropt->tocFile);
 
        initStringInfo(&linebuf);
 
@@ -1407,8 +1407,8 @@ SortTocFromFile(Archive *AHX)
                /* Find TOC entry */
                te = getTocEntryByDumpId(AH, id);
                if (!te)
-                       fatal("could not find entry for ID %d",
-                                 id);
+                       pg_fatal("could not find entry for ID %d",
+                                        id);
 
                /* Mark it wanted */
                ropt->idWanted[id - 1] = true;
@@ -1430,7 +1430,7 @@ SortTocFromFile(Archive *AHX)
        pg_free(linebuf.data);
 
        if (fclose(fh) != 0)
-               fatal("could not close TOC file: %m");
+               pg_fatal("could not close TOC file: %m");
 }
 
 /**********************
@@ -1544,9 +1544,9 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
        if (!AH->OF)
        {
                if (filename)
-                       fatal("could not open output file \"%s\": %m", filename);
+                       pg_fatal("could not open output file \"%s\": %m", filename);
                else
-                       fatal("could not open output file: %m");
+                       pg_fatal("could not open output file: %m");
        }
 }
 
@@ -1573,7 +1573,7 @@ RestoreOutput(ArchiveHandle *AH, OutputContext savedContext)
                res = fclose(AH->OF);
 
        if (res != 0)
-               fatal("could not close output file: %m");
+               pg_fatal("could not close output file: %m");
 
        AH->gzOut = savedContext.gzOut;
        AH->OF = savedContext.OF;
@@ -1736,34 +1736,34 @@ warn_or_exit_horribly(ArchiveHandle *AH, const char *fmt,...)
 
                case STAGE_INITIALIZING:
                        if (AH->stage != AH->lastErrorStage)
-                               pg_log_generic(PG_LOG_INFO, "while INITIALIZING:");
+                               pg_log_info("while INITIALIZING:");
                        break;
 
                case STAGE_PROCESSING:
                        if (AH->stage != AH->lastErrorStage)
-                               pg_log_generic(PG_LOG_INFO, "while PROCESSING TOC:");
+                               pg_log_info("while PROCESSING TOC:");
                        break;
 
                case STAGE_FINALIZING:
                        if (AH->stage != AH->lastErrorStage)
-                               pg_log_generic(PG_LOG_INFO, "while FINALIZING:");
+                               pg_log_info("while FINALIZING:");
                        break;
        }
        if (AH->currentTE != NULL && AH->currentTE != AH->lastErrorTE)
        {
-               pg_log_generic(PG_LOG_INFO, "from TOC entry %d; %u %u %s %s %s",
-                                          AH->currentTE->dumpId,
-                                          AH->currentTE->catalogId.tableoid,
-                                          AH->currentTE->catalogId.oid,
-                                          AH->currentTE->desc ? AH->currentTE->desc : "(no desc)",
-                                          AH->currentTE->tag ? AH->currentTE->tag : "(no tag)",
-                                          AH->currentTE->owner ? AH->currentTE->owner : "(no owner)");
+               pg_log_info("from TOC entry %d; %u %u %s %s %s",
+                                       AH->currentTE->dumpId,
+                                       AH->currentTE->catalogId.tableoid,
+                                       AH->currentTE->catalogId.oid,
+                                       AH->currentTE->desc ? AH->currentTE->desc : "(no desc)",
+                                       AH->currentTE->tag ? AH->currentTE->tag : "(no tag)",
+                                       AH->currentTE->owner ? AH->currentTE->owner : "(no owner)");
        }
        AH->lastErrorStage = AH->stage;
        AH->lastErrorTE = AH->currentTE;
 
        va_start(ap, fmt);
-       pg_log_generic_v(PG_LOG_ERROR, fmt, ap);
+       pg_log_generic_v(PG_LOG_ERROR, PG_LOG_PRIMARY, fmt, ap);
        va_end(ap);
 
        if (AH->public.exit_on_error)
@@ -1827,7 +1827,7 @@ buildTocEntryArrays(ArchiveHandle *AH)
        {
                /* this check is purely paranoia, maxDumpId should be correct */
                if (te->dumpId <= 0 || te->dumpId > maxDumpId)
-                       fatal("bad dumpId");
+                       pg_fatal("bad dumpId");
 
                /* tocsByDumpId indexes all TOCs by their dump ID */
                AH->tocsByDumpId[te->dumpId] = te;
@@ -1848,7 +1848,7 @@ buildTocEntryArrays(ArchiveHandle *AH)
                         * item's dump ID, so there should be a place for it in the array.
                         */
                        if (tableId <= 0 || tableId > maxDumpId)
-                               fatal("bad table dumpId for TABLE DATA item");
+                               pg_fatal("bad table dumpId for TABLE DATA item");
 
                        AH->tableDataId[tableId] = te->dumpId;
                }
@@ -1940,7 +1940,7 @@ ReadOffset(ArchiveHandle *AH, pgoff_t * o)
                        break;
 
                default:
-                       fatal("unexpected data offset flag %d", offsetFlg);
+                       pg_fatal("unexpected data offset flag %d", offsetFlg);
        }
 
        /*
@@ -1953,7 +1953,7 @@ ReadOffset(ArchiveHandle *AH, pgoff_t * o)
                else
                {
                        if (AH->ReadBytePtr(AH) != 0)
-                               fatal("file offset in dump file is too large");
+                               pg_fatal("file offset in dump file is too large");
                }
        }
 
@@ -2091,8 +2091,8 @@ _discoverArchiveFormat(ArchiveHandle *AH)
                        char            buf[MAXPGPATH];
 
                        if (snprintf(buf, MAXPGPATH, "%s/toc.dat", AH->fSpec) >= MAXPGPATH)
-                               fatal("directory name too long: \"%s\"",
-                                         AH->fSpec);
+                               pg_fatal("directory name too long: \"%s\"",
+                                                AH->fSpec);
                        if (stat(buf, &st) == 0 && S_ISREG(st.st_mode))
                        {
                                AH->format = archDirectory;
@@ -2101,39 +2101,39 @@ _discoverArchiveFormat(ArchiveHandle *AH)
 
 #ifdef HAVE_LIBZ
                        if (snprintf(buf, MAXPGPATH, "%s/toc.dat.gz", AH->fSpec) >= MAXPGPATH)
-                               fatal("directory name too long: \"%s\"",
-                                         AH->fSpec);
+                               pg_fatal("directory n