Skip to content

Commit 30666d1

Browse files
pg_resetwal: Add --char-signedness option to change the default char signedness.
With the newly added option --char-signedness, pg_resetwal updates the default char signedness flag in the controlfile. This option is primarily intended for an upcoming patch that pg_upgrade supports preserving the default char signedness during upgrades, and is not meant for manual operation. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/CB11ADBC-0C3F-4FE0-A678-666EE80CBB07%40amazon.com
1 parent 44fe30f commit 30666d1

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

doc/src/sgml/ref/pg_resetwal.sgml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ PostgreSQL documentation
171171
</para>
172172

173173
<variablelist>
174+
<varlistentry>
175+
<term><option>--char-signedness=<replaceable class="parameter">option</replaceable></option></term>
176+
<listitem>
177+
<para>
178+
Manually set the default char signedness. Possible values are
179+
<literal>signed</literal> and <literal>unsigned</literal>.
180+
</para>
181+
<para>
182+
For a database cluster that <command>pg_upgrade</command> upgraded from
183+
a <productname>PostgreSQL</productname> version before 18, the safe
184+
value would be the default <type>char</type> signedness of the platform
185+
that ran the cluster before that upgrade. For all other
186+
clusters, <literal>signed</literal> would be the safe value. However,
187+
this option is exclusively for use with <command>pg_upgrade</command>
188+
and should not normally be used manually.
189+
</para>
190+
</listitem>
191+
</varlistentry>
192+
174193
<varlistentry>
175194
<term><option>-c <replaceable class="parameter">xid</replaceable>,<replaceable class="parameter">xid</replaceable></option></term>
176195
<term><option>--commit-timestamp-ids=<replaceable class="parameter">xid</replaceable>,<replaceable class="parameter">xid</replaceable></option></term>

src/bin/pg_resetwal/pg_resetwal.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static TimeLineID minXlogTli = 0;
7575
static XLogSegNo minXlogSegNo = 0;
7676
static int WalSegSz;
7777
static int set_wal_segsize;
78+
static int set_char_signedness = -1;
7879

7980
static void CheckDataVersion(void);
8081
static bool read_controlfile(void);
@@ -106,6 +107,7 @@ main(int argc, char *argv[])
106107
{"oldest-transaction-id", required_argument, NULL, 'u'},
107108
{"next-transaction-id", required_argument, NULL, 'x'},
108109
{"wal-segsize", required_argument, NULL, 1},
110+
{"char-signedness", required_argument, NULL, 2},
109111
{NULL, 0, NULL, 0}
110112
};
111113

@@ -302,6 +304,23 @@ main(int argc, char *argv[])
302304
break;
303305
}
304306

307+
case 2:
308+
{
309+
errno = 0;
310+
311+
if (pg_strcasecmp(optarg, "signed") == 0)
312+
set_char_signedness = 1;
313+
else if (pg_strcasecmp(optarg, "unsigned") == 0)
314+
set_char_signedness = 0;
315+
else
316+
{
317+
pg_log_error("invalid argument for option %s", "--char-signedness");
318+
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
319+
exit(1);
320+
}
321+
break;
322+
}
323+
305324
default:
306325
/* getopt_long already emitted a complaint */
307326
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -456,6 +475,9 @@ main(int argc, char *argv[])
456475
if (set_wal_segsize != 0)
457476
ControlFile.xlog_seg_size = WalSegSz;
458477

478+
if (set_char_signedness != -1)
479+
ControlFile.default_char_signedness = (set_char_signedness == 1);
480+
459481
if (minXlogSegNo > newXlogSegNo)
460482
newXlogSegNo = minXlogSegNo;
461483

@@ -779,6 +801,8 @@ PrintControlValues(bool guessed)
779801
(ControlFile.float8ByVal ? _("by value") : _("by reference")));
780802
printf(_("Data page checksum version: %u\n"),
781803
ControlFile.data_checksum_version);
804+
printf(_("Default char data signedness: %s\n"),
805+
(ControlFile.default_char_signedness ? _("signed") : _("unsigned")));
782806
}
783807

784808

@@ -1188,6 +1212,7 @@ usage(void)
11881212
printf(_(" -O, --multixact-offset=OFFSET set next multitransaction offset\n"));
11891213
printf(_(" -u, --oldest-transaction-id=XID set oldest transaction ID\n"));
11901214
printf(_(" -x, --next-transaction-id=XID set next transaction ID\n"));
1215+
printf(_(" --char-signedness=OPTION set char signedness to \"signed\" or \"unsigned\"\n"));
11911216
printf(_(" --wal-segsize=SIZE size of WAL segments, in megabytes\n"));
11921217

11931218
printf(_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);

src/bin/pg_resetwal/t/001_basic.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
qr/must be greater than/,
174174
'fails with -x value too small');
175175

176+
# --char-signedness
177+
command_fails_like(
178+
[ 'pg_resetwal', '--char-signedness', 'foo', $node->data_dir ],
179+
qr/error: invalid argument for option --char-signedness/,
180+
'fails with incorrect --char-signedness option');
181+
176182
# run with control override options
177183

178184
my $out = (run_command([ 'pg_resetwal', '--dry-run', $node->data_dir ]))[0];

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