@@ -48,7 +48,7 @@ static void prepare_new_databases(void);
48
48
static void create_new_objects (void );
49
49
static void copy_clog_xlog_xid (void );
50
50
static void set_frozenxids (void );
51
- static void setup (char * argv0 , bool live_check );
51
+ static void setup (char * argv0 , bool * live_check );
52
52
static void cleanup (void );
53
53
54
54
ClusterInfo old_cluster ,
@@ -80,9 +80,9 @@ main(int argc, char **argv)
80
80
adjust_data_dir (& old_cluster );
81
81
adjust_data_dir (& new_cluster );
82
82
83
- output_check_banner ( & live_check );
83
+ setup ( argv [ 0 ], & live_check );
84
84
85
- setup ( argv [ 0 ], live_check );
85
+ output_check_banner ( live_check );
86
86
87
87
check_cluster_versions ();
88
88
@@ -95,7 +95,7 @@ main(int argc, char **argv)
95
95
96
96
97
97
/* -- NEW -- */
98
- start_postmaster (& new_cluster );
98
+ start_postmaster (& new_cluster , true );
99
99
100
100
check_new_cluster ();
101
101
report_clusters_compatible ();
@@ -116,7 +116,7 @@ main(int argc, char **argv)
116
116
/* New now using xids of the old system */
117
117
118
118
/* -- NEW -- */
119
- start_postmaster (& new_cluster );
119
+ start_postmaster (& new_cluster , true );
120
120
121
121
prepare_new_databases ();
122
122
@@ -177,7 +177,7 @@ main(int argc, char **argv)
177
177
178
178
179
179
static void
180
- setup (char * argv0 , bool live_check )
180
+ setup (char * argv0 , bool * live_check )
181
181
{
182
182
char exec_path [MAXPGPATH ]; /* full path to my executable */
183
183
@@ -189,15 +189,39 @@ setup(char *argv0, bool live_check)
189
189
190
190
verify_directories ();
191
191
192
- /* no postmasters should be running */
193
- if (!live_check && is_server_running (old_cluster .pgdata ))
194
- pg_log (PG_FATAL , "There seems to be a postmaster servicing the old cluster.\n"
195
- "Please shutdown that postmaster and try again.\n" );
192
+ /* no postmasters should be running, except for a live check */
193
+ if (pid_lock_file_exists (old_cluster .pgdata ))
194
+ {
195
+ /*
196
+ * If we have a postmaster.pid file, try to start the server. If
197
+ * it starts, the pid file was stale, so stop the server. If it
198
+ * doesn't start, assume the server is running. If the pid file
199
+ * is left over from a server crash, this also allows any committed
200
+ * transactions stored in the WAL to be replayed so they are not
201
+ * lost, because WAL files are not transfered from old to new
202
+ * servers.
203
+ */
204
+ if (start_postmaster (& old_cluster , false))
205
+ stop_postmaster (false);
206
+ else
207
+ {
208
+ if (!user_opts .check )
209
+ pg_log (PG_FATAL , "There seems to be a postmaster servicing the old cluster.\n"
210
+ "Please shutdown that postmaster and try again.\n" );
211
+ else
212
+ * live_check = true;
213
+ }
214
+ }
196
215
197
216
/* same goes for the new postmaster */
198
- if (is_server_running (new_cluster .pgdata ))
199
- pg_log (PG_FATAL , "There seems to be a postmaster servicing the new cluster.\n"
217
+ if (pid_lock_file_exists (new_cluster .pgdata ))
218
+ {
219
+ if (start_postmaster (& new_cluster , false))
220
+ stop_postmaster (false);
221
+ else
222
+ pg_log (PG_FATAL , "There seems to be a postmaster servicing the new cluster.\n"
200
223
"Please shutdown that postmaster and try again.\n" );
224
+ }
201
225
202
226
/* get path to pg_upgrade executable */
203
227
if (find_my_exec (argv0 , exec_path ) < 0 )
0 commit comments