Skip to content

Commit 3d5ffcc

Browse files
committed
Add option -N/--no-sync to pg_upgrade
This is an option consistent with what the other tools of src/bin/ (pg_checksums, pg_dump, pg_rewind and pg_basebackup) provide which is useful for leveraging the I/O effort when testing things. This is not to be used in a production environment. All the regression tests of pg_upgrade are updated to use this new option. This happens to cut at most a couple of seconds in environments constrained on I/O, by avoiding a flush of data folder for the new cluster upgraded. Author: Michael Paquier Reviewed-by: Peter Eisentraut Discussion: https://postgr.es/m/YbrhzuBmBxS/DkfX@paquier.xyz
1 parent 944dc45 commit 3d5ffcc

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

doc/src/sgml/ref/pgupgrade.sgml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ PostgreSQL documentation
130130
cluster</para></listitem>
131131
</varlistentry>
132132

133+
<varlistentry>
134+
<term><option>-N</option></term>
135+
<term><option>--no-sync</option></term>
136+
<listitem>
137+
<para>
138+
By default, <command>pg_upgrade</command> will wait for all files
139+
of the upgraded cluster to be written safely to disk. This option
140+
causes <command>pg_upgrade</command> to return without waiting, which
141+
is faster, but means that a subsequent operating system crash can leave
142+
the synchronized data directory corrupt. Generally, this option is
143+
useful for testing but should not be used on a production
144+
installation.
145+
</para>
146+
</listitem>
147+
</varlistentry>
148+
133149
<varlistentry>
134150
<term><option>-o</option> <replaceable class="parameter">options</replaceable></term>
135151
<term><option>--old-options</option> <replaceable class="parameter">options</replaceable></term>

src/bin/pg_upgrade/option.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ parseCommandLine(int argc, char *argv[])
4343
{"new-datadir", required_argument, NULL, 'D'},
4444
{"old-bindir", required_argument, NULL, 'b'},
4545
{"new-bindir", required_argument, NULL, 'B'},
46+
{"no-sync", no_argument, NULL, 'N'},
4647
{"old-options", required_argument, NULL, 'o'},
4748
{"new-options", required_argument, NULL, 'O'},
4849
{"old-port", required_argument, NULL, 'p'},
@@ -66,6 +67,7 @@ parseCommandLine(int argc, char *argv[])
6667
char **filename;
6768
time_t run_time = time(NULL);
6869

70+
user_opts.do_sync = true;
6971
user_opts.transfer_mode = TRANSFER_MODE_COPY;
7072

7173
os_info.progname = get_progname(argv[0]);
@@ -101,7 +103,7 @@ parseCommandLine(int argc, char *argv[])
101103
if (os_user_effective_id == 0)
102104
pg_fatal("%s: cannot be run as root\n", os_info.progname);
103105

104-
while ((option = getopt_long(argc, argv, "d:D:b:B:cj:ko:O:p:P:rs:U:v",
106+
while ((option = getopt_long(argc, argv, "d:D:b:B:cj:kNo:O:p:P:rs:U:v",
105107
long_options, &optindex)) != -1)
106108
{
107109
switch (option)
@@ -134,6 +136,10 @@ parseCommandLine(int argc, char *argv[])
134136
user_opts.transfer_mode = TRANSFER_MODE_LINK;
135137
break;
136138

139+
case 'N':
140+
user_opts.do_sync = false;
141+
break;
142+
137143
case 'o':
138144
/* append option? */
139145
if (!old_cluster.pgopts)
@@ -286,6 +292,7 @@ usage(void)
286292
printf(_(" -D, --new-datadir=DATADIR new cluster data directory\n"));
287293
printf(_(" -j, --jobs=NUM number of simultaneous processes or threads to use\n"));
288294
printf(_(" -k, --link link instead of copying files to new cluster\n"));
295+
printf(_(" -N, --no-sync do not wait for changes to be written safely to disk\n"));
289296
printf(_(" -o, --old-options=OPTIONS old cluster options to pass to the server\n"));
290297
printf(_(" -O, --new-options=OPTIONS new cluster options to pass to the server\n"));
291298
printf(_(" -p, --old-port=PORT old cluster port number (default %d)\n"), old_cluster.port);

src/bin/pg_upgrade/pg_upgrade.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ main(int argc, char **argv)
169169
new_cluster.pgdata);
170170
check_ok();
171171

172-
prep_status("Sync data directory to disk");
173-
exec_prog(UTILITY_LOG_FILE, NULL, true, true,
174-
"\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir,
175-
new_cluster.pgdata);
176-
check_ok();
172+
if (user_opts.do_sync)
173+
{
174+
prep_status("Sync data directory to disk");
175+
exec_prog(UTILITY_LOG_FILE, NULL, true, true,
176+
"\"%s/initdb\" --sync-only \"%s\"", new_cluster.bindir,
177+
new_cluster.pgdata);
178+
check_ok();
179+
}
177180

178181
create_script_for_old_cluster_deletion(&deletion_script_file_name);
179182

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ typedef struct
279279
{
280280
bool check; /* true -> ask user for permission to make
281281
* changes */
282+
bool do_sync; /* flush changes to disk */
282283
transferMode transfer_mode; /* copy files or link them? */
283284
int jobs; /* number of processes/threads to use */
284285
char *socketdir; /* directory to use for Unix sockets */

src/bin/pg_upgrade/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ PGDATA="$BASE_PGDATA"
233233

234234
standard_initdb 'initdb'
235235

236-
pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir" -p "$PGPORT" -P "$PGPORT"
236+
pg_upgrade $PG_UPGRADE_OPTS --no-sync -d "${PGDATA}.old" -D "$PGDATA" -b "$oldbindir" -p "$PGPORT" -P "$PGPORT"
237237

238238
# make sure all directories and files have group permissions, on Unix hosts
239239
# Windows hosts don't support Unix-y permissions.

src/tools/msvc/vcregress.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ sub upgradecheck
648648
print "\nSetting up new cluster\n\n";
649649
standard_initdb() or exit 1;
650650
print "\nRunning pg_upgrade\n\n";
651-
@args = ('pg_upgrade', '-d', "$data.old", '-D', $data, '-b', $bindir);
651+
@args = (
652+
'pg_upgrade', '-d', "$data.old", '-D', $data, '-b', $bindir,
653+
'--no-sync');
652654
system(@args) == 0 or exit 1;
653655
print "\nStarting new cluster\n\n";
654656
@args = ('pg_ctl', '-l', "$logdir/postmaster2.log", 'start');

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