From 51be6c09256272e1ce0360b5376b4a14cd1d9a61 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 6 Nov 2024 10:53:40 -0600 Subject: [PATCH v1 8/8] Avoid copying sequence files in pg_upgrade's catalog-swap mode. THIS IS A PROOF OF CONCEPT AND IS NOT READY FOR SERIOUS REVIEW. On clusters with many sequences, this can further reduce the amount of time required to wire up the data files in the new cluster. If the sequence data file format changes, this optimization cannot be used, but that seems rare enough. --- src/bin/pg_upgrade/dump.c | 8 +++++++- src/bin/pg_upgrade/info.c | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c index 8453722833..d5a81cc29c 100644 --- a/src/bin/pg_upgrade/dump.c +++ b/src/bin/pg_upgrade/dump.c @@ -51,10 +51,16 @@ generate_old_dump(void) snprintf(sql_file_name, sizeof(sql_file_name), DB_DUMP_FILE_MASK, old_db->db_oid); snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); + /* + * XXX: We need to be sure that the sequence data format hasn't + * changed. + */ parallel_exec_prog(log_file_name, NULL, "\"%s/pg_dump\" %s --schema-only --quote-all-identifiers " - "--binary-upgrade --sequence-data --format=custom %s --no-sync --file=\"%s/%s\" %s", + "--binary-upgrade %s --format=custom %s --no-sync --file=\"%s/%s\" %s", new_cluster.bindir, cluster_conn_opts(&old_cluster), + (user_opts.transfer_mode == TRANSFER_MODE_CATALOG_SWAP) ? + "" : "--sequence-data", log_opts.verbose ? "--verbose" : "", log_opts.dumpdir, sql_file_name, escaped_connstr.data); diff --git a/src/bin/pg_upgrade/info.c b/src/bin/pg_upgrade/info.c index f83ded89cb..786d17e32f 100644 --- a/src/bin/pg_upgrade/info.c +++ b/src/bin/pg_upgrade/info.c @@ -483,6 +483,8 @@ get_rel_infos_query(void) * pg_largeobject contains user data that does not appear in pg_dump * output, so we have to copy that system table. It's easiest to do that * by treating it as a user table. + * + * XXX: We need to be sure that the sequence data format hasn't changed. */ appendPQExpBuffer(&query, "WITH regular_heap (reloid, indtable, toastheap) AS ( " @@ -490,7 +492,7 @@ get_rel_infos_query(void) " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n " " ON c.relnamespace = n.oid " " WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ", " - CppAsString2(RELKIND_MATVIEW) ") AND " + CppAsString2(RELKIND_MATVIEW) "%s) AND " /* exclude possible orphaned temp tables */ " ((n.nspname !~ '^pg_temp_' AND " " n.nspname !~ '^pg_toast_temp_' AND " @@ -499,6 +501,8 @@ get_rel_infos_query(void) " c.oid >= %u::pg_catalog.oid) OR " " (n.nspname = 'pg_catalog' AND " " relname IN ('pg_largeobject') ))), ", + (user_opts.transfer_mode == TRANSFER_MODE_CATALOG_SWAP) ? + ", " CppAsString2(RELKIND_SEQUENCE) : "", FirstNormalObjectId); /* -- 2.39.5 (Apple Git-154)