aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2023-08-22 11:21:36 -0700
committerJeff Davis <jdavis@postgresql.org>2023-08-22 12:49:17 -0700
commit1d9976d1bd0067099753820c427139696d38b4a1 (patch)
treef04a1eef853289b9ef35e307e9106e918296a49b /src
parent75f323aa1c1ec88f9781cb6d9307e42b820b26f0 (diff)
downloadpostgresql-1d9976d1bd0067099753820c427139696d38b4a1.tar.gz
postgresql-1d9976d1bd0067099753820c427139696d38b4a1.zip
Fix pg_dump assertion failure when dumping pg_catalog.
Commit 396d348b04 did not account for the default collation. Also, use pg_log_warning() instead of Assert(). Discussion: https://postgr.es/m/ce071503fee88334aa70f360e6e4ea14d48305ee.camel%40j-davis.com Reviewed-by: Michael Paquier Backpatch-through: 15
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_dump/pg_dump.c57
-rw-r--r--src/bin/pg_dump/t/002_pg_dump.pl8
2 files changed, 55 insertions, 10 deletions
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 2a64d26e407..cb6d8d1bb09 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -13258,6 +13258,18 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
else
collctype = NULL;
+ /*
+ * Before version 15, collcollate and collctype were of type NAME and
+ * non-nullable. Treat empty strings as NULL for consistency.
+ */
+ if (fout->remoteVersion < 150000)
+ {
+ if (collcollate[0] == '\0')
+ collcollate = NULL;
+ if (collctype[0] == '\0')
+ collctype = NULL;
+ }
+
if (!PQgetisnull(res, 0, i_colliculocale))
colliculocale = PQgetvalue(res, 0, i_colliculocale);
else
@@ -13284,29 +13296,54 @@ dumpCollation(Archive *fout, const CollInfo *collinfo)
if (strcmp(PQgetvalue(res, 0, i_collisdeterministic), "f") == 0)
appendPQExpBufferStr(q, ", deterministic = false");
- if (colliculocale != NULL)
+ if (collprovider[0] == 'd')
{
- appendPQExpBufferStr(q, ", locale = ");
- appendStringLiteralAH(q, colliculocale, fout);
+ if (collcollate || collctype || colliculocale)
+ pg_log_warning("invalid collation \"%s\"", qcollname);
+
+ /* no locale -- the default collation cannot be reloaded anyway */
}
- else
+ else if (collprovider[0] == 'i')
{
- Assert(collcollate != NULL);
- Assert(collctype != NULL);
+ if (fout->remoteVersion >= 150000)
+ {
+ if (collcollate || collctype || !colliculocale)
+ pg_log_warning("invalid collation \"%s\"", qcollname);
- if (strcmp(collcollate, collctype) == 0)
+ appendPQExpBufferStr(q, ", locale = ");
+ appendStringLiteralAH(q, colliculocale ? colliculocale : "",
+ fout);
+ }
+ else
+ {
+ if (!collcollate || !collctype || colliculocale ||
+ strcmp(collcollate, collctype) != 0)
+ pg_log_warning("invalid collation \"%s\"", qcollname);
+
+ appendPQExpBufferStr(q, ", locale = ");
+ appendStringLiteralAH(q, collcollate ? collcollate : "", fout);
+ }
+ }
+ else if (collprovider[0] == 'c')
+ {
+ if (colliculocale || !collcollate || !collctype)
+ pg_log_warning("invalid collation \"%s\"", qcollname);
+
+ if (collcollate && collctype && strcmp(collcollate, collctype) == 0)
{
appendPQExpBufferStr(q, ", locale = ");
- appendStringLiteralAH(q, collcollate, fout);
+ appendStringLiteralAH(q, collcollate ? collcollate : "", fout);
}
else
{
appendPQExpBufferStr(q, ", lc_collate = ");
- appendStringLiteralAH(q, collcollate, fout);
+ appendStringLiteralAH(q, collcollate ? collcollate : "", fout);
appendPQExpBufferStr(q, ", lc_ctype = ");
- appendStringLiteralAH(q, collctype, fout);
+ appendStringLiteralAH(q, collctype ? collctype : "", fout);
}
}
+ else
+ pg_fatal("unrecognized collation provider '%c'", collprovider[0]);
/*
* For binary upgrade, carry over the collation version. For normal
diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 32c3e066666..0d32882dfce 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -4091,6 +4091,14 @@ $node->command_fails_like(
qr/pg_dumpall: error: improper qualified name \(too many dotted names\): myhost\.mydb/,
'pg_dumpall: option --exclude-database rejects multipart database names');
+##############################################################
+# Test dumping pg_catalog (for research -- cannot be reloaded)
+
+$node->command_ok(
+ [ 'pg_dump', '-p', "$port", '-n', 'pg_catalog' ],
+ 'pg_dump: option -n pg_catalog'
+);
+
#########################################
# Test valid database exclusion patterns