mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
pg_dumpall: Add a -E flag to set the encoding, like pg_dump has.
Michael Paquier, reviewed by Fabien Coelho Discussion: http://postgr.es/m/CAB7nPqQcYWmrm2n-dVaMUhYPKFU_DxQwPuUGuC4ZF+8B=dS5xQ@mail.gmail.com
This commit is contained in:
parent
2f5ada2710
commit
84be67181a
@ -99,6 +99,19 @@ PostgreSQL documentation
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>-E <replaceable class="parameter">encoding</replaceable></option></term>
|
||||||
|
<term><option>--encoding=<replaceable class="parameter">encoding</replaceable></option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Create the dump in the specified character set encoding. By default,
|
||||||
|
the dump is created in the database encoding. (Another way to get the
|
||||||
|
same result is to set the <envar>PGCLIENTENCODING</envar> environment
|
||||||
|
variable to the desired dump encoding.)
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
|
<term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
|
||||||
<term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
|
<term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
|
||||||
|
@ -97,6 +97,7 @@ main(int argc, char *argv[])
|
|||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"data-only", no_argument, NULL, 'a'},
|
{"data-only", no_argument, NULL, 'a'},
|
||||||
{"clean", no_argument, NULL, 'c'},
|
{"clean", no_argument, NULL, 'c'},
|
||||||
|
{"encoding", required_argument, NULL, 'E'},
|
||||||
{"file", required_argument, NULL, 'f'},
|
{"file", required_argument, NULL, 'f'},
|
||||||
{"globals-only", no_argument, NULL, 'g'},
|
{"globals-only", no_argument, NULL, 'g'},
|
||||||
{"host", required_argument, NULL, 'h'},
|
{"host", required_argument, NULL, 'h'},
|
||||||
@ -147,6 +148,7 @@ main(int argc, char *argv[])
|
|||||||
char *pguser = NULL;
|
char *pguser = NULL;
|
||||||
char *pgdb = NULL;
|
char *pgdb = NULL;
|
||||||
char *use_role = NULL;
|
char *use_role = NULL;
|
||||||
|
const char *dumpencoding = NULL;
|
||||||
trivalue prompt_password = TRI_DEFAULT;
|
trivalue prompt_password = TRI_DEFAULT;
|
||||||
bool data_only = false;
|
bool data_only = false;
|
||||||
bool globals_only = false;
|
bool globals_only = false;
|
||||||
@ -204,7 +206,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
pgdumpopts = createPQExpBuffer();
|
pgdumpopts = createPQExpBuffer();
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "acd:f:gh:l:oOp:rsS:tU:vwWx", long_options, &optindex)) != -1)
|
while ((c = getopt_long(argc, argv, "acd:E:f:gh:l:oOp:rsS:tU:vwWx", long_options, &optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@ -221,6 +223,12 @@ main(int argc, char *argv[])
|
|||||||
connstr = pg_strdup(optarg);
|
connstr = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'E':
|
||||||
|
dumpencoding = pg_strdup(optarg);
|
||||||
|
appendPQExpBufferStr(pgdumpopts, " -E ");
|
||||||
|
appendShellString(pgdumpopts, optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
filename = pg_strdup(optarg);
|
filename = pg_strdup(optarg);
|
||||||
appendPQExpBufferStr(pgdumpopts, " -f ");
|
appendPQExpBufferStr(pgdumpopts, " -f ");
|
||||||
@ -453,6 +461,19 @@ main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
OPF = stdout;
|
OPF = stdout;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the client encoding if requested.
|
||||||
|
*/
|
||||||
|
if (dumpencoding)
|
||||||
|
{
|
||||||
|
if (PQsetClientEncoding(conn, dumpencoding) < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: invalid client encoding \"%s\" specified\n"),
|
||||||
|
progname, dumpencoding);
|
||||||
|
exit_nicely(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the active encoding and the standard_conforming_strings setting, so
|
* Get the active encoding and the standard_conforming_strings setting, so
|
||||||
* we know how to escape strings.
|
* we know how to escape strings.
|
||||||
@ -588,6 +609,7 @@ help(void)
|
|||||||
printf(_("\nOptions controlling the output content:\n"));
|
printf(_("\nOptions controlling the output content:\n"));
|
||||||
printf(_(" -a, --data-only dump only the data, not the schema\n"));
|
printf(_(" -a, --data-only dump only the data, not the schema\n"));
|
||||||
printf(_(" -c, --clean clean (drop) databases before recreating\n"));
|
printf(_(" -c, --clean clean (drop) databases before recreating\n"));
|
||||||
|
printf(_(" -E, --encoding=ENCODING dump the data in encoding ENCODING\n"));
|
||||||
printf(_(" -g, --globals-only dump only global objects, no databases\n"));
|
printf(_(" -g, --globals-only dump only global objects, no databases\n"));
|
||||||
printf(_(" -o, --oids include OIDs in dump\n"));
|
printf(_(" -o, --oids include OIDs in dump\n"));
|
||||||
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
|
printf(_(" -O, --no-owner skip restoration of object ownership\n"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user