Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 431100a

Browse files
author
Marina Polyakova
committed
ICU: PGPRO-1265: Option --add-collprovider for pg_dump[all]
This option is recommended when upgrading with pg_dump[all] and pg_restore from previous versions of Postgres Pro as well as from all versions of PostgreSQL (it's automatically used in case of a binary upgrade; and it actually does nothing for the current version of Postgres Pro). If you do not want to manually fix the scripts (or do not know how to do it correctly) this helps to avoid mess when the templated database and the created database actually use different collation providers that are ommitted. In this case the check constrains that use the default collation of the database may change and the COPY command may end with fail.
1 parent 6a3717f commit 431100a

File tree

5 files changed

+86
-13
lines changed

5 files changed

+86
-13
lines changed

doc/src/sgml/ref/pg_dump.sgml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,27 @@ doc/src/sgml/ref/pg_dump.sgml
638638
</listitem>
639639
</varlistentry>
640640

641+
<varlistentry>
642+
<term><option>--add-collprovider</option></term>
643+
<listitem>
644+
<para>
645+
This option is recommended when upgrading with
646+
<application>pg_dump</application> and
647+
<application>pg_restore</application> from previous versions of
648+
<productname>&project;</> as well as from all versions of
649+
<productname>PostgreSQL</> (it's automatically used in case of a binary
650+
upgrade; and it actually does nothing for the current version of
651+
<productname>&project;</>). If you do not want to manually fix the
652+
scripts (or do not know how to do it correctly) this helps to avoid mess
653+
when the templated database and the created database actually use
654+
different collation providers that are ommitted (see <xref
655+
linkend="collation-managing">). In this case the check constrains that
656+
use the default collation of the database may change and the
657+
<command>COPY</command> command may end with fail.
658+
</para>
659+
</listitem>
660+
</varlistentry>
661+
641662
<varlistentry>
642663
<term><option>--binary-upgrade</option></term>
643664
<listitem>

doc/src/sgml/ref/pg_dumpall.sgml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,27 @@ doc/src/sgml/ref/pg_dumpall.sgml
231231
</listitem>
232232
</varlistentry>
233233

234+
<varlistentry>
235+
<term><option>--add-collprovider</option></term>
236+
<listitem>
237+
<para>
238+
This option is recommended when upgrading with
239+
<application>pg_dumpall</application> and
240+
<application>pg_restore</application> from previous versions of
241+
<productname>&project;</> as well as from all versions of
242+
<productname>PostgreSQL</> (it's automatically used in case of a binary
243+
upgrade; and it actually does nothing for the current version of
244+
<productname>&project;</>). If you do not want to manually fix the
245+
scripts (or do not know how to do it correctly) this helps to avoid mess
246+
when the templated database and the created database actually use
247+
different collation providers that are ommitted (see <xref
248+
linkend="collation-managing">). In this case the check constrains that
249+
use the default collation of the database may change and the
250+
<command>COPY</command> command may end with fail.
251+
</para>
252+
</listitem>
253+
</varlistentry>
254+
234255
<varlistentry>
235256
<term><option>--binary-upgrade</option></term>
236257
<listitem>

src/bin/pg_dump/pg_dump.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ char g_comment_end[10];
135135

136136
static const CatalogId nilCatalogId = {0, 0};
137137

138+
/*
139+
* Whether to add the collation provider to the non-empty LC_COLLATE settings in
140+
* the database creation; always true for binary upgrade.
141+
*/
142+
static bool add_collprovider = false;
143+
138144
/*
139145
* Macro for producing quoted, schema-qualified name of a dumpable object.
140146
* Note implicit dependence on "fout"; we should get rid of that argument.
@@ -372,6 +378,7 @@ main(int argc, char **argv)
372378
{"no-unlogged-table-data", no_argument, &dopt.no_unlogged_table_data, 1},
373379
{"no-subscriptions", no_argument, &dopt.no_subscriptions, 1},
374380
{"no-sync", no_argument, NULL, 7},
381+
{"add-collprovider", no_argument, NULL, 8},
375382

376383
{NULL, 0, NULL, 0}
377384
};
@@ -556,6 +563,10 @@ main(int argc, char **argv)
556563
dosync = false;
557564
break;
558565

566+
case 8:
567+
add_collprovider = true;
568+
break;
569+
559570
default:
560571
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
561572
exit_nicely(1);
@@ -583,14 +594,18 @@ main(int argc, char **argv)
583594
if (dopt.column_inserts)
584595
dopt.dump_inserts = 1;
585596

586-
/*
587-
* Binary upgrade mode implies dumping sequence data even in schema-only
588-
* mode. This is not exposed as a separate option, but kept separate
589-
* internally for clarity.
590-
*/
591597
if (dopt.binary_upgrade)
598+
{
599+
/*
600+
* Binary upgrade mode implies dumping sequence data even in schema-only
601+
* mode. This is not exposed as a separate option, but kept separate
602+
* internally for clarity.
603+
*/
592604
dopt.sequence_data = 1;
593605

606+
add_collprovider = true;
607+
}
608+
594609
if (dopt.dataOnly && dopt.schemaOnly)
595610
{
596611
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
@@ -959,6 +974,7 @@ help(const char *progname)
959974
printf(_(" -t, --table=TABLE dump the named table(s) only\n"));
960975
printf(_(" -T, --exclude-table=TABLE do NOT dump the named table(s)\n"));
961976
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
977+
printf(_(" --add-collprovider add provider for database LC_COLLATE settings\n"));
962978
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
963979
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
964980
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
@@ -2573,7 +2589,7 @@ dumpDatabase(Archive *fout)
25732589
char *dbcollate;
25742590
appendPQExpBufferStr(creaQry, " LC_COLLATE = ");
25752591
dbcollate = pg_strdup(collate);
2576-
if (dopt->binary_upgrade)
2592+
if (add_collprovider)
25772593
dbcollate = addCollProvider(dbcollate,
25782594
fout->remoteVersion,
25792595
fout->remoteEdition,

src/bin/pg_dump/pg_dumpall.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ static char role_catalog[10];
9292
static FILE *OPF;
9393
static char *filename = NULL;
9494

95+
static int add_collprovider = 0;
96+
9597
#define exit_nicely(code) exit(code)
9698

9799
int
@@ -140,6 +142,7 @@ main(int argc, char *argv[])
140142
{"no-subscriptions", no_argument, &no_subscriptions, 1},
141143
{"no-sync", no_argument, NULL, 4},
142144
{"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1},
145+
{"add-collprovider", no_argument, &add_collprovider, 1},
143146

144147
{NULL, 0, NULL, 0}
145148
};
@@ -364,6 +367,10 @@ main(int argc, char *argv[])
364367
exit_nicely(1);
365368
}
366369

370+
/* Always add the collation provider in the binary upgrade */
371+
if (binary_upgrade)
372+
add_collprovider++;
373+
367374
/*
368375
* If password values are not required in the dump, switch to using
369376
* pg_roles which is equally useful, just more likely to have unrestricted
@@ -399,6 +406,8 @@ main(int argc, char *argv[])
399406
appendPQExpBufferStr(pgdumpopts, " --no-subscriptions");
400407
if (no_unlogged_table_data)
401408
appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
409+
if (add_collprovider)
410+
appendPQExpBufferStr(pgdumpopts, " --add-collprovider");
402411

403412
/*
404413
* If there was a database specified on the command line, use that,
@@ -596,6 +605,7 @@ help(void)
596605
printf(_(" -S, --superuser=NAME superuser user name to use in the dump\n"));
597606
printf(_(" -t, --tablespaces-only dump only tablespaces, no databases or roles\n"));
598607
printf(_(" -x, --no-privileges do not dump privileges (grant/revoke)\n"));
608+
printf(_(" --add-collprovider add provider for database LC_COLLATE settings\n"));
599609
printf(_(" --binary-upgrade for use by upgrade utilities only\n"));
600610
printf(_(" --column-inserts dump data as INSERT commands with column names\n"));
601611
printf(_(" --disable-dollar-quoting disable dollar quoting, use SQL standard quoting\n"));
@@ -1461,18 +1471,21 @@ dumpCreateDB(PGconn *conn)
14611471
appendStringLiteralConn(buf, dbencoding, conn);
14621472
}
14631473

1464-
if (default_collate && strcmp(dbcollate, default_collate) != 0)
1474+
if (default_collate && strlen(dbcollate) > 0)
14651475
{
1466-
char *dbcollate_full_name;
1467-
appendPQExpBufferStr(buf, " LC_COLLATE = ");
1468-
dbcollate_full_name = pg_strdup(dbcollate);
1469-
if (binary_upgrade)
1476+
char *dbcollate_full_name = pg_strdup(dbcollate);
1477+
1478+
if (add_collprovider)
14701479
dbcollate_full_name = addCollProvider(
14711480
dbcollate_full_name,
14721481
server_version,
14731482
server_edition,
14741483
pg_char_to_encoding(dbencoding));
1475-
appendStringLiteralConn(buf, dbcollate_full_name, conn);
1484+
if (strcmp(dbcollate_full_name, default_collate) != 0)
1485+
{
1486+
appendPQExpBufferStr(buf, " LC_COLLATE = ");
1487+
appendStringLiteralConn(buf, dbcollate_full_name, conn);
1488+
}
14761489
free(dbcollate_full_name);
14771490
}
14781491

src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"--file=$tempdir/createdb.sql",
8181
'-C',
8282
'-R', # no-op, just for testing
83+
'--add-collprovider', # no-op, just for testing
8384
'-v',
8485
'postgres', ], },
8586
data_only => {
@@ -182,7 +183,8 @@
182183
pg_dumpall_dbprivs => {
183184
dump_cmd => [
184185
'pg_dumpall', '--no-sync',
185-
"--file=$tempdir/pg_dumpall_dbprivs.sql", ], },
186+
"--file=$tempdir/pg_dumpall_dbprivs.sql",
187+
'--add-collprovider', ], }, # no-op, just for testing
186188
no_blobs => {
187189
dump_cmd => [
188190
'pg_dump', '--no-sync',

0 commit comments

Comments
 (0)