Skip to content

Commit 206b44b

Browse files
committed
1 parent 9637bad commit 206b44b

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

src/bin/pg_upgrade/info.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,19 @@ get_template0_info(ClusterInfo *cluster)
311311
int i_datctype;
312312
int i_daticulocale;
313313

314-
dbres = executeQueryOrDie(conn,
315-
"SELECT encoding, datlocprovider, "
316-
" datcollate, datctype, daticulocale "
317-
"FROM pg_catalog.pg_database "
318-
"WHERE datname='template0'");
314+
if (GET_MAJOR_VERSION(cluster->major_version) >= 1500)
315+
dbres = executeQueryOrDie(conn,
316+
"SELECT encoding, datlocprovider, "
317+
" datcollate, datctype, daticulocale "
318+
"FROM pg_catalog.pg_database "
319+
"WHERE datname='template0'");
320+
else
321+
dbres = executeQueryOrDie(conn,
322+
"SELECT encoding, 'c' AS datlocprovider, "
323+
" datcollate, datctype, NULL AS daticulocale "
324+
"FROM pg_catalog.pg_database "
325+
"WHERE datname='template0'");
326+
319327

320328
if (PQntuples(dbres) != 1)
321329
pg_fatal("template0 not found");

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,30 @@ set_locale_and_encoding(void)
404404
daticulocale_literal = pg_strdup("NULL");
405405

406406
/* update template0 in new cluster */
407-
PQclear(executeQueryOrDie(conn_new_template1,
408-
"UPDATE pg_catalog.pg_database "
409-
" SET encoding = %u, "
410-
" datlocprovider = '%c', "
411-
" datcollate = %s, "
412-
" datctype = %s, "
413-
" daticulocale = %s "
414-
" WHERE datname = 'template0' ",
415-
locale->db_encoding,
416-
locale->db_collprovider,
417-
datcollate_literal,
418-
datctype_literal,
419-
daticulocale_literal));
407+
if (GET_MAJOR_VERSION(new_cluster.major_version) >= 1500)
408+
PQclear(executeQueryOrDie(conn_new_template1,
409+
"UPDATE pg_catalog.pg_database "
410+
" SET encoding = %u, "
411+
" datlocprovider = '%c', "
412+
" datcollate = %s, "
413+
" datctype = %s, "
414+
" daticulocale = %s "
415+
" WHERE datname = 'template0' ",
416+
locale->db_encoding,
417+
locale->db_collprovider,
418+
datcollate_literal,
419+
datctype_literal,
420+
daticulocale_literal));
421+
else
422+
PQclear(executeQueryOrDie(conn_new_template1,
423+
"UPDATE pg_catalog.pg_database "
424+
" SET encoding = %u, "
425+
" datcollate = %s, "
426+
" datctype = %s "
427+
" WHERE datname = 'template0' ",
428+
locale->db_encoding,
429+
datcollate_literal,
430+
datctype_literal));
420431

421432
PQfreemem(datcollate_literal);
422433
PQfreemem(datctype_literal);

src/bin/pg_upgrade/t/002_pg_upgrade.pl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ sub filter_dump
110110
my $original_provider = "c";
111111
my $original_collate = "C";
112112
my $original_iculocale = "";
113+
my $provider_field = "'c' AS datlocprovider";
114+
my $iculocale_field = "NULL AS daticulocale";
113115
if ($oldnode->pg_version >= 15 && $ENV{with_icu} eq 'yes')
114116
{
117+
$provider_field = "datlocprovider";
118+
$iculocale_field = "daticulocale";
115119
$original_provider = "i";
116120
$original_iculocale = "fr-CA";
117121
}
@@ -132,8 +136,8 @@ sub filter_dump
132136

133137
my $result;
134138
$result = $oldnode->safe_psql(
135-
'postgres', q{SELECT encoding, datlocprovider, datcollate, daticulocale
136-
FROM pg_database WHERE datname='template0'});
139+
'postgres', "SELECT encoding, $provider_field, datcollate, $iculocale_field
140+
FROM pg_database WHERE datname='template0'");
137141
is($result, "$original_encoding|$original_provider|$original_collate|$original_iculocale",
138142
"check locales in original cluster"
139143
);
@@ -395,8 +399,8 @@ sub filter_dump
395399

396400
# Test that upgraded cluster has original locale settings.
397401
$result = $newnode->safe_psql(
398-
'postgres', q{SELECT encoding, datlocprovider, datcollate, datctype, daticulocale
399-
FROM pg_database WHERE datname='template0'});
402+
'postgres', "SELECT encoding, $provider_field, datcollate, datctype, $iculocale_field
403+
FROM pg_database WHERE datname='template0'");
400404
is($result, "$original_encoding|$original_provider|$original_collate|$original_ctype|$original_iculocale",
401405
"check that locales in new cluster match original cluster"
402406
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy