2017-07-12 16:28:28 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, idx_ptrack
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
module_name = 'compression'
|
|
|
|
|
|
|
|
|
|
|
|
class CompressionTest(ProbackupTest, unittest.TestCase):
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_compression_stream_zlib(self):
|
|
|
|
"""make archive node, make full and page stream backups, check data correctness in restored instance"""
|
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-05-03 13:12:19 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-07-12 16:28:28 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-05-03 13:12:19 +02:00
|
|
|
pg_options={
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"create table t_heap as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(0,256) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
full_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='full',
|
|
|
|
options=[
|
|
|
|
'--stream',
|
|
|
|
'--compress-algorithm=zlib'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PAGE BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(256,512) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
page_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page',
|
|
|
|
options=[
|
|
|
|
'--stream', '--compress-algorithm=zlib',
|
|
|
|
'--log-level-console=verbose',
|
|
|
|
'--log-level-file=verbose'])
|
|
|
|
|
|
|
|
# PTRACK BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(512,768) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--compress-algorithm=zlib'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check full backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(full_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=full_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check page backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(page_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=page_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(page_result, page_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check ptrack backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(ptrack_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=ptrack_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_compression_archive_zlib(self):
|
2018-05-03 13:12:19 +02:00
|
|
|
"""
|
|
|
|
make archive node, make full and page backups,
|
|
|
|
check data correctness in restored instance
|
|
|
|
"""
|
2017-07-12 16:28:28 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-05-03 13:12:19 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-07-12 16:28:28 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-05-03 13:12:19 +02:00
|
|
|
pg_options={
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"create table t_heap as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector from generate_series(0,1) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
full_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='full',
|
|
|
|
options=["--compress-algorithm=zlib"])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PAGE BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector "
|
|
|
|
"from generate_series(0,2) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
page_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page',
|
|
|
|
options=["--compress-algorithm=zlib"])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PTRACK BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector from generate_series(0,3) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--compress-algorithm=zlib'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check full backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(full_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=full_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check page backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(page_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=page_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(page_result, page_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check ptrack backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(ptrack_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=ptrack_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_compression_stream_pglz(self):
|
2018-05-03 13:12:19 +02:00
|
|
|
"""
|
|
|
|
make archive node, make full and page stream backups,
|
|
|
|
check data correctness in restored instance
|
|
|
|
"""
|
2017-07-12 16:28:28 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-05-03 13:12:19 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-07-12 16:28:28 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-05-03 13:12:19 +02:00
|
|
|
pg_options={
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"create table t_heap as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(0,256) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
full_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='full',
|
|
|
|
options=['--stream', '--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PAGE BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(256,512) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
page_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page',
|
|
|
|
options=['--stream', '--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PTRACK BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(512,768) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check full backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(full_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=full_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check page backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(page_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=page_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(page_result, page_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check ptrack backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(ptrack_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=ptrack_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_compression_archive_pglz(self):
|
2018-05-03 13:12:19 +02:00
|
|
|
"""
|
|
|
|
make archive node, make full and page backups,
|
|
|
|
check data correctness in restored instance
|
|
|
|
"""
|
2017-07-12 16:28:28 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-05-03 13:12:19 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-07-12 16:28:28 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-05-03 13:12:19 +02:00
|
|
|
pg_options={
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"create table t_heap as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector "
|
|
|
|
"from generate_series(0,100) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
full_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='full',
|
|
|
|
options=['--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PAGE BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector "
|
|
|
|
"from generate_series(100,200) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
page_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page',
|
|
|
|
options=['--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2018-05-03 13:12:19 +02:00
|
|
|
# PTRACK BACKUP
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-05-03 13:12:19 +02:00
|
|
|
"insert into t_heap select i as id, md5(i::text) as text, "
|
|
|
|
"md5(i::text)::tsvector as tsvector "
|
|
|
|
"from generate_series(200,300) i")
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result = node.execute("postgres", "SELECT * FROM t_heap")
|
2018-05-03 13:12:19 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--compress-algorithm=pglz'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check full backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(full_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=full_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check page backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(page_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=page_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
page_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(page_result, page_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check ptrack backup
|
2018-05-03 13:12:19 +02:00
|
|
|
self.assertIn(
|
|
|
|
"INFO: Restore of backup {0} completed.".format(ptrack_backup_id),
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node, backup_id=ptrack_backup_id,
|
|
|
|
options=[
|
|
|
|
"-j", "4", "--immediate",
|
|
|
|
"--recovery-target-action=promote"]),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd))
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.execute("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
def test_compression_wrong_algorithm(self):
|
2018-05-03 13:12:19 +02:00
|
|
|
"""
|
|
|
|
make archive node, make full and page backups,
|
|
|
|
check data correctness in restored instance
|
|
|
|
"""
|
2017-07-12 16:28:28 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-04-11 18:47:19 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-07-12 16:28:28 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-04-11 18:47:19 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.start()
|
|
|
|
|
|
|
|
try:
|
2018-04-11 18:47:19 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='full', options=['--compress-algorithm=bla-blah'])
|
2017-07-12 16:28:28 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2018-04-11 18:47:19 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because compress-algorithm is invalid.\n "
|
|
|
|
"Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd))
|
2017-07-12 16:28:28 +02:00
|
|
|
except ProbackupException as e:
|
2018-04-11 18:47:19 +02:00
|
|
|
self.assertEqual(
|
|
|
|
e.message,
|
2017-07-12 16:28:28 +02:00
|
|
|
'ERROR: invalid compress algorithm value "bla-blah"\n',
|
2018-04-11 18:47:19 +02:00
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd))
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2018-11-11 20:53:00 +02:00
|
|
|
|
|
|
|
@unittest.skip("skip")
|
|
|
|
def test_uncompressable_pages(self):
|
|
|
|
"""
|
|
|
|
make archive node, create table with uncompressable toast pages,
|
|
|
|
take backup with compression, make sure that page was not compressed,
|
|
|
|
restore backup and check data correctness
|
|
|
|
"""
|
|
|
|
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),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s'}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# node.safe_psql(
|
|
|
|
# "postgres",
|
|
|
|
# "create table t_heap as select i, "
|
|
|
|
# "repeat('1234567890abcdefghiyklmn', 1)::bytea, "
|
|
|
|
# "point(0,0) from generate_series(0,1) i")
|
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"create table t as select i, "
|
|
|
|
"repeat(md5(i::text),5006056) as fat_attr "
|
|
|
|
"from generate_series(0,10) i;")
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='full',
|
|
|
|
options=[
|
|
|
|
'--compress',
|
|
|
|
'--log-level-file=verbose'])
|
|
|
|
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='full',
|
|
|
|
options=[
|
|
|
|
'--compress',
|
|
|
|
'--log-level-file=verbose'])
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
# self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# create table t as select i, repeat(md5('1234567890'), 1)::bytea, point(0,0) from generate_series(0,1) i;
|
|
|
|
|
|
|
|
|
|
|
|
# create table t_bytea_1(file oid);
|
|
|
|
# INSERT INTO t_bytea_1 (file)
|
|
|
|
# VALUES (lo_import('/home/gsmol/git/postgres/contrib/pg_probackup/tests/expected/sample.random', 24593));
|
|
|
|
# insert into t_bytea select string_agg(data,'') from pg_largeobject where pageno > 0;
|
|
|
|
#
|