| 1 |
# Copyright (c) 2025, PostgreSQL Global Development Group |
| 2 |
|
| 3 |
# Tests for handling the default char signedness during upgrade. |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings FATAL => 'all'; |
| 7 |
|
| 8 |
use PostgreSQL::Test::Cluster; |
| 9 |
use PostgreSQL::Test::Utils; |
| 10 |
use Test::More; |
| 11 |
|
| 12 |
# Can be changed to test the other modes |
| 13 |
my $mode = $ENV{PG_TEST_PG_UPGRADE_MODE} || '--copy'; |
| 14 |
|
| 15 |
# Initialize old and new clusters |
| 16 |
my $old = PostgreSQL::Test::Cluster->new('old'); |
| 17 |
my $new = PostgreSQL::Test::Cluster->new('new'); |
| 18 |
$old->init(); |
| 19 |
$new->init(); |
| 20 |
|
| 21 |
# Check the default char signedness of both the old and the new clusters. |
| 22 |
# Newly created clusters unconditionally use 'signed'. |
| 23 |
command_like( |
| 24 |
[ 'pg_controldata', $old->data_dir ], |
| 25 |
qr/Default char data signedness:\s+signed/, |
| 26 |
'default char signedness of old cluster is signed in control file'); |
| 27 |
command_like( |
| 28 |
[ 'pg_controldata', $new->data_dir ], |
| 29 |
qr/Default char data signedness:\s+signed/, |
| 30 |
'default char signedness of new cluster is signed in control file'); |
| 31 |
|
| 32 |
# Set the old cluster's default char signedness to unsigned for test. |
| 33 |
command_ok( |
| 34 |
[ |
| 35 |
'pg_resetwal', |
| 36 |
'--char-signedness' => 'unsigned', |
| 37 |
'--force', |
| 38 |
$old->data_dir |
| 39 |
], |
| 40 |
"set old cluster's default char signedness to unsigned"); |
| 41 |
|
| 42 |
# Check if the value is successfully updated. |
| 43 |
command_like( |
| 44 |
[ 'pg_controldata', $old->data_dir ], |
| 45 |
qr/Default char data signedness:\s+unsigned/, |
| 46 |
'updated default char signedness is unsigned in control file'); |
| 47 |
|
| 48 |
# In a VPATH build, we'll be started in the source directory, but we want |
| 49 |
# to run pg_upgrade in the build directory so that any files generated finish |
| 50 |
# in it, like delete_old_cluster.{sh,bat}. |
| 51 |
chdir ${PostgreSQL::Test::Utils::tmp_check}; |
| 52 |
|
| 53 |
# Cannot use --set-char-signedness option for upgrading from v18+ |
| 54 |
command_checks_all( |
| 55 |
[ |
| 56 |
'pg_upgrade', '--no-sync', |
| 57 |
'--old-datadir' => $old->data_dir, |
| 58 |
'--new-datadir' => $new->data_dir, |
| 59 |
'--old-bindir' => $old->config_data('--bindir'), |
| 60 |
'--new-bindir' => $new->config_data('--bindir'), |
| 61 |
'--socketdir' => $new->host, |
| 62 |
'--old-port' => $old->port, |
| 63 |
'--new-port' => $new->port, |
| 64 |
'--set-char-signedness' => 'signed', |
| 65 |
$mode |
| 66 |
], |
| 67 |
1, |
| 68 |
[qr/option --set-char-signedness cannot be used/], |
| 69 |
[], |
| 70 |
'--set-char-signedness option cannot be used for upgrading from v18 or later' |
| 71 |
); |
| 72 |
|
| 73 |
# pg_upgrade should be successful. |
| 74 |
command_ok( |
| 75 |
[ |
| 76 |
'pg_upgrade', '--no-sync', |
| 77 |
'--old-datadir' => $old->data_dir, |
| 78 |
'--new-datadir' => $new->data_dir, |
| 79 |
'--old-bindir' => $old->config_data('--bindir'), |
| 80 |
'--new-bindir' => $new->config_data('--bindir'), |
| 81 |
'--socketdir' => $new->host, |
| 82 |
'--old-port' => $old->port, |
| 83 |
'--new-port' => $new->port, |
| 84 |
$mode |
| 85 |
], |
| 86 |
'run of pg_upgrade'); |
| 87 |
|
| 88 |
# Check if the default char signedness of the new cluster inherited |
| 89 |
# the old cluster's value. |
| 90 |
command_like( |
| 91 |
[ 'pg_controldata', $new->data_dir ], |
| 92 |
qr/Default char data signedness:\s+unsigned/, |
| 93 |
'the default char signedness is updated during pg_upgrade'); |
| 94 |
|
| 95 |
done_testing(); |