Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b44818

Browse files
committed
In pg_upgrade, check that the binary and data directories are the same
major version.Backpatch to 9.1.Dan McGee
1 parent3b3c2cf commit0b44818

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static void check_for_prepared_transactions(ClusterInfo *cluster);
2020
staticvoidcheck_for_isn_and_int8_passing_mismatch(ClusterInfo*cluster);
2121
staticvoidcheck_for_reg_data_type_usage(ClusterInfo*cluster);
2222
staticvoidcheck_for_support_lib(ClusterInfo*cluster);
23+
staticvoidget_bin_version(ClusterInfo*cluster);
2324

2425

2526
void
@@ -216,6 +217,8 @@ output_completion_banner(char *deletion_script_file_name)
216217
void
217218
check_cluster_versions(void)
218219
{
220+
prep_status("Checking cluster versions");
221+
219222
/* get old and new cluster versions */
220223
old_cluster.major_version=get_major_server_version(&old_cluster);
221224
new_cluster.major_version=get_major_server_version(&new_cluster);
@@ -235,10 +238,26 @@ check_cluster_versions(void)
235238

236239
/*
237240
* We can't allow downgrading because we use the target pg_dumpall, and
238-
* pg_dumpall cannot operate on newdatbase versions, only older versions.
241+
* pg_dumpall cannot operate on newdatabase versions, only older versions.
239242
*/
240243
if (old_cluster.major_version>new_cluster.major_version)
241244
pg_log(PG_FATAL,"This utility cannot be used to downgrade to older major PostgreSQL versions.\n");
245+
246+
/* get old and new binary versions */
247+
get_bin_version(&old_cluster);
248+
get_bin_version(&new_cluster);
249+
250+
/* Ensure binaries match the designated data directories */
251+
if (GET_MAJOR_VERSION(old_cluster.major_version)!=
252+
GET_MAJOR_VERSION(old_cluster.bin_version))
253+
pg_log(PG_FATAL,
254+
"Old cluster data and binary directories are from different major versions.\n");
255+
if (GET_MAJOR_VERSION(new_cluster.major_version)!=
256+
GET_MAJOR_VERSION(new_cluster.bin_version))
257+
pg_log(PG_FATAL,
258+
"New cluster data and binary directories are from different major versions.\n");
259+
260+
check_ok();
242261
}
243262

244263

@@ -754,3 +773,32 @@ check_for_support_lib(ClusterInfo *cluster)
754773

755774
fclose(lib_test);
756775
}
776+
777+
778+
staticvoid
779+
get_bin_version(ClusterInfo*cluster)
780+
{
781+
charcmd[MAXPGPATH],cmd_output[MAX_STRING];
782+
FILE*output;
783+
intpre_dot,post_dot;
784+
785+
snprintf(cmd,sizeof(cmd),"\"%s/pg_ctl\" --version",cluster->bindir);
786+
787+
if ((output=popen(cmd,"r"))==NULL)
788+
pg_log(PG_FATAL,"Could not get pg_ctl version data: %s\n",
789+
getErrorText(errno));
790+
791+
fgets(cmd_output,sizeof(cmd_output),output);
792+
793+
pclose(output);
794+
795+
/* Remove trailing newline */
796+
if (strchr(cmd_output,'\n')!=NULL)
797+
*strchr(cmd_output,'\n')='\0';
798+
799+
if (sscanf(cmd_output,"%*s %*s %d.%d",&pre_dot,&post_dot)!=2)
800+
pg_log(PG_FATAL,"could not get version from %s\n",cmd);
801+
802+
cluster->bin_version= (pre_dot*100+post_dot)*100;
803+
}
804+

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ typedef struct
184184
unsigned shortport;/* port number where postmaster is waiting */
185185
uint32major_version;/* PG_VERSION of cluster */
186186
charmajor_version_str[64];/* string PG_VERSION of cluster */
187+
uint32bin_version;/* version returned from pg_ctl */
187188
Oidpg_database_oid;/* OID of pg_database relation */
188189
char*tablespace_suffix;/* directory specification */
189190
}ClusterInfo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp