</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><envar>TZ</envar></term>
(see <xref linkend="libpq-envars"/>).
</para>
+ <para>
+ The environment variable <envar>PG_COLOR</envar> specifies whether to use
+ color in diagnostics messages. Possible values are
+ <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
</refsect1>
<refsect1>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
</refentry>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
also uses the environment variables supported by <application>libpq</application>
(see <xref linkend="libpq-envars"/>).
</para>
+
+ <para>
+ The environment variable <envar>PG_COLOR</envar> specifies whether to use
+ color in diagnostics messages. Possible values are
+ <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
</refsect1>
<refsect1 id="app-pg-isready-notes">
(see <xref linkend="libpq-envars"/>).
</para>
+ <para>
+ The environment variable <envar>PG_COLOR</envar> specifies whether to use
+ color in diagnostics messages. Possible values are
+ <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
</refsect1>
<refsect1>
uses the environment variables supported by <application>libpq</application>
(see <xref linkend="libpq-envars"/>).
</para>
+
+ <para>
+ The environment variable <envar>PG_COLOR</envar> specifies whether to use
+ color in diagnostics messages. Possible values are
+ <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
</refsect1>
<refsect1>
</variablelist>
</refsect1>
+ <refsect1>
+ <title>Environment</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
<refsect1>
<title>Notes</title>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
<application>pg_rewind</application> also uses the environment variables
supported by <application>libpq</application> (see <xref linkend="libpq-envars"/>).
</para>
+
+ <para>
+ The environment variable <envar>PG_COLOR</envar> specifies whether to use
+ color in diagnostics messages. Possible values are
+ <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
</refsect1>
<refsect1>
</para>
</refsect1>
+ <refsect1>
+ <title>Environment</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><envar>PGDATA</envar></term>
+ <listitem>
+ <para>
+ Data directory; see also the <option>-p</option> option.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
<refsect1>
<title>Notes</title>
<para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><envar>PSQL_EDITOR</envar></term>
<term><envar>EDITOR</envar></term>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term><envar>PG_COLOR</envar></term>
+ <listitem>
+ <para>
+ Specifies whether to use color in diagnostics messages. Possible values
+ are <literal>always</literal>, <literal>auto</literal>,
+ <literal>never</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
<para>
void
UpdateControlFile(void)
{
- update_controlfile(DataDir, NULL, ControlFile, true);
+ update_controlfile(DataDir, ControlFile, true);
}
/*
tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */
- ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
+ ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok)
ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file")));
tupdesc = BlessTupleDesc(tupdesc);
/* Read the control file. */
- ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
+ ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok)
ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file")));
tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */
- ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
+ ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok)
ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file")));
tupdesc = BlessTupleDesc(tupdesc);
/* read the control file */
- ControlFile = get_controlfile(DataDir, NULL, &crc_ok);
+ ControlFile = get_controlfile(DataDir, &crc_ok);
if (!crc_ok)
ereport(ERROR,
(errmsg("calculated CRC checksum does not match value stored in file")));
#include "common/file_utils.h"
#include "common/restricted_token.h"
#include "common/username.h"
+#include "fe_utils/logging.h"
#include "fe_utils/string_utils.h"
#include "getaddrinfo.h"
#include "getopt_long.h"
"# allows any local user to connect as any PostgreSQL user, including\n" \
"# the database superuser. If you do not trust all your local users,\n" \
"# use another authentication method.\n"
-static char *authwarning = NULL;
+static bool authwarning = false;
/*
* Centralized knowledge of switches to pass to backend
if (!result)
{
- fprintf(stderr, _("%s: out of memory\n"), progname);
+ pg_log_error("out of memory");
exit(1);
}
return result;
if ((infile = fopen(path, "r")) == NULL)
{
- fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not open file \"%s\" for reading: %m", path);
exit(1);
}
if ((out_file = fopen(path, "w")) == NULL)
{
- fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not open file \"%s\" for writing: %m", path);
exit(1);
}
for (line = lines; *line != NULL; line++)
{
if (fputs(*line, out_file) < 0)
{
- fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not write file \"%s\": %m", path);
exit(1);
}
free(*line);
}
if (fclose(out_file))
{
- fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not write file \"%s\": %m", path);
exit(1);
}
}
errno = 0;
cmdfd = popen(command, mode);
if (cmdfd == NULL)
- fprintf(stderr, _("%s: could not execute command \"%s\": %s\n"),
- progname, command, strerror(errno));
+ pg_log_error("could not execute command \"%s\": %m", command);
return cmdfd;
}
{
if (made_new_pgdata)
{
- fprintf(stderr, _("%s: removing data directory \"%s\"\n"),
- progname, pg_data);
+ pg_log_info("removing data directory \"%s\"", pg_data);
if (!rmtree(pg_data, true))
- fprintf(stderr, _("%s: failed to remove data directory\n"),
- progname);
+ pg_log_error("failed to remove data directory");
}
else if (found_existing_pgdata)
{
- fprintf(stderr,
- _("%s: removing contents of data directory \"%s\"\n"),
- progname, pg_data);
+ pg_log_info("removing contents of data directory \"%s\"",
+ pg_data);
if (!rmtree(pg_data, false))
- fprintf(stderr, _("%s: failed to remove contents of data directory\n"),
- progname);
+ pg_log_error("failed to remove contents of data directory");
}
if (made_new_xlogdir)
{
- fprintf(stderr, _("%s: removing WAL directory \"%s\"\n"),
- progname, xlog_dir);
+ pg_log_info("removing WAL directory \"%s\"", xlog_dir);
if (!rmtree(xlog_dir, true))
- fprintf(stderr, _("%s: failed to remove WAL directory\n"),
- progname);
+ pg_log_error("failed to remove WAL directory");
}
else if (found_existing_xlogdir)
{
- fprintf(stderr,
- _("%s: removing contents of WAL directory \"%s\"\n"),
- progname, xlog_dir);
+ pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
if (!rmtree(xlog_dir, false))
- fprintf(stderr, _("%s: failed to remove contents of WAL directory\n"),
- progname);
+ pg_log_error("failed to remove contents of WAL directory");
}
/* otherwise died during startup, do nothing! */
}
else
{
if (made_new_pgdata || found_existing_pgdata)
- fprintf(stderr,
- _("%s: data directory \"%s\" not removed at user's request\n"),
- progname, pg_data);
+ pg_log_info("data directory \"%s\" not removed at user's request",
+ pg_data);
if (made_new_xlogdir || found_existing_xlogdir)
- fprintf(stderr,
- _("%s: WAL directory \"%s\" not removed at user's request\n"),
- progname, xlog_dir);
+ pg_log_info("WAL directory \"%s\" not removed at user's request",
+ xlog_dir);
}
}
#ifndef WIN32
if (geteuid() == 0) /* 0 is root's uid */
{
+ pg_log_error("cannot be run as root");
fprintf(stderr,
- _("%s: cannot be run as root\n"
- "Please log in (using, e.g., \"su\") as the "
- "(unprivileged) user that will\n"
- "own the server process.\n"),
- progname);
+ _("Please log in (using, e.g., \"su\") as the (unprivileged) user that will\n"
+ "own the server process.\n"));
exit(1);
}
#endif
if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
return enc;
}
- fprintf(stderr, _("%s: \"%s\" is not a valid server encoding name\n"),
- progname, encoding_name ? encoding_name : "(null)");
+ pg_log_error("\"%s\" is not a valid server encoding name",
+ encoding_name ? encoding_name : "(null)");
exit(1);
}
{
if (errno == ENOENT)
{
- fprintf(stderr,
- _("%s: file \"%s\" does not exist\n"), progname, path);
+ 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"));
}
else
{
- fprintf(stderr,
- _("%s: could not access file \"%s\": %s\n"), progname, path,
- strerror(errno));
+ 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"));
}
if (!S_ISREG(statbuf.st_mode))
{
- fprintf(stderr,
- _("%s: file \"%s\" is not a regular file\n"), progname, path);
+ 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"));
if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
{
- fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not open file \"%s\" for writing: %m", path);
exit(1);
}
if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
fclose(version_file))
{
- fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not write file \"%s\": %m", path);
exit(1);
}
free(path);
conf_file = fopen(path, PG_BINARY_W);
if (conf_file == NULL)
{
- fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not open file \"%s\" for writing: %m", path);
exit(1);
}
if (fclose(conf_file))
{
- fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not write file \"%s\": %m", path);
exit(1);
}
free(path);
writefile(path, conflines);
if (chmod(path, pg_file_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not change permissions of \"%s\": %m", path);
exit(1);
}
writefile(path, autoconflines);
if (chmod(path, pg_file_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not change permissions of \"%s\": %m", path);
exit(1);
}
writefile(path, conflines);
if (chmod(path, pg_file_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not change permissions of \"%s\": %m", path);
exit(1);
}
writefile(path, conflines);
if (chmod(path, pg_file_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not change permissions of \"%s\": %m", path);
exit(1);
}
if (strcmp(headerline, *bki_lines) != 0)
{
+ pg_log_error("input file \"%s\" does not belong to PostgreSQL %s",
+ bki_file, PG_VERSION);
fprintf(stderr,
- _("%s: input file \"%s\" does not belong to PostgreSQL %s\n"
- "Check your installation or specify the correct path "
- "using the option -L.\n"),
- progname, bki_file, PG_VERSION);
+ _("Check your installation or specify the correct path "
+ "using the option -L.\n"));
exit(1);
}
if (!pwf)
{
- fprintf(stderr, _("%s: could not open file \"%s\" for reading: %s\n"),
- progname, pwfilename, strerror(errno));
+ pg_log_error("could not open file \"%s\" for reading: %m",
+ pwfilename);
exit(1);
}
if (!fgets(pwd1, sizeof(pwd1), pwf))
{
if (ferror(pwf))
- fprintf(stderr, _("%s: could not read password from file \"%s\": %s\n"),
- progname, pwfilename, strerror(errno));
+ pg_log_error("could not read password from file \"%s\": %m",
+ pwfilename);
else
- fprintf(stderr, _("%s: password file \"%s\" is empty\n"),
- progname, pwfilename);
+ pg_log_error("password file \"%s\" is empty",
+ pwfilename);
exit(1);
}
fclose(pwf);
save = setlocale(category, NULL);
if (!save)
{
- fprintf(stderr, _("%s: setlocale() failed\n"),
- progname);
+ pg_log_error("setlocale() failed");
exit(1);
}
/* restore old value. */
if (!setlocale(category, save))
{
- fprintf(stderr, _("%s: failed to restore old locale \"%s\"\n"),
- progname, save);
+ pg_log_error("failed to restore old locale \"%s\"", save);
exit(1);
}
free(save);
if (res == NULL)
{
if (*locale)
- fprintf(stderr, _("%s: invalid locale name \"%s\"\n"),
- progname, locale);
+ pg_log_error("invalid locale name \"%s\"", locale);
else
{
/*
* setlocale's behavior is implementation-specific, it's hard to
* be sure what it didn't like. Print a safe generic message.
*/
- fprintf(stderr, _("%s: invalid locale settings; check LANG and LC_* environment variables\n"),
- progname);
+ pg_log_error("invalid locale settings; check LANG and LC_* environment variables");
}
exit(1);
}
#endif
user_enc == PG_SQL_ASCII))
{
- fprintf(stderr, _("%s: encoding mismatch\n"), progname);
+ 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"
{
if (*authmethod == NULL)
{
- authwarning = _("\nWARNING: enabling \"trust\" authentication for local connections\n"
- "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");
+ authwarning = true;
*authmethod = "trust";
}
}
return;
}
- fprintf(stderr, _("%s: invalid authentication method \"%s\" for \"%s\" connections\n"),
- progname, authmethod, conntype);
+ pg_log_error("invalid authentication method \"%s\" for \"%s\" connections",
+ authmethod, conntype);
exit(1);
}
strcmp(authmethodhost, "scram-sha-256") == 0) &&
!(pwprompt || pwfilename))
{
- fprintf(stderr, _("%s: must specify a password for the superuser to enable %s authentication\n"), progname,
+ pg_log_error("must specify a password for the superuser to enable %s authentication",
(strcmp(authmethodlocal, "md5") == 0 ||
strcmp(authmethodlocal, "password") == 0 ||
strcmp(authmethodlocal, "scram-sha-256") == 0)
}
else
{
+ pg_log_error("no data directory specified");
fprintf(stderr,
- _("%s: no data directory specified\n"
- "You must identify the directory where the data for this database system\n"
+ _("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"),
- progname);
+ "environment variable PGDATA.\n"));
exit(1);
}
}
strlcpy(full_path, progname, sizeof(full_path));
if (ret == -1)
- fprintf(stderr,
- _("The program \"postgres\" is needed by %s "
- "but was not found in the\n"
- "same directory as \"%s\".\n"
- "Check your installation.\n"),
- progname, full_path);
+ pg_log_error("The program \"postgres\" is needed by %s but was not found in the\n"
+ "same directory as \"%s\".\n"
+ "Check your installation.",
+ full_path, progname);
else
- fprintf(stderr,
- _("The program \"postgres\" was found by \"%s\"\n"
- "but was not the same version as %s.\n"
- "Check your installation.\n"),
- full_path, progname);
+ pg_log_error("The program \"postgres\" was found by \"%s\"\n"
+ "but was not the same version as %s.\n"
+ "Check your installation.",
+ full_path, progname);
exit(1);
}
}
else if (!is_absolute_path(share_path))
{
- fprintf(stderr, _("%s: input file location must be an absolute path\n"), progname);
+ pg_log_error("input file location must be an absolute path");
exit(1);
}
if (ctype_enc == -1)
{
/* Couldn't recognize the locale's codeset */
- fprintf(stderr, _("%s: could not find suitable encoding for locale \"%s\"\n"),
- progname, lc_ctype);
+ 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_encoding_to_char(ctype_enc),
pg_encoding_to_char(encodingid));
#else
- fprintf(stderr,
- _("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
- progname, lc_ctype, pg_encoding_to_char(ctype_enc));
+ 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"),
if (pg_mkdir_p(pg_data, pg_dir_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
- progname, pg_data, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m", pg_data);
exit(1);
}
else
if (chmod(pg_data, pg_dir_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
- progname, pg_data, strerror(errno));
+ pg_log_error("could not change permissions of directory \"%s\": %m",
+ pg_data);
exit(1);
}
else
case 3:
case 4:
/* Present and not empty */
- fprintf(stderr,
- _("%s: directory \"%s\" exists but is not empty\n"),
- progname, pg_data);
+ pg_log_error("directory \"%s\" exists but is not empty", pg_data);
if (ret != 4)
warn_on_mount_point(ret);
else
default:
/* Trouble accessing directory */
- fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
- progname, pg_data, strerror(errno));
+ pg_log_error("could not access directory \"%s\": %m", pg_data);
exit(1);
}
}
canonicalize_path(xlog_dir);
if (!is_absolute_path(xlog_dir))
{
- fprintf(stderr, _("%s: WAL directory location must be an absolute path\n"), progname);
+ pg_log_error("WAL directory location must be an absolute path");
exit(1);
}
if (pg_mkdir_p(xlog_dir, pg_dir_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
- progname, xlog_dir, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m",
+ xlog_dir);
exit(1);
}
else
if (chmod(xlog_dir, pg_dir_create_mode) != 0)
{
- fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
- progname, xlog_dir, strerror(errno));
+ pg_log_error("could not change permissions of directory \"%s\": %m",
+ xlog_dir);
exit(1);
}
else
case 3:
case 4:
/* Present and not empty */
- fprintf(stderr,
- _("%s: directory \"%s\" exists but is not empty\n"),
- progname, xlog_dir);
+ pg_log_error("directory \"%s\" exists but is not empty", xlog_dir);
if (ret != 4)
warn_on_mount_point(ret);
else
default:
/* Trouble accessing directory */
- fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
- progname, xlog_dir, strerror(errno));
+ pg_log_error("could not access directory \"%s\": %m", xlog_dir);
exit(1);
}
#ifdef HAVE_SYMLINK
if (symlink(xlog_dir, subdirloc) != 0)
{
- fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
- progname, subdirloc, strerror(errno));
+ pg_log_error("could not create symbolic link \"%s\": %m",
+ subdirloc);
exit(1);
}
#else
- fprintf(stderr, _("%s: symlinks are not supported on this platform\n"), progname);
+ pg_log_error("symlinks are not supported on this platform");
exit(1);
#endif
}
/* Without -X option, just make the subdirectory normally */
if (mkdir(subdirloc, pg_dir_create_mode) < 0)
{
- fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
- progname, subdirloc, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m",
+ subdirloc);
exit(1);
}
}
*/
if (mkdir(path, pg_dir_create_mode) < 0)
{
- fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
- progname, path, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m", path);
exit(1);
}
char pg_ctl_path[MAXPGPATH];
/*
- * Ensure that buffering behavior of stdout and stderr matches what it is
+ * Ensure that buffering behavior of stdout matches what it is
* in interactive usage (at least on most platforms). This prevents
* unexpected output ordering when, eg, output is redirected to a file.
* POSIX says we must do this before any other usage of these files.
*/
setvbuf(stdout, NULL, PG_IOLBF, 0);
- setvbuf(stderr, NULL, _IONBF, 0);
+ pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("initdb"));
if (optind < argc)
{
- fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
- progname, argv[optind]);
+ pg_log_error("too many command-line arguments (first is \"%s\")",
+ argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
/* must check that directory is readable */
if (pg_check_dir(pg_data) <= 0)
{
- fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
- progname, pg_data, strerror(errno));
+ pg_log_error("could not access directory \"%s\": %m", pg_data);
exit(1);
}
fputs(_("syncing data to disk ... "), stdout);
fflush(stdout);
- fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
+ fsync_pgdata(pg_data, PG_VERSION_NUM);
check_ok();
return 0;
}
if (pwprompt && pwfilename)
{
- fprintf(stderr, _("%s: password prompt and password file cannot be specified together\n"), progname);
+ pg_log_error("password prompt and password file cannot be specified together");
exit(1);
}
/* verify that wal segment size is valid */
if (endptr == str_wal_segment_size_mb || *endptr != '\0')
{
- fprintf(stderr,
- _("%s: argument of --wal-segsize must be a number\n"),
- progname);
+ pg_log_error("argument of --wal-segsize must be a number");
exit(1);
}
if (!IsValidWalSegSize(wal_segment_size_mb * 1024 * 1024))
{
- fprintf(stderr,
- _("%s: argument of --wal-segsize must be a power of 2 between 1 and 1024\n"),
- progname);
+ pg_log_error("argument of --wal-segsize must be a power of 2 between 1 and 1024");
exit(1);
}
}
- get_restricted_token(progname);
+ get_restricted_token();
setup_pgdata();
if (strncmp(username, "pg_", 3) == 0)
{
- fprintf(stderr, _("%s: superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"\n"), progname, username);
+ pg_log_error("superuser name \"%s\" is disallowed; role names cannot begin with \"pg_\"", username);
exit(1);
}
{
fputs(_("syncing data to disk ... "), stdout);
fflush(stdout);
- fsync_pgdata(pg_data, progname, PG_VERSION_NUM);
+ fsync_pgdata(pg_data, PG_VERSION_NUM);
check_ok();
}
else
printf(_("\nSync to disk skipped.\nThe data directory might become corrupt if the operating system crashes.\n"));
- if (authwarning != NULL)
- fprintf(stderr, "%s", authwarning);
+ if (authwarning)
+ {
+ 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"));
+ }
/*
* Build up a shell command to tell the user how to start the server
# src/bin/initdb/nls.mk
CATALOG_NAME = initdb
AVAIL_LANGUAGES = cs de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN
-GETTEXT_FILES = findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/file_utils.c ../../common/pgfnames.c ../../common/restricted_token.c ../../common/rmtree.c ../../common/username.c ../../common/wait_error.c ../../port/dirmod.c
-GETTEXT_TRIGGERS = simple_prompt
+GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) findtimezone.c initdb.c ../../common/exec.c ../../common/fe_memutils.c ../../common/file_utils.c ../../common/pgfnames.c ../../common/restricted_token.c ../../common/rmtree.c ../../common/username.c ../../common/wait_error.c ../../port/dirmod.c
+GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) simple_prompt
+GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
+LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils
+
OBJS = pg_archivecleanup.o $(WIN32RES)
all: pg_archivecleanup
-pg_archivecleanup: $(OBJS) | submake-libpgport
+pg_archivecleanup: $(OBJS) | submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs
# src/bin/pg_archivecleanup/nls.mk
CATALOG_NAME = pg_archivecleanup
AVAIL_LANGUAGES =de es fr ja ko pl ru sv tr vi
-GETTEXT_FILES = pg_archivecleanup.c
+GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) pg_archivecleanup.c
+GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS)
+GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
#include "pg_getopt.h"
+#include "fe_utils/logging.h"
+
#include "access/xlog_internal.h"
const char *progname;
/* Options and defaults */
-bool debug = false; /* are we debugging? */
bool dryrun = false; /* are we performing a dry-run operation? */
char *additional_ext = NULL; /* Extension to remove from filenames */
char *archiveLocation; /* where to find the archive? */
char *restartWALFileName; /* the file from which we can restart restore */
-char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */
char exclusiveCleanupFileName[MAXFNAMELEN]; /* the oldest file we want
* to remain in archive */
if (stat(archiveLocation, &stat_buf) != 0 ||
!S_ISDIR(stat_buf.st_mode))
{
- fprintf(stderr, _("%s: archive location \"%s\" does not exist\n"),
- progname, archiveLocation);
+ pg_log_error("archive location \"%s\" does not exist",
+ archiveLocation);
exit(2);
}
}
if ((IsXLogFileName(walfile) || IsPartialXLogFileName(walfile)) &&
strcmp(walfile + 8, exclusiveCleanupFileName + 8) < 0)
{
+ char WALFilePath[MAXPGPATH * 2]; /* the file path including archive */
+
/*
* Use the original file name again now, including any
* extension that might have been chopped off before testing
* user can pipe the output into some other program.
*/
printf("%s\n", WALFilePath);
- if (debug)
- fprintf(stderr,
- _("%s: file \"%s\" would be removed\n"),
- progname, WALFilePath);
+ pg_log_debug("file \"%s\" would be removed", WALFilePath);
continue;
}
- if (debug)
- fprintf(stderr, _("%s: removing file \"%s\"\n"),
- progname, WALFilePath);
+ pg_log_debug("removing file \"%s\"", WALFilePath);
rc = unlink(WALFilePath);
if (rc != 0)
{
- fprintf(stderr, _("%s: ERROR: could not remove file \"%s\": %s\n"),
- progname, WALFilePath, strerror(errno));
+ pg_log_error("could not remove file \"%s\": %m",
+ WALFilePath);
break;
}
}
}
if (errno)
- fprintf(stderr, _("%s: could not read archive location \"%s\": %s\n"),
- progname, archiveLocation, strerror(errno));
+ pg_log_error("could not read archive location \"%s\": %m",
+ archiveLocation);
if (closedir(xldir))
- fprintf(stderr, _("%s: could not close archive location \"%s\": %s\n"),
- progname, archiveLocation, strerror(errno));
+ pg_log_error("could not close archive location \"%s\": %m",
+ archiveLocation);
}
else
- fprintf(stderr, _("%s: could not open archive location \"%s\": %s\n"),
- progname, archiveLocation, strerror(errno));
+ pg_log_error("could not open archive location \"%s\": %m",
+ archiveLocation);
}
/*
if (!fnameOK)
{
- fprintf(stderr, _("%s: invalid file name argument\n"), progname);
+ pg_log_error("invalid file name argument");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2);
}
{
int c;
+ pg_logging_init(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_archivecleanup"));
progname = get_progname(argv[0]);
switch (c)
{
case 'd': /* Debug mode */
- debug = true;
+ pg_logging_set_level(PG_LOG_DEBUG);
break;
case 'n': /* Dry-Run mode */
dryrun = true;
}
else
{
- fprintf(stderr, _("%s: must specify archive location\n"), progname);
+ pg_log_error("must specify archive location");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2);
}
}
else
{
- fprintf(stderr, _("%s: must specify oldest kept WAL file\n"), progname);
+ pg_log_error("must specify oldest kept WAL file");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2);
}
if (optind < argc)
{
- fprintf(stderr, _("%s: too many command-line arguments\n"), progname);
+ pg_log_error("too many command-line arguments");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(2);
}
*/
SetWALFileNameForCleanup();
- if (debug)
- {
- snprintf(WALFilePath, MAXPGPATH, "%s/%s",
+ pg_log_debug("keeping WAL file \"%s/%s\" and later",
archiveLocation, exclusiveCleanupFileName);
- fprintf(stderr, _("%s: keeping WAL file \"%s\" and later\n"),
- progname, WALFilePath);
- }
/*
* Remove WAL files older than cut-off
# src/bin/pg_basebackup/nls.mk
CATALOG_NAME = pg_basebackup
AVAIL_LANGUAGES = de es fr he it ja ko pl pt_BR ru sv tr vi zh_CN
-GETTEXT_FILES = pg_basebackup.c pg_receivewal.c pg_recvlogical.c receivelog.c streamutil.c walmethods.c ../../common/fe_memutils.c ../../common/file_utils.c
-GETTEXT_TRIGGERS = simple_prompt tar_set_error
+GETTEXT_FILES = $(FRONTEND_COMMON_GETTEXT_FILES) pg_basebackup.c pg_receivewal.c pg_recvlogical.c receivelog.c streamutil.c walmethods.c ../../common/fe_memutils.c ../../common/file_utils.c
+GETTEXT_TRIGGERS = $(FRONTEND_COMMON_GETTEXT_TRIGGERS) simple_prompt tar_set_error
+GETTEXT_FLAGS = $(FRONTEND_COMMON_GETTEXT_FLAGS)
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/string.h"
+#include "fe_utils/logging.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
#include "libpq-fe.h"
{
if (made_new_pgdata)
{
- fprintf(stderr, _("%s: removing data directory \"%s\"\n"),
- progname, basedir);
+ pg_log_info("removing data directory \"%s\"", basedir);
if (!rmtree(basedir, true))
- fprintf(stderr, _("%s: failed to remove data directory\n"),
- progname);
+ pg_log_error("failed to remove data directory");
}
else if (found_existing_pgdata)
{
- fprintf(stderr,
- _("%s: removing contents of data directory \"%s\"\n"),
- progname, basedir);
+ pg_log_info("removing contents of data directory \"%s\"", basedir);
if (!rmtree(basedir, false))
- fprintf(stderr, _("%s: failed to remove contents of data directory\n"),
- progname);
+ pg_log_error("failed to remove contents of data directory");
}
if (made_new_xlogdir)
{
- fprintf(stderr, _("%s: removing WAL directory \"%s\"\n"),
- progname, xlog_dir);
+ pg_log_info("removing WAL directory \"%s\"", xlog_dir);
if (!rmtree(xlog_dir, true))
- fprintf(stderr, _("%s: failed to remove WAL directory\n"),
- progname);
+ pg_log_error("failed to remove WAL directory");
}
else if (found_existing_xlogdir)
{
- fprintf(stderr,
- _("%s: removing contents of WAL directory \"%s\"\n"),
- progname, xlog_dir);
+ pg_log_info("removing contents of WAL directory \"%s\"", xlog_dir);
if (!rmtree(xlog_dir, false))
- fprintf(stderr, _("%s: failed to remove contents of WAL directory\n"),
- progname);
+ pg_log_error("failed to remove contents of WAL directory");
}
}
else
{
if ((made_new_pgdata || found_existing_pgdata) && !checksum_failure)
- fprintf(stderr,
- _("%s: data directory \"%s\" not removed at user's request\n"),
- progname, basedir);
+ pg_log_info("data directory \"%s\" not removed at user's request", basedir);
if (made_new_xlogdir || found_existing_xlogdir)
- fprintf(stderr,
- _("%s: WAL directory \"%s\" not removed at user's request\n"),
- progname, xlog_dir);
+ pg_log_info("WAL directory \"%s\" not removed at user's request", xlog_dir);
}
if ((made_tablespace_dirs || found_tablespace_dirs) && !checksum_failure)
- fprintf(stderr,
- _("%s: changes to tablespace directories will not be undone\n"),
- progname);
+ pg_log_info("changes to tablespace directories will not be undone");
}
static void
{
if (dst_ptr - dst >= MAXPGPATH)
{
- fprintf(stderr, _("%s: directory name too long\n"), progname);
+ pg_log_error("directory name too long");
exit(1);
}
{
if (*cell->new_dir)
{
- fprintf(stderr, _("%s: multiple \"=\" signs in tablespace mapping\n"), progname);
+ pg_log_error("multiple \"=\" signs in tablespace mapping");
exit(1);
}
else
if (!*cell->old_dir || !*cell->new_dir)
{
- fprintf(stderr,
- _("%s: invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"\n"),
- progname, arg);
+ pg_log_error("invalid tablespace mapping format \"%s\", must be \"OLDDIR=NEWDIR\"", arg);
exit(1);
}
*/
if (!is_absolute_path(cell->old_dir))
{
- fprintf(stderr, _("%s: old directory is not an absolute path in tablespace mapping: %s\n"),
- progname, cell->old_dir);
+ pg_log_error("old directory is not an absolute path in tablespace mapping: %s",
+ cell->old_dir);
exit(1);
}
if (!is_absolute_path(cell->new_dir))
{
- fprintf(stderr, _("%s: new directory is not an absolute path in tablespace mapping: %s\n"),
- progname, cell->new_dir);
+ pg_log_error("new directory is not an absolute path in tablespace mapping: %s",
+ cell->new_dir);
exit(1);
}
r = read(bgpipe[0], xlogend, sizeof(xlogend) - 1);
if (r < 0)
{
- fprintf(stderr, _("%s: could not read from ready pipe: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not read from ready pipe: %m");
exit(1);
}
if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr,
- _("%s: could not parse write-ahead log location \"%s\"\n"),
- progname, xlogend);
+ pg_log_error("could not parse write-ahead log location \"%s\"",
+ xlogend);
exit(1);
}
xlogendptr = ((uint64) hi) << 32 | lo;
if (!stream.walmethod->finish())
{
- fprintf(stderr,
- _("%s: could not finish writing WAL files: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not finish writing WAL files: %m");
return 1;
}
/* Convert the starting position */
if (sscanf(startpos, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr,
- _("%s: could not parse write-ahead log location \"%s\"\n"),
- progname, startpos);
+ pg_log_error("could not parse write-ahead log location \"%s\"",
+ startpos);
exit(1);
}
param->startptr = ((uint64) hi) << 32 | lo;
/* Create our background pipe */
if (pipe(bgpipe) < 0)
{
- fprintf(stderr,
- _("%s: could not create pipe for background process: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not create pipe for background process: %m");
exit(1);
}
#endif
if (verbose)
{
if (temp_replication_slot)
- fprintf(stderr, _("%s: created temporary replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("created temporary replication slot \"%s\"",
+ replication_slot);
else
- fprintf(stderr, _("%s: created replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("created replication slot \"%s\"",
+ replication_slot);
}
}
if (pg_mkdir_p(statusdir, pg_dir_create_mode) != 0 && errno != EEXIST)
{
- fprintf(stderr,
- _("%s: could not create directory \"%s\": %s\n"),
- progname, statusdir, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m", statusdir);
exit(1);
}
}
}
else if (bgchild < 0)
{
- fprintf(stderr, _("%s: could not create background process: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not create background process: %m");
exit(1);
}
bgchild = _beginthreadex(NULL, 0, (void *) LogStreamerMain, param, 0, NULL);
if (bgchild == 0)
{
- fprintf(stderr, _("%s: could not create background thread: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not create background thread: %m");
exit(1);
}
#endif
*/
if (pg_mkdir_p(dirname, pg_dir_create_mode) == -1)
{
- fprintf(stderr,
- _("%s: could not create directory \"%s\": %s\n"),
- progname, dirname, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m", dirname);
exit(1);
}
if (created)
/*
* Exists, not empty
*/
- fprintf(stderr,
- _("%s: directory \"%s\" exists but is not empty\n"),
- progname, dirname);
+ pg_log_error("directory \"%s\" exists but is not empty", dirname);
exit(1);
case -1:
/*
* Access problem
*/
- fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
- progname, dirname, strerror(errno));
+ pg_log_error("could not access directory \"%s\": %m", dirname);
exit(1);
}
}
result = strtod(src, &after_num);
if (src == after_num)
{
- fprintf(stderr,
- _("%s: transfer rate \"%s\" is not a valid value\n"),
- progname, src);
+ pg_log_error("transfer rate \"%s\" is not a valid value", src);
exit(1);
}
if (errno != 0)
{
- fprintf(stderr,
- _("%s: invalid transfer rate \"%s\": %s\n"),
- progname, src, strerror(errno));
+ pg_log_error("invalid transfer rate \"%s\": %m", src);
exit(1);
}
/*
* Reject obviously wrong values here.
*/
- fprintf(stderr, _("%s: transfer rate must be greater than zero\n"),
- progname);
+ pg_log_error("transfer rate must be greater than zero");
exit(1);
}
if (*after_num != '\0')
{
- fprintf(stderr,
- _("%s: invalid --max-rate unit: \"%s\"\n"),
- progname, suffix);
+ pg_log_error("invalid --max-rate unit: \"%s\"", suffix);
exit(1);
}
/* Valid integer? */
if ((uint64) result != (uint64) ((uint32) result))
{
- fprintf(stderr,
- _("%s: transfer rate \"%s\" exceeds integer range\n"),
- progname, src);
+ pg_log_error("transfer rate \"%s\" exceeds integer range", src);
exit(1);
}
*/
if (result < MAX_RATE_LOWER || result > MAX_RATE_UPPER)
{
- fprintf(stderr,
- _("%s: transfer rate \"%s\" is out of range\n"),
- progname, src);
+ pg_log_error("transfer rate \"%s\" is out of range", src);
exit(1);
}
{
if (gzwrite(ztarfile, buf, r) != r)
{
- fprintf(stderr,
- _("%s: could not write to compressed file \"%s\": %s\n"),
- progname, current_file, get_gz_error(ztarfile));
+ pg_log_error("could not write to compressed file \"%s\": %s",
+ current_file, get_gz_error(ztarfile));
exit(1);
}
}
{
if (fwrite(buf, r, 1, tarfile) != 1)
{
- fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
- progname, current_file, strerror(errno));
+ pg_log_error("could not write to file \"%s\": %m", current_file);
exit(1);
}
}
if (gzsetparams(ztarfile, compresslevel,
Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr,
- _("%s: could not set compression level %d: %s\n"),
- progname, compresslevel, get_gz_error(ztarfile));
+ pg_log_error("could not set compression level %d: %s",
+ compresslevel, get_gz_error(ztarfile));
exit(1);
}
}
if (gzsetparams(ztarfile, compresslevel,
Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr,
- _("%s: could not set compression level %d: %s\n"),
- progname, compresslevel, get_gz_error(ztarfile));
+ pg_log_error("could not set compression level %d: %s",
+ compresslevel, get_gz_error(ztarfile));
exit(1);
}
}
if (gzsetparams(ztarfile, compresslevel,
Z_DEFAULT_STRATEGY) != Z_OK)
{
- fprintf(stderr,
- _("%s: could not set compression level %d: %s\n"),
- progname, compresslevel, get_gz_error(ztarfile));
+ pg_log_error("could not set compression level %d: %s",
+ compresslevel, get_gz_error(ztarfile));
exit(1);
}
}
if (!ztarfile)
{
/* Compression is in use */
- fprintf(stderr,
- _("%s: could not create compressed file \"%s\": %s\n"),
- progname, filename, get_gz_error(ztarfile));
+ pg_log_error("could not create compressed file \"%s\": %s",
+ filename, get_gz_error(ztarfile));
exit(1);
}
}
/* Either no zlib support, or zlib support but compresslevel = 0 */
if (!tarfile)
{
- fprintf(stderr, _("%s: could not create file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not create file \"%s\": %m", filename);
exit(1);
}
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COPY_OUT)
{
- fprintf(stderr, _("%s: could not get COPY data stream: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not get COPY data stream: %s",
+ PQerrorMessage(conn));
exit(1);
}
{
if (gzclose(ztarfile) != 0)
{
- fprintf(stderr,
- _("%s: could not close compressed file \"%s\": %s\n"),
- progname, filename, get_gz_error(ztarfile));
+ pg_log_error("could not close compressed file \"%s\": %s",
+ filename, get_gz_error(ztarfile));
exit(1);
}
}
{
if (fclose(tarfile) != 0)
{
- fprintf(stderr,
- _("%s: could not close file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not close file \"%s\": %m",
+ filename);
exit(1);
}
}
}
else if (r == -2)
{
- fprintf(stderr, _("%s: could not read COPY data: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not read COPY data: %s",
+ PQerrorMessage(conn));
exit(1);
}
/* sync the resulting tar file, errors are not considered fatal */
if (do_sync && strcmp(basedir, "-") != 0)
- (void) fsync_fname(filename, false, progname);
+ (void) fsync_fname(filename, false);
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_COPY_OUT)
{
- fprintf(stderr, _("%s: could not get COPY data stream: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not get COPY data stream: %s",
+ PQerrorMessage(conn));
exit(1);
}
}
else if (r == -2)
{
- fprintf(stderr, _("%s: could not read COPY data: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not read COPY data: %s",
+ PQerrorMessage(conn));
exit(1);
}
*/
if (r != 512)
{
- fprintf(stderr, _("%s: invalid tar block header size: %d\n"),
- progname, r);
+ pg_log_error("invalid tar block header size: %d", r);
exit(1);
}
totaldone += 512;
pg_str_endswith(filename, "/archive_status")) &&
errno == EEXIST))
{
- fprintf(stderr,
- _("%s: could not create directory \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not create directory \"%s\": %m",
+ filename);
exit(1);
}
}
#ifndef WIN32
if (chmod(filename, (mode_t) filemode))
- fprintf(stderr,
- _("%s: could not set permissions on directory \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not set permissions on directory \"%s\": %m",
+ filename);
#endif
}
else if (copybuf[156] == '2')
mapped_tblspc_path = get_tablespace_mapping(©buf[157]);
if (symlink(mapped_tblspc_path, filename) != 0)
{
- fprintf(stderr,
- _("%s: could not create symbolic link from \"%s\" to \"%s\": %s\n"),
- progname, filename, mapped_tblspc_path,
- strerror(errno));
+ pg_log_error("could not create symbolic link from \"%s\" to \"%s\": %m",
+ filename, mapped_tblspc_path);
exit(1);
}
}
else
{
- fprintf(stderr,
- _("%s: unrecognized link indicator \"%c\"\n"),
- progname, copybuf[156]);
+ pg_log_error("unrecognized link indicator \"%c\"",
+ copybuf[156]);
exit(1);
}
continue; /* directory or link handled */
file = fopen(filename, "wb");
if (!file)
{
- fprintf(stderr, _("%s: could not create file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not create file \"%s\": %m", filename);
exit(1);
}
#ifndef WIN32
if (chmod(filename, (mode_t) filemode))
- fprintf(stderr, _("%s: could not set permissions on file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not set permissions on file \"%s\": %m",
+ filename);
#endif
if (current_len_left == 0)
if (fwrite(copybuf, r, 1, file) != 1)
{
- fprintf(stderr, _("%s: could not write to file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not write to file \"%s\": %m", filename);
exit(1);
}
totaldone += r;
if (file != NULL)
{
- fprintf(stderr,
- _("%s: COPY stream ended before last file was finished\n"),
- progname);
+ pg_log_error("COPY stream ended before last file was finished");
exit(1);
}
if (!result)
{
- fprintf(stderr, _("%s: out of memory\n"), progname);
+ pg_log_error("out of memory");
exit(1);
}
return result;
recoveryconfcontents = createPQExpBuffer();
if (!recoveryconfcontents)
{
- fprintf(stderr, _("%s: out of memory\n"), progname);
+ pg_log_error("out of memory");
exit(1);
}
connOptions = PQconninfo(conn);
if (connOptions == NULL)
{
- fprintf(stderr, _("%s: out of memory\n"), progname);
+ pg_log_error("out of memory");
exit(1);
}
if (PQExpBufferBroken(recoveryconfcontents) ||
PQExpBufferDataBroken(conninfo_buf))
{
- fprintf(stderr, _("%s: out of memory\n"), progname);
+ pg_log_error("out of memory");
exit(1);
}
cf = fopen(filename, is_recovery_guc_supported ? "a" : "w");
if (cf == NULL)
{
- fprintf(stderr, _("%s: could not open file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not open file \"%s\": %m", filename);
exit(1);
}
if (fwrite(recoveryconfcontents->data, recoveryconfcontents->len, 1, cf) != 1)
{
- fprintf(stderr,
- _("%s: could not write to file \"%s\": %s\n"),
- progname, filename, strerror(errno));
+ pg_log_error("could not write to file \"%s\": %m", filename);
exit(1);
}
cf = fopen(filename, "w");
if (cf == NULL)
{
- fprintf(stderr, _("%s: could not create file \"%s\": %s\n"), progname, filename, strerror(errno));
+ pg_log_error("could not create file \"%s\": %m", filename);
exit(1);
}
{
const char *serverver = PQparameterStatus(conn, "server_version");
- fprintf(stderr, _("%s: incompatible server version %s\n"),
- progname, serverver ? serverver : "'unknown'");
+ pg_log_error("incompatible server version %s",
+ serverver ? serverver : "'unknown'");
exit(1);
}
* Error message already written in CheckServerVersionForStreaming(),
* but add a hint about using -X none.
*/
- fprintf(stderr, _("HINT: use -X none or -X fetch to disable log streaming\n"));
+ pg_log_info("HINT: use -X none or -X fetch to disable log streaming");
exit(1);
}
maxrate_clause = psprintf("MAX_RATE %u", maxrate);
if (verbose)
- fprintf(stderr,
- _("%s: initiating base backup, waiting for checkpoint to complete\n"),
- progname);
+ pg_log_info("initiating base backup, waiting for checkpoint to complete");
if (showprogress && !verbose)
{
if (PQsendQuery(conn, basebkp) == 0)
{
- fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
- progname, "BASE_BACKUP", PQerrorMessage(conn));
+ pg_log_error("could not send replication command \"%s\": %s",
+ "BASE_BACKUP", PQerrorMessage(conn));
exit(1);
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not initiate base backup: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not initiate base backup: %s",
+ PQerrorMessage(conn));
exit(1);
}
if (PQntuples(res) != 1)
{
- fprintf(stderr,
- _("%s: server returned unexpected response to BASE_BACKUP command; got %d rows and %d fields, expected %d rows and %d fields\n"),
- progname, PQntuples(res), PQnfields(res), 1, 2);
+ 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);
}
strlcpy(xlogstart, PQgetvalue(res, 0, 0), sizeof(xlogstart));
if (verbose)
- fprintf(stderr, _("%s: checkpoint completed\n"), progname);
+ pg_log_info("checkpoint completed");
/*
* 9.3 and later sends the TLI of the starting point. With older servers,
MemSet(xlogend, 0, sizeof(xlogend));
if (verbose && includewal != NO_WAL)
- fprintf(stderr, _("%s: write-ahead log start point: %s on timeline %u\n"),
- progname, xlogstart, starttli);
+ pg_log_info("write-ahead log start point: %s on timeline %u",
+ xlogstart, starttli);
/*
* Get the header
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr, _("%s: could not get backup header: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not get backup header: %s",
+ PQerrorMessage(conn));
exit(1);
}
if (PQntuples(res) < 1)
{
- fprintf(stderr, _("%s: no data returned from server\n"), progname);
+ pg_log_error("no data returned from server");
exit(1);
}
*/
if (format == 't' && strcmp(basedir, "-") == 0 && PQntuples(res) > 1)
{
- fprintf(stderr,
- _("%s: can only write single tablespace to stdout, database has %d\n"),
- progname, PQntuples(res));
+ pg_log_error("can only write single tablespace to stdout, database has %d",
+ PQntuples(res));
exit(1);
}
if (includewal == STREAM_WAL)
{
if (verbose)
- fprintf(stderr, _("%s: starting background WAL receiver\n"),
- progname);
+ pg_log_info("starting background WAL receiver");
StartLogStreamer(xlogstart, starttli, sysidentifier);
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
- fprintf(stderr,
- _("%s: could not get write-ahead log end position from server: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not get write-ahead log end position from server: %s",
+ PQerrorMessage(conn));
exit(1);
}
if (PQntuples(res) != 1)
{
- fprintf(stderr,
- _("%s: no write-ahead log end position returned from server\n"),
- progname);
+ pg_log_error("no write-ahead log end position returned from server");
exit(1);
}
strlcpy(xlogend, PQgetvalue(res, 0, 0), sizeof(xlogend));
if (verbose && includewal != NO_WAL)
- fprintf(stderr, _("%s: write-ahead log end point: %s\n"), progname, xlogend);
+ pg_log_info("write-ahead log end point: %s", xlogend);
PQclear(res);
res = PQgetResult(conn);
if (sqlstate &&
strcmp(sqlstate, ERRCODE_DATA_CORRUPTED) == 0)
{
- fprintf(stderr, _("%s: checksum error occurred\n"),
- progname);
+ pg_log_error("checksum error occurred");
checksum_failure = true;
}
else
{
- fprintf(stderr, _("%s: final receive failed: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("final receive failed: %s",
+ PQerrorMessage(conn));
}
exit(1);
}
#endif
if (verbose)
- fprintf(stderr,
- _("%s: waiting for background process to finish streaming ...\n"), progname);
+ pg_log_info("waiting for background process to finish streaming ...");
#ifndef WIN32
if (write(bgpipe[1], xlogend, strlen(xlogend)) != strlen(xlogend))
{
- fprintf(stderr,
- _("%s: could not send command to background pipe: %s\n"),
- progname, strerror(errno));
+ pg_log_info("could not send command to background pipe: %m");
exit(1);
}
r = waitpid(bgchild, &status, 0);
if (r == (pid_t) -1)
{
- fprintf(stderr, _("%s: could not wait for child process: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not wait for child process: %m");
exit(1);
}
if (r != bgchild)
{
- fprintf(stderr, _("%s: child %d died, expected %d\n"),
- progname, (int) r, (int) bgchild);
+ pg_log_error("child %d died, expected %d", (int) r, (int) bgchild);
exit(1);
}
if (status != 0)
{
- fprintf(stderr, "%s: %s\n",
- progname, wait_result_to_str(status));
+ pg_log_error("%s", wait_result_to_str(status));
exit(1);
}
/* Exited normally, we're happy! */
*/
if (sscanf(xlogend, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr,
- _("%s: could not parse write-ahead log location \"%s\"\n"),
- progname, xlogend);
+ pg_log_error("could not parse write-ahead log location \"%s\"",
+ xlogend);
exit(1);
}
xlogendptr = ((uint64) hi) << 32 | lo;
WAIT_OBJECT_0)
{
_dosmaperr(GetLastError());
- fprintf(stderr, _("%s: could not wait for child thread: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not wait for child thread: %m");
exit(1);
}
if (GetExitCodeThread((HANDLE) bgchild_handle, &status) == 0)
{
_dosmaperr(GetLastError());
- fprintf(stderr, _("%s: could not get child thread exit status: %s\n"),
- progname, strerror(errno));
+ pg_log_error("could not get child thread exit status: %m");
exit(1);
}
if (status != 0)
{
- fprintf(stderr, _("%s: child thread exited with error %u\n"),
- progname, (unsigned int) status);
+ pg_log_error("child thread exited with error %u",
+ (unsigned int) status);
exit(1);
}
/* Exited normally, we're happy */
if (do_sync)
{
if (verbose)
- fprintf(stderr,
- _("%s: syncing data to disk ...\n"), progname);
+ pg_log_info("syncing data to disk ...");
if (format == 't')
{
if (strcmp(basedir, "-") != 0)
- (void) fsync_fname(basedir, true, progname);
+ (void) fsync_fname(basedir, true);
}
else
{
- (void) fsync_pgdata(basedir, progname, serverVersion);
+ (void) fsync_pgdata(basedir, serverVersion);
}
}
if (verbose)
- fprintf(stderr, _("%s: base backup completed\n"), progname);
+ pg_log_info("base backup completed");
}
int option_index;
+ pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
format = 't';
else
{
- fprintf(stderr,
- _("%s: invalid output format \"%s\", must be \"plain\" or \"tar\"\n"),
- progname, optarg);
+ pg_log_error("invalid output format \"%s\", must be \"plain\" or \"tar\"\n",
+ optarg);
exit(1);
}
break;
}
else
{
- fprintf(stderr,
- _("%s: invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"\n"),
- progname, optarg);
+ pg_log_error("invalid wal-method option \"%s\", must be \"fetch\", \"stream\", or \"none\"",
+ optarg);
exit(1);
}
break;
compresslevel = atoi(optarg);
if (compresslevel < 0 || compresslevel > 9)
{
- fprintf(stderr, _("%s: invalid compression level \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid compression level \"%s\"\n", optarg);
exit(1);
}
break;
fastcheckpoint = false;
else
{
- fprintf(stderr, _("%s: invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"\n"),
- progname, optarg);
+ pg_log_error("invalid checkpoint argument \"%s\", must be \"fast\" or \"spread\"",
+ optarg);
exit(1);
}
break;
standby_message_timeout = atoi(optarg) * 1000;
if (standby_message_timeout < 0)
{
- fprintf(stderr, _("%s: invalid status interval \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid status interval \"%s\"", optarg);
exit(1);
}
break;
*/
if (optind < argc)
{
- fprintf(stderr,
- _("%s: too many command-line arguments (first is \"%s\")\n"),
- progname, argv[optind]);
+ pg_log_error("too many command-line arguments (first is \"%s\")",
+ argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
*/
if (basedir == NULL)
{
- fprintf(stderr, _("%s: no target directory specified\n"), progname);
+ pg_log_error("no target directory specified");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
*/
if (format == 'p' && compresslevel != 0)
{
- fprintf(stderr,
- _("%s: only tar mode backups can be compressed\n"),
- progname);
+ pg_log_error("only tar mode backups can be compressed");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
if (format == 't' && includewal == STREAM_WAL && strcmp(basedir, "-") == 0)
{
- fprintf(stderr,
- _("%s: cannot stream write-ahead logs in tar mode to stdout\n"),
- progname);
+ pg_log_error("cannot stream write-ahead logs in tar mode to stdout");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
if (replication_slot && includewal != STREAM_WAL)
{
- fprintf(stderr,
- _("%s: replication slots can only be used with WAL streaming\n"),
- progname);
+ pg_log_error("replication slots can only be used with WAL streaming");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
{
if (replication_slot)
{
- fprintf(stderr,
- _("%s: --no-slot cannot be used with slot name\n"),
- progname);
+ pg_log_error("--no-slot cannot be used with slot name");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
{
if (!replication_slot)
{
- fprintf(stderr,
- _("%s: %s needs a slot to be specified using --slot\n"),
- progname, "--create-slot");
+ pg_log_error("%s needs a slot to be specified using --slot",
+ "--create-slot");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
if (no_slot)
{
- fprintf(stderr,
- _("%s: --create-slot and --no-slot are incompatible options\n"),
- progname);
+ pg_log_error("--create-slot and --no-slot are incompatible options");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
{
if (format != 'p')
{
- fprintf(stderr,
- _("%s: WAL directory location can only be specified in plain mode\n"),
- progname);
+ pg_log_error("WAL directory location can only be specified in plain mode");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
canonicalize_path(xlog_dir);
if (!is_absolute_path(xlog_dir))
{
- fprintf(stderr, _("%s: WAL directory location must be "
- "an absolute path\n"), progname);
+ pg_log_error("WAL directory location must be an absolute path");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
#ifndef HAVE_LIBZ
if (compresslevel != 0)
{
- fprintf(stderr,
- _("%s: this build does not support compression\n"),
- progname);
+ pg_log_error("this build does not support compression");
exit(1);
}
#endif
#ifdef HAVE_SYMLINK
if (symlink(xlog_dir, linkloc) != 0)
{
- fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
- progname, linkloc, strerror(errno));
+ pg_log_error("could not create symbolic link \"%s\": %m", linkloc);
exit(1);
}
#else
- fprintf(stderr, _("%s: symlinks are not supported on this platform\n"), progname);
+ pg_log_error("symlinks are not supported on this platform");
exit(1);
#endif
free(linkloc);
#include <unistd.h>
#include "common/file_perm.h"
+#include "fe_utils/logging.h"
#include "libpq-fe.h"
#include "access/xlog_internal.h"
#include "getopt_long.h"
/* we assume that we get called once at the end of each segment */
if (verbose && segment_finished)
- fprintf(stderr, _("%s: finished segment at %X/%X (timeline %u)\n"),
- progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
- timeline);
+ pg_log_info("finished segment at %X/%X (timeline %u)",
+ (uint32) (xlogpos >> 32), (uint32) xlogpos,
+ timeline);
if (!XLogRecPtrIsInvalid(endpos) && endpos < xlogpos)
{
if (verbose)
- fprintf(stderr, _("%s: stopped log streaming at %X/%X (timeline %u)\n"),
- progname, (uint32) (xlogpos >> 32), (uint32) xlogpos,
- timeline);
+ pg_log_info("stopped log streaming at %X/%X (timeline %u)",
+ (uint32) (xlogpos >> 32), (uint32) xlogpos,
+ timeline);
time_to_stop = true;
return true;
}
* timeline, but it's close enough for reporting purposes.
*/
if (verbose && prevtimeline != 0 && prevtimeline != timeline)
- fprintf(stderr, _("%s: switched to timeline %u at %X/%X\n"),
- progname, timeline,
- (uint32) (prevpos >> 32), (uint32) prevpos);
+ pg_log_info("switched to timeline %u at %X/%X",
+ timeline,
+ (uint32) (prevpos >> 32), (uint32) prevpos);
prevtimeline = timeline;
prevpos = xlogpos;
if (time_to_stop)
{
if (verbose)
- fprintf(stderr, _("%s: received interrupt signal, exiting\n"),
- progname);
+ pg_log_info("received interrupt signal, exiting");
return true;
}
return false;
dir = opendir(dest_folder);
if (dir == NULL)
{
- fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
- progname, basedir, strerror(errno));
+ pg_log_error("could not open directory \"%s\": %m", basedir);
exit(1);
}
Assert(dest_dir != NULL && dest_folder != NULL);
if (closedir(dest_dir))
{
- fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
- progname, dest_folder, strerror(errno));
+ pg_log_error("could not close directory \"%s\": %m", dest_folder);
exit(1);
}
}
snprintf(fullpath, sizeof(fullpath), "%s/%s", basedir, dirent->d_name);
if (stat(fullpath, &statbuf) != 0)
{
- fprintf(stderr, _("%s: could not stat file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not stat file \"%s\": %m", fullpath);
exit(1);
}
if (statbuf.st_size != WalSegSz)
{
- fprintf(stderr,
- _("%s: segment file \"%s\" has incorrect size %d, skipping\n"),
- progname, dirent->d_name, (int) statbuf.st_size);
+ pg_log_warning("segment file \"%s\" has incorrect size %d, skipping",
+ dirent->d_name, (int) statbuf.st_size);
continue;
}
}
fd = open(fullpath, O_RDONLY | PG_BINARY, 0);
if (fd < 0)
{
- fprintf(stderr, _("%s: could not open compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not open compressed file \"%s\": %m",
+ fullpath);
exit(1);
}
if (lseek(fd, (off_t) (-4), SEEK_END) < 0)
{
- fprintf(stderr, _("%s: could not seek in compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not seek in compressed file \"%s\": %m",
+ fullpath);
exit(1);
}
r = read(fd, (char *) buf, sizeof(buf));
if (r != sizeof(buf))
{
if (r < 0)
- fprintf(stderr, _("%s: could not read compressed file \"%s\": %s\n"),
- progname, fullpath, strerror(errno));
+ pg_log_error("could not read compressed file \"%s\": %m",
+ fullpath);
else
- fprintf(stderr, _("%s: could not read compressed file \"%s\": read %d of %zu\n"),
- progname, fullpath, r, sizeof(buf));
+ pg_log_error("could not read compressed file \"%s\": read %d of %zu",
+ fullpath, r, sizeof(buf));
exit(1);
}
if (bytes_out != WalSegSz)
{
- fprintf(stderr,
- _("%s: compressed segment file \"%s\" has incorrect uncompressed size %d, skipping\n"),
- progname, dirent->d_name, bytes_out);
+ pg_log_warning("compressed segment file \"%s\" has incorrect uncompressed size %d, skipping",
+ dirent->d_name, bytes_out);
continue;
}
}
if (errno)
{
- fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
- progname, basedir, strerror(errno));
+ pg_log_error("could not read directory \"%s\": %m", basedir);
exit(1);
}
* Start the replication
*/
if (verbose)
- fprintf(stderr,
- _("%s: starting log streaming at %X/%X (timeline %u)\n"),
- progname, (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
- stream.timeline);
+ pg_log_info("starting log streaming at %X/%X (timeline %u)",
+ (uint32) (stream.startpos >> 32), (uint32) stream.startpos,
+ stream.timeline);
stream.stream_stop = stop_streaming;
stream.stop_socket = PGINVALID_SOCKET;
if (!stream.walmethod->finish())
{
- fprintf(stderr,
- _("%s: could not finish writing WAL files: %s\n"),
- progname, strerror(errno));
+ pg_log_info("could not finish writing WAL files: %m");
return;
}
uint32 hi,
lo;
+ pg_logging_init(argv[0]);
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_basebackup"));
case 'p':
if (atoi(optarg) <= 0)
{
- fprintf(stderr, _("%s: invalid port number \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid port number \"%s\"", optarg);
exit(1);
}
dbport = pg_strdup(optarg);
standby_message_timeout = atoi(optarg) * 1000;
if (standby_message_timeout < 0)
{
- fprintf(stderr, _("%s: invalid status interval \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid status interval \"%s\"", optarg);
exit(1);
}
break;
case 'E':
if (sscanf(optarg, "%X/%X", &hi, &lo) != 2)
{
- fprintf(stderr,
- _("%s: could not parse end position \"%s\"\n"),
- progname, optarg);
+ pg_log_error("could not parse end position \"%s\"", optarg);
exit(1);
}
endpos = ((uint64) hi) << 32 | lo;
compresslevel = atoi(optarg);
if (compresslevel < 0 || compresslevel > 9)
{
- fprintf(stderr, _("%s: invalid compression level \"%s\"\n"),
- progname, optarg);
+ pg_log_error("invalid compression level \"%s\"", optarg);
exit(1);
}
break;
*/
if (optind < argc)
{
- fprintf(stderr,
- _("%s: too many command-line arguments (first is \"%s\")\n"),
- progname, argv[optind]);
+ pg_log_error("too many command-line arguments (first is \"%s\")",
+ argv[optind]);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
if (do_drop_slot && do_create_slot)
{
- fprintf(stderr, _("%s: cannot use --create-slot together with --drop-slot\n"), progname);
+ pg_log_error("cannot use --create-slot together with --drop-slot");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
if (replication_slot == NULL && (do_drop_slot || do_create_slot))
{
/* translator: second %s is an option name */
- fprintf(stderr, _("%s: %s needs a slot to be specified using --slot\n"), progname,
+ 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);
if (synchronous && !do_sync)
{
- fprintf(stderr, _("%s: cannot use --synchronous together with --no-sync\n"), progname);
+ pg_log_error("cannot use --synchronous together with --no-sync");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
*/
if (basedir == NULL && !do_drop_slot && !do_create_slot)
{
- fprintf(stderr, _("%s: no target directory specified\n"), progname);
+ pg_log_error("no target directory specified");
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
#ifndef HAVE_LIBZ
if (compresslevel != 0)
{
- fprintf(stderr,
- _("%s: this build does not support compression\n"),
- progname);
+ pg_log_error("this build does not support compression");
exit(1);
}
#endif
*/
if (db_name)
{
- fprintf(stderr,
- _("%s: replication connection using slot \"%s\" is unexpectedly database specific\n"),
- progname, replication_slot);
+ pg_log_error("replication connection using slot \"%s\" is unexpectedly database specific",
+ replication_slot);
exit(1);
}
if (do_drop_slot)
{
if (verbose)
- fprintf(stderr,
- _("%s: dropping replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("dropping replication slot \"%s\"", replication_slot);
if (!DropReplicationSlot(conn, replication_slot))
exit(1);
if (do_create_slot)
{
if (verbose)
- fprintf(stderr,
- _("%s: creating replication slot \"%s\"\n"),
- progname, replication_slot);
+ pg_log_info("creating replication slot \"%s\"", replication_slot);
if (!CreateReplicationSlot(conn, replication_slot, NULL, false, true, false,
slot_exists_ok))
}
else if (noloop)
{
- fprintf(stderr, _("%s: disconnected\n"), progname);
+ pg_log_error("disconnected");
exit(1);
}
else
{
- fprintf(stderr,
/* translator: check source for value for %d */
- _("%s: disconnected; waiting %d seconds to try again\n"),
- progname, RECONNECT_SLEEP_TIME);
+ pg_log_info("disconnected; waiting %d seconds to try again",
+ RECONNECT_SLEEP_TIME);
pg_usleep(RECONNECT_SLEEP_TIME * 1000000);
}
}
#include "access/xlog_internal.h"
#include "common/file_perm.h"
#include "common/fe_memutils.h"
+#include "fe_utils/logging.h"
#include "getopt_long.h"
#include "libpq-fe.h"
#include "libpq/pqsignal.h"
return true;
if (verbose)
- fprintf(stderr,
- _("%s: confirming write up to %X/%X, flush to %X/%X (slot %s)\n"),
- progname,
+ pg_log_info("confirming write up to %X/%X, flush to %X/%X (slot %s)",
(uint32) (output_written_lsn >> 32), (uint32) output_written_lsn,
(uint32) (output_fsync_lsn >> 32), (uint32) output_fsync_lsn,
replication_slot);
if (PQputCopyData(conn, replybuf, len) <= 0 || PQflush(conn))
{
- fprintf(stderr, _("%s: could not send feedback packet: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not send feedback packet: %s",
+ PQerrorMessage(conn));
return false;
}
if (fsync(outfd) != 0)
{
- fprintf(stderr,
- _("%s: could not fsync file \"%s\": %s\n"),
- progname, outfile, strerror(errno));
+ pg_log_error("could not fsync file \"%s\": %m", outfile);
return false;
}
* Start the replication
*/
if (verbose)
- fprintf(stderr,
- _("%s: starting log streaming at %X/%X (slot %s)\n"),
- progname, (uint32) (startpos >> 32), (uint32) startpos,
- replication_slot);
+ pg_log_info("starting log streaming at %X/%X (slot %s)",
+ (uint32) (startpos >> 32), (uint32) startpos,
+ replication_slot);
/* Initiate the replication stream at specified location */
appendPQExpBuffer(query, "START_REPLICATION SLOT \"%s\" LOGICAL %X/%X",
res = PQexec(conn, query->data);
if (PQresultStatus(res) != PGRES_COPY_BOTH)
{
- fprintf(stderr, _("%s: could not send replication command \"%s\": %s"),
- progname, query->data, PQresultErrorMessage(res));
+ pg_log_error("could not send replication command \"%s\": %s",
+ query->data, PQresultErrorMessage(res));
PQclear(res);
goto error;
}
resetPQExpBuffer(query);
if (verbose)
- fprintf(stderr,
- _("%s: streaming initiated\n"),
- progname);
+ pg_log_info("streaming initiated");
while (!time_to_abort)
{
S_IRUSR | S_IWUSR);
if (outfd == -1)
{
- fprintf(stderr,
- _("%s: could not open log file \"%s\": %s\n"),
- progname, outfile, strerror(errno));
+ pg_log_error("could not open log file \"%s\": %m", outfile);
goto error;
}
if (fstat(outfd, &statbuf) != 0)
- fprintf(stderr,
- _("%s: could not stat file \"%s\": %s\n"),
- progname, outfile, strerror(errno));
+ pg_log_error("could not stat file \"%s\": %m", outfile);
output_isfile = S_ISREG(statbuf.st_mode) && !isatty(outfd);
}
if (PQsocket(conn) < 0)
{
- fprintf(stderr,
- _("%s: invalid socket: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("invalid socket: %s", PQerrorMessage(conn));
goto error;
}
}
else if (r < 0)
{
- fprintf(stderr, _("%s: select() failed: %s\n"),
- progname, strerror(errno));
+ pg_log_error("select() failed: %m");
goto error;
}
/* Else there is actually data on the socket */
if (PQconsumeInput(conn) == 0)
{
- fprintf(stderr,
- _("%s: could not receive data from WAL stream: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not receive data from WAL stream: %s",
+ PQerrorMessage(conn));
goto error;
}
continue;
/* Failure while reading the copy stream */
if (r == -2)
{
- fprintf(stderr, _("%s: could not read COPY data: %s"),
- progname, PQerrorMessage(conn));
+ pg_log_error("could not read COPY data: %s",
+ PQerrorMessage(conn));
goto error;
}
if (r < pos + 1)
{
- fprintf(stderr, _("%s: streaming header too small: %d\n"),
- progname, r);
+ pg_log_error("streaming header too small: %d", r);
goto error;
}
replyRequested = copybuf[pos];
}
else if (copybuf[0] != 'w')
{
- fprintf(stderr, _("%s: unrecognized streaming header: \"%c\"\n"),
- progname, copybuf[0]);
+ pg_log_error("unrecognized streaming header: \"%c\"",
+ copybuf[0]);
goto error;
}
hdr_len += 8; /* sendTime */
if (r < hdr_len + 1)
{
- fprintf(stderr, _("%s: streaming header too small: %d\n"),
- progname, r);
+ pg_log_error("streaming header too small: %d", r);
goto error;
}
if (ret < 0)
{
- fprintf(stderr,
- _("%s: could not write %u bytes to log file \"%s\": %s\n"),
- progname, bytes_left, outfile,
- strerror(errno));
+ pg_log_error("could not write %u bytes to log file \"%s\": %m",
+ bytes_left, outfile);
goto error;
}
if (write(outfd, "\n", 1) != 1)
{
- fprintf(stderr,
- _("%s: could not write %u bytes to log file \"%s\": %s\n"),
- progname, 1, outfile,
- strerror(errno));
+ pg_log_error("could not write %u bytes to log file \"%s\": %m",
+ 1, outfile);
goto error;
}
}
else if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
- fprintf(stderr,
- _("%s: unexpected termination of replication stream: %s"),
- progname, PQresultErrorMessage(res));
+ pg_log_error("unexpected termination of replication stream: %s",
+ &n