From 4b02e935fee881eab1f4fabdbebccedfa57b4ddd Mon Sep 17 00:00:00 2001 From: Tom Lane <tgl@sss.pgh.pa.us> Date: Thu, 16 Nov 2017 11:16:53 -0500 Subject: [PATCH] Fix bogus logic for checking data dirs' versions within pg_upgrade. Commit 9be95ef15 failed to cure all of the redundancy here: we were actually calling get_major_server_version() three times for each of the old and new data directories. While that's not enormously expensive, it's still sloppy. A. Akenteva Discussion: https://postgr.es/m/f9266a85d918a3cf3a386b5148aee666@postgrespro.ru --- src/bin/pg_upgrade/check.c | 6 +++--- src/bin/pg_upgrade/exec.c | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index b7e1e4be190..1b9083597ca 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -234,9 +234,9 @@ check_cluster_versions(void) { prep_status("Checking cluster versions"); - /* get old and new cluster versions */ - old_cluster.major_version = get_major_server_version(&old_cluster); - new_cluster.major_version = get_major_server_version(&new_cluster); + /* cluster versions should already have been obtained */ + Assert(old_cluster.major_version != 0); + Assert(new_cluster.major_version != 0); /* * We allow upgrades from/to the same major version for alpha/beta diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 810a5a0c3c5..f5cd74ff97f 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -331,9 +331,8 @@ check_data_dir(ClusterInfo *cluster) { const char *pg_data = cluster->pgdata; - /* get old and new cluster versions */ - old_cluster.major_version = get_major_server_version(&old_cluster); - new_cluster.major_version = get_major_server_version(&new_cluster); + /* get the cluster version */ + cluster->major_version = get_major_server_version(cluster); check_single_dir(pg_data, ""); check_single_dir(pg_data, "base"); -- GitLab