1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-04-08 16:54:08 +02:00

tests: add ptrack test for unlogged tables

This commit is contained in:
Grigory Smolkin 2018-05-21 13:19:33 +03:00
parent 37ced690ad
commit d1e4d2b059

View File

@ -77,14 +77,24 @@ class ExcludeTest(ProbackupTest, unittest.TestCase):
self.del_test_dir(module_name, fname)
# @unittest.skip("skip")
def test_exclude_unlogged_tables(self):
"""make node without archiving, create temp table, take full backup, check that temp table not present in backup catalogue"""
def test_exclude_unlogged_tables_1(self):
"""
make node without archiving, create unlogged table, take full backup,
alter table to unlogged, take ptrack backup, restore ptrack backup,
check that PGDATA`s are physically the same
"""
fname = self.id().split('.')[3]
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
node = self.make_simple_node(
base_dir="{0}/{1}/node".format(module_name, fname),
set_replication=True,
initdb_params=['--data-checksums'],
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', "shared_buffers": "1GB", "fsync": "off", 'ptrack_enable': 'on'}
pg_options={
'wal_level': 'replica',
'max_wal_senders': '2',
"shared_buffers": "1GB",
"fsync": "off",
'ptrack_enable': 'on'}
)
self.init_pb(backup_dir)
@ -94,75 +104,38 @@ class ExcludeTest(ProbackupTest, unittest.TestCase):
conn = node.connect()
with node.connect("postgres") as conn:
conn.execute("create unlogged table test as select generate_series(0,5005000)::text")
conn.execute(
"create unlogged table test as "
"select generate_series(0,5005000)::text")
conn.commit()
conn.execute("create index test_idx on test (generate_series)")
conn.commit()
heap_path = conn.execute("select pg_relation_filepath('test')")[0][0]
conn.commit()
self.backup_node(
backup_dir, 'node', node,
backup_type='full', options=['--stream'])
index_path = conn.execute("select pg_relation_filepath('test_idx')")[0][0]
conn.commit()
index_init_path = index_path + "_init"
node.safe_psql('postgres', "alter table test set logged")
heap_oid = conn.execute("select 'test'::regclass::oid")[0][0]
conn.commit()
self.backup_node(
backup_dir, 'node', node, backup_type='ptrack',
options=['--stream', '--log-level-file=verbose']
)
toast_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid)))[0][0]
conn.commit()
toast_init_path = toast_path + "_init"
pgdata = self.pgdata_content(node.data_dir)
toast_idx_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid) + "_index"))[0][0]
conn.commit()
toast_index_idx_path = toast_idx_path + "_init"
node_restored = self.make_simple_node(
base_dir="{0}/{1}/node_restored".format(module_name, fname),
)
node_restored.cleanup()
unlogged_heap_filename = os.path.basename(heap_path)
unlogged_heap_init_filename = unlogged_heap_filename + "_init"
self.restore_node(
backup_dir, 'node', node_restored, options=["-j", "4"])
unlogged_idx_filename = os.path.basename(index_path)
unlogged_idx_init_filename = unlogged_idx_filename + "_init"
unlogged_toast_filename = os.path.basename(toast_path)
unlogged_toast_init_filename = unlogged_toast_filename + "_init"
unlogged_idx_toast_filename = os.path.basename(toast_idx_path)
unlogged_idx_toast_init_filename = unlogged_idx_toast_filename + "_init"
self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
found_unlogged_heap_init = False
found_unlogged_idx_init = False
found_unlogged_toast = False
found_unlogged_idx_toast_init = False
for root, dirs, files in os.walk(backup_dir):
for file in files:
if file in [unlogged_heap_filename, unlogged_heap_filename + ".1",
unlogged_idx_filename,
unlogged_idx_filename + ".1",
unlogged_toast_filename,
unlogged_toast_filename + ".1",
unlogged_idx_toast_filename,
unlogged_idx_toast_filename + ".1"]:
self.assertTrue(False, "Found unlogged table file in backup catalogue.\n Filepath: {0}".format(file))
if file == unlogged_heap_init_filename:
found_unlogged_heap_init = True
if file == unlogged_idx_init_filename:
found_unlogged_idx_init = True
if file == unlogged_toast_init_filename:
found_unlogged_toast = True
if file == unlogged_idx_toast_init_filename:
found_unlogged_idx_toast_init = True
self.assertTrue(found_unlogged_heap_init, "{0} is not found in backup catalogue".format(unlogged_heap_init_filename));
self.assertTrue(found_unlogged_idx_init, "{0} is not found in backup catalogue".format(unlogged_idx_init_filename));
self.assertTrue(found_unlogged_toast, "{0} is not found in backup catalogue".format(unlogged_toast_filename));
self.assertTrue(found_unlogged_idx_toast_init, "{0} is not found in backup catalogue".format(unlogged_idx_toast_init_filename));
# Physical comparison
pgdata_restored = self.pgdata_content(node_restored.data_dir)
self.compare_pgdata(pgdata, pgdata_restored)
# Clean after yourself
self.del_test_dir(module_name, fname)