Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2127aac

Browse files
committed
In pg_upgrade, only lock the old cluster if link mode is used, and do it
right after we restore the schema (a common failure point), and right before we do the link operation. Per suggesgtions from Robert and ^!C^!^@Lvaro
1 parent 6b28994 commit 2127aac

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

contrib/pg_upgrade/check.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ report_clusters_compatible(void)
148148
}
149149

150150
pg_log(PG_REPORT, "\n"
151-
"If pg_upgrade fails after this point, you must re-initdb the new cluster\n"
152-
"before continuing. You will also need to remove the \".old\" suffix from\n"
153-
"%s/global/pg_control.old.\n", old_cluster.pgdata);
151+
"If pg_upgrade fails after this point, you must re-initdb the\n"
152+
"new cluster before continuing.\n");
154153
}
155154

156155

@@ -198,8 +197,8 @@ output_completion_banner(char *deletion_script_file_name)
198197
/* Did we copy the free space files? */
199198
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
200199
pg_log(PG_REPORT,
201-
"Optimizer statistics are not transferred by pg_upgrade so consider\n"
202-
"running:\n"
200+
"Optimizer statistics are not transferred by pg_upgrade so\n"
201+
"consider running:\n"
203202
" vacuumdb --all --analyze-only\n"
204203
"on the newly-upgraded cluster.\n\n");
205204
else

contrib/pg_upgrade/controldata.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,23 @@ check_control_data(ControlData *oldctrl,
516516

517517

518518
void
519-
rename_old_pg_control(void)
519+
disable_old_cluster(void)
520520
{
521521
char old_path[MAXPGPATH],
522522
new_path[MAXPGPATH];
523523

524+
/* rename pg_control so old server cannot be accidentally started */
524525
prep_status("Adding \".old\" suffix to old global/pg_control");
525526

526527
snprintf(old_path, sizeof(old_path), "%s/global/pg_control", old_cluster.pgdata);
527528
snprintf(new_path, sizeof(new_path), "%s/global/pg_control.old", old_cluster.pgdata);
528529
if (pg_mv_file(old_path, new_path) != 0)
529530
pg_log(PG_FATAL, "Unable to rename %s to %s.\n", old_path, new_path);
530531
check_ok();
532+
533+
pg_log(PG_REPORT, "\n"
534+
"If you want to start the old cluster, you will need to remove\n"
535+
"the \".old\" suffix from %s/global/pg_control.old.\n"
536+
"Because \"link\" mode was used, the old cluster cannot be safely\n"
537+
"started once the new cluster has been started.\n\n", old_cluster.pgdata);
531538
}

contrib/pg_upgrade/pg_upgrade.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <langinfo.h>
4444
#endif
4545

46-
static void disable_old_cluster(void);
4746
static void prepare_new_cluster(void);
4847
static void prepare_new_databases(void);
4948
static void create_new_objects(void);
@@ -87,7 +86,6 @@ main(int argc, char **argv)
8786
pg_log(PG_REPORT, "\nPerforming Upgrade\n");
8887
pg_log(PG_REPORT, "------------------\n");
8988

90-
disable_old_cluster();
9189
prepare_new_cluster();
9290

9391
stop_postmaster(false);
@@ -109,6 +107,16 @@ main(int argc, char **argv)
109107

110108
stop_postmaster(false);
111109

110+
/*
111+
* Most failures happen in create_new_objects(), which has
112+
* completed at this point. We do this here because it is just
113+
* before linking, which will link the old and new cluster data
114+
* files, preventing the old cluster from being safely started
115+
* once the new cluster is started.
116+
*/
117+
if (user_opts.transfer_mode == TRANSFER_MODE_LINK)
118+
disable_old_cluster();
119+
112120
transfer_all_new_dbs(&old_cluster.dbarr, &new_cluster.dbarr,
113121
old_cluster.pgdata, new_cluster.pgdata);
114122

@@ -176,14 +184,6 @@ setup(char *argv0, bool live_check)
176184
}
177185

178186

179-
static void
180-
disable_old_cluster(void)
181-
{
182-
/* rename pg_control so old server cannot be accidentally started */
183-
rename_old_pg_control();
184-
}
185-
186-
187187
static void
188188
prepare_new_cluster(void)
189189
{

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ void create_script_for_old_cluster_deletion(char **deletion_script_file_name);
282282
/* controldata.c */
283283

284284
void get_control_data(ClusterInfo *cluster, bool live_check);
285-
void check_control_data(ControlData *oldctrl,
286-
ControlData *newctrl);
285+
void check_control_data(ControlData *oldctrl, ControlData *newctrl);
286+
void disable_old_cluster(void);
287287

288288

289289
/* dump.c */
@@ -298,7 +298,6 @@ int exec_prog(bool throw_error, const char *cmd, ...)
298298
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
299299
void verify_directories(void);
300300
bool is_server_running(const char *datadir);
301-
void rename_old_pg_control(void);
302301

303302

304303
/* file.c */

doc/src/sgml/pgupgrade.sgml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182

183183
<para>
184184
If you are using a version-specific installation directory, e.g.
185-
<filename>/opt/PostgreSQL/8.4</>, you do not need to move the old cluster. The
185+
<filename>/opt/PostgreSQL/9.1</>, you do not need to move the old cluster. The
186186
one-click installers all use version-specific installation directories.
187187
</para>
188188

@@ -254,7 +254,8 @@ gmake prefix=/usr/local/pgsql.new install
254254

255255
<para>
256256
Install any custom shared object files (or DLLs) used by the old cluster
257-
into the new cluster, e.g. <filename>pgcrypto.so</filename>, whether they are from <filename>contrib</filename>
257+
into the new cluster, e.g. <filename>pgcrypto.so</filename>,
258+
whether they are from <filename>contrib</filename>
258259
or some other source. Do not install the schema definitions, e.g.
259260
<filename>pgcrypto.sql</>, because these will be upgraded from the old cluster.
260261
</para>
@@ -454,18 +455,14 @@ psql --username postgres --file script.sql postgres
454455

455456
<listitem>
456457
<para>
457-
If you
458-
ran <command>pg_upgrade</command> <emphasis>without</> <option>--link</>
459-
or did not start the new server, the old cluster was not
460-
modified except that an <literal>.old</> suffix was appended
461-
to <filename>$PGDATA/global/pg_control</> and perhaps
462-
tablespace directories. To reuse the old cluster, remove
463-
the <filename>.old</> suffix
464-
from <filename>$PGDATA/global/pg_control</>. and, if upgrading
465-
to 8.4 or earlier, remove the tablespace directories created
466-
by the upgrade and remove the <filename>.old</> suffix from
467-
the tablespace directory names; then you can restart the old
468-
cluster.
458+
If you ran <command>pg_upgrade</command> <emphasis>without</>
459+
<option>--link</> or did not start the new server, the
460+
old cluster was not modified except that, if linking
461+
started, a <literal>.old</> suffix was appended to
462+
<filename>$PGDATA/global/pg_control</>. To reuse the old
463+
cluster, possibly remove the <filename>.old</> suffix from
464+
<filename>$PGDATA/global/pg_control</>; you can then restart the
465+
old cluster.
469466
</para>
470467
</listitem>
471468
</itemizedlist>
@@ -582,9 +579,9 @@ psql --username postgres --file script.sql postgres
582579
</para>
583580

584581
<para>
585-
If you want to use link mode and you don't want your old cluster
582+
If you want to use link mode and you do not want your old cluster
586583
to be modified when the new cluster is started, make a copy of the
587-
old cluster and upgrade that with link mode. To make a valid copy
584+
old cluster and upgrade that in link mode. To make a valid copy
588585
of the old cluster, use <command>rsync</> to create a dirty
589586
copy of the old cluster while the server is running, then shut down
590587
the old server and run <command>rsync</> again to update the copy with any

0 commit comments

Comments
 (0)