From 583ffaaa307e0861b71ab560140bc43f65ef4fe1 Mon Sep 17 00:00:00 2001 From: Alexey Kondratov Date: Wed, 22 Apr 2020 19:30:39 +0300 Subject: [PATCH] Teach pg_probackup to work with ptrack 2.1 --- doc/pgprobackup.xml | 10 +++++----- src/backup.c | 2 +- src/ptrack.c | 4 +++- tests/helpers/ptrack_helpers.py | 3 ++- tests/ptrack.py | 13 +++++++------ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/doc/pgprobackup.xml b/doc/pgprobackup.xml index 58d42749..a2161f0c 100644 --- a/doc/pgprobackup.xml +++ b/doc/pgprobackup.xml @@ -1168,12 +1168,12 @@ CREATE EXTENSION ptrack; - To enable tracking page updates, set ptrack_map_size + To enable tracking page updates, set ptrack.map_size parameter to a positive integer and restart the server. For optimal performance, it is recommended to set - ptrack_map_size to + ptrack.map_size to N / 1024, where N is the size of the PostgreSQL cluster, in MB. If you set this @@ -1181,7 +1181,7 @@ CREATE EXTENSION ptrack; together, which leads to false-positive results when tracking changed blocks and increases the incremental backup size as unchanged blocks can also be copied into the incremental backup. - Setting ptrack_map_size to a higher value + Setting ptrack.map_size to a higher value does not affect PTRACK operation. The maximum allowed value is 1024. @@ -1201,11 +1201,11 @@ GRANT EXECUTE ON FUNCTION pg_ptrack_get_block(oid, oid, oid, bigint) TO backup; - If you change the ptrack_map_size parameter value, + If you change the ptrack.map_size parameter value, the previously created PTRACK map file is cleared, and tracking newly changed blocks starts from scratch. Thus, you have to retake a full backup before taking incremental PTRACK backups after - changing ptrack_map_size. + changing ptrack.map_size. diff --git a/src/backup.c b/src/backup.c index 96b47916..4ec515a1 100644 --- a/src/backup.c +++ b/src/backup.c @@ -436,7 +436,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync) /* * Build the page map from ptrack information. */ - if (nodeInfo->ptrack_version_num == 20) + if (nodeInfo->ptrack_version_num >= 20) make_pagemap_from_ptrack_2(backup_files_list, backup_conn, nodeInfo->ptrack_schema, prev_backup_start_lsn); diff --git a/src/ptrack.c b/src/ptrack.c index ee39d23b..a267f3f4 100644 --- a/src/ptrack.c +++ b/src/ptrack.c @@ -204,6 +204,8 @@ get_ptrack_version(PGconn *backup_conn, PGNodeInfo *nodeInfo) nodeInfo->ptrack_version_num = 17; else if (strcmp(ptrack_version_str, "2.0") == 0) nodeInfo->ptrack_version_num = 20; + else if (strcmp(ptrack_version_str, "2.1") == 0) + nodeInfo->ptrack_version_num = 21; else elog(WARNING, "Update your ptrack to the version 1.5 or upper. Current version is %s", ptrack_version_str); @@ -572,7 +574,7 @@ pg_ptrack_enable2(PGconn *backup_conn) { PGresult *res_db; - res_db = pgut_execute(backup_conn, "SHOW ptrack_map_size", 0, NULL); + res_db = pgut_execute(backup_conn, "SHOW ptrack.map_size", 0, NULL); if (strcmp(PQgetvalue(res_db, 0, 0), "0") == 0) { diff --git a/tests/helpers/ptrack_helpers.py b/tests/helpers/ptrack_helpers.py index 52a1ffda..eec57a3b 100644 --- a/tests/helpers/ptrack_helpers.py +++ b/tests/helpers/ptrack_helpers.py @@ -366,7 +366,8 @@ class ProbackupTest(object): if ptrack_enable: if node.major_version > 11: - options['ptrack_map_size'] = '128MB' + options['ptrack.map_size'] = '128' + options['shared_preload_libraries'] = 'ptrack' else: options['ptrack_enable'] = 'on' diff --git a/tests/ptrack.py b/tests/ptrack.py index 6ca8d93c..4678708b 100644 --- a/tests/ptrack.py +++ b/tests/ptrack.py @@ -269,7 +269,8 @@ class PtrackTest(ProbackupTest, unittest.TestCase): base_dir=os.path.join(module_name, fname, 'node'), set_replication=True, initdb_params=['--data-checksums'], pg_options={ - 'checkpoint_timeout': '30s'}) + 'checkpoint_timeout': '30s', + 'shared_preload_libraries': 'ptrack'}) self.init_pb(backup_dir) self.add_instance(backup_dir, 'node', node) @@ -336,16 +337,16 @@ class PtrackTest(ProbackupTest, unittest.TestCase): # DISABLE PTRACK if node.major_version >= 12: - node.safe_psql('postgres', "alter system set ptrack_map_size to 0") + node.safe_psql('postgres', "alter system set ptrack.map_size to 0") else: node.safe_psql('postgres', "alter system set ptrack_enable to off") - node.stop() node.slow_start() # ENABLE PTRACK if node.major_version >= 12: - node.safe_psql('postgres', "alter system set ptrack_map_size to '128MB'") + node.safe_psql('postgres', "alter system set ptrack.map_size to '128'") + node.safe_psql('postgres', "alter system set shared_preload_libraries to 'ptrack'") else: node.safe_psql('postgres', "alter system set ptrack_enable to on") node.stop() @@ -4054,7 +4055,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): 'FATAL: incorrect checksum of file "{0}"'.format(ptrack_map), log_content) - self.set_auto_conf(node, {'ptrack_map_size': '0'}) + self.set_auto_conf(node, {'ptrack.map_size': '0'}) node.slow_start() @@ -4082,7 +4083,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase): node.stop(['-m', 'immediate', '-D', node.data_dir]) - self.set_auto_conf(node, {'ptrack_map_size': '32'}) + self.set_auto_conf(node, {'ptrack.map_size': '32', 'shared_preload_libraries': 'ptrack'}) node.slow_start()