diff options
author | Nathan Bossart <nathan@postgresql.org> | 2024-07-24 11:30:33 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2024-07-24 11:30:33 -0500 |
commit | 73de50e13e397da8e98ed59b0fe63a00051a7128 (patch) | |
tree | ef34c122c984b734c87976235b2e1715ee46d65e /src/bin/pg_upgrade/check.c | |
parent | 0cc57dca298c86403b6d6bb647f99d542f9d3dca (diff) | |
download | postgresql-73de50e13e397da8e98ed59b0fe63a00051a7128.tar.gz postgresql-73de50e13e397da8e98ed59b0fe63a00051a7128.zip |
pg_upgrade: Retrieve subscription count more efficiently.
Presently, pg_upgrade obtains the number of subscriptions in the
to-be-upgraded cluster by first querying pg_subscription in every
database for the number of subscriptions in only that database.
Then, in count_old_cluster_subscriptions(), it adds all the values
collected in the first step. This is expensive, especially when
there are many databases.
Fortunately, there is a better way to retrieve the subscription
count. Since pg_subscription is a shared catalog, we only need to
connect to a single database and query it once. This commit
modifies pg_upgrade to use that approach, which also allows us to
trim several lines of code. In passing, move the call to
get_db_subscription_count(), which has been renamed to
get_subscription_count(), from get_db_rel_and_slot_infos() to the
dedicated >= v17 section in check_and_dump_old_cluster().
We may be able to make similar improvements to
get_old_cluster_logical_slot_infos(), but that is left as a future
exercise.
Reviewed-by: Michael Paquier, Amit Kapila
Discussion: https://postgr.es/m/ZprQJv_TxccN3tkr%40nathan
Backpatch-through: 17
Diffstat (limited to 'src/bin/pg_upgrade/check.c')
-rw-r--r-- | src/bin/pg_upgrade/check.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 27924159d67..51e30a2f239 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -609,8 +609,10 @@ check_and_dump_old_cluster(bool live_check) /* * Subscriptions and their dependencies can be migrated since PG17. - * See comments atop get_db_subscription_count(). + * Before that the logical slots are not upgraded, so we will not be + * able to upgrade the logical replication clusters completely. */ + get_subscription_count(&old_cluster); check_old_cluster_subscription_state(); } @@ -1797,17 +1799,14 @@ check_new_cluster_subscription_configuration(void) { PGresult *res; PGconn *conn; - int nsubs_on_old; int max_replication_slots; /* Subscriptions and their dependencies can be migrated since PG17. */ if (GET_MAJOR_VERSION(old_cluster.major_version) < 1700) return; - nsubs_on_old = count_old_cluster_subscriptions(); - /* Quick return if there are no subscriptions to be migrated. */ - if (nsubs_on_old == 0) + if (old_cluster.nsubs == 0) return; prep_status("Checking for new cluster configuration for subscriptions"); @@ -1821,10 +1820,10 @@ check_new_cluster_subscription_configuration(void) pg_fatal("could not determine parameter settings on new cluster"); max_replication_slots = atoi(PQgetvalue(res, 0, 0)); - if (nsubs_on_old > max_replication_slots) + if (old_cluster.nsubs > max_replication_slots) pg_fatal("\"max_replication_slots\" (%d) must be greater than or equal to the number of " "subscriptions (%d) on the old cluster", - max_replication_slots, nsubs_on_old); + max_replication_slots, old_cluster.nsubs); PQclear(res); PQfinish(conn); |