2017-07-12 16:28:28 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import subprocess
|
2018-01-27 17:31:19 +02:00
|
|
|
from testgres import QueryException
|
2017-12-25 10:27:38 +02:00
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
import time
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
module_name = 'ptrack'
|
|
|
|
|
|
|
|
|
2018-01-26 11:52:15 +02:00
|
|
|
class PtrackTest(ProbackupTest, unittest.TestCase):
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_ptrack_enable(self):
|
|
|
|
"""make ptrack without full backup, should result in error"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-12-25 10:27:38 +02:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
)
|
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)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
try:
|
2017-12-25 10:27:38 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"]
|
|
|
|
)
|
2017-07-12 16:28:28 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-12-25 10:27:38 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because ptrack disabled.\n"
|
|
|
|
" Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd
|
|
|
|
)
|
|
|
|
)
|
2017-07-12 16:28:28 +02:00
|
|
|
except ProbackupException as e:
|
2017-12-25 10:27:38 +02:00
|
|
|
self.assertIn(
|
|
|
|
'ERROR: Ptrack is disabled\n',
|
|
|
|
e.message,
|
|
|
|
'\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)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_ptrack_disable(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""
|
|
|
|
Take full backup, disable ptrack restart postgresql,
|
|
|
|
enable ptrack, restart postgresql, take ptrack backup
|
|
|
|
which should fail
|
|
|
|
"""
|
2017-10-05 11:06:01 +02:00
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-12-25 10:27:38 +02:00
|
|
|
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',
|
|
|
|
'ptrack_enable': 'on'
|
|
|
|
}
|
|
|
|
)
|
2017-10-05 11:06:01 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-10-05 11:06:01 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=['--stream'])
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# DISABLE PTRACK
|
|
|
|
node.safe_psql('postgres', "alter system set ptrack_enable to off")
|
|
|
|
node.restart()
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# ENABLE PTRACK
|
|
|
|
node.safe_psql('postgres', "alter system set ptrack_enable to on")
|
|
|
|
node.restart()
|
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
try:
|
2017-12-25 10:27:38 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"]
|
|
|
|
)
|
2017-10-05 11:06:01 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2017-12-25 10:27:38 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because ptrack_enable was set to OFF at some"
|
|
|
|
" point after previous backup.\n"
|
|
|
|
" Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd
|
|
|
|
)
|
|
|
|
)
|
2017-10-05 11:06:01 +02:00
|
|
|
except ProbackupException as e:
|
2017-12-25 10:27:38 +02:00
|
|
|
self.assertIn(
|
|
|
|
'ERROR: LSN from ptrack_control',
|
|
|
|
e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd
|
|
|
|
)
|
|
|
|
)
|
2017-10-05 11:06:01 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_ptrack_uncommited_xact(self):
|
|
|
|
"""make ptrack backup while there is uncommited open transaction"""
|
|
|
|
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': '300s',
|
|
|
|
'ptrack_enable': 'on'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname),
|
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node_restored.cleanup()
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
con = node.connect("postgres")
|
|
|
|
con.execute(
|
|
|
|
"create table t_heap as select i"
|
|
|
|
" as id from generate_series(0,1) i"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--log-level-file=verbose']
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--log-level-file=verbose']
|
|
|
|
)
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored, options=["-j", "4"])
|
2018-01-17 19:51:43 +02:00
|
|
|
|
|
|
|
# Physical comparison
|
|
|
|
if self.paranoia:
|
2018-04-28 17:49:34 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
|
|
|
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_ptrack_vacuum_full(self):
|
|
|
|
"""make node, make full and ptrack stream backups,
|
|
|
|
restore them 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': '300s',
|
|
|
|
'ptrack_enable': 'on'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname),
|
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node_restored.cleanup()
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"create table t_heap tablespace somedata as select i"
|
|
|
|
" as id from generate_series(0,1000000) i"
|
|
|
|
)
|
|
|
|
|
|
|
|
# create async connection
|
2018-01-10 15:05:26 +02:00
|
|
|
conn = self.get_async_connect(port=node.port)
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
self.wait(conn)
|
|
|
|
|
|
|
|
acurs = conn.cursor()
|
|
|
|
acurs.execute("select pg_backend_pid()")
|
|
|
|
|
|
|
|
self.wait(conn)
|
|
|
|
pid = acurs.fetchall()[0][0]
|
|
|
|
print(pid)
|
|
|
|
|
|
|
|
gdb = self.gdb_attach(pid)
|
|
|
|
gdb.set_breakpoint('reform_and_rewrite_tuple')
|
|
|
|
|
|
|
|
if not gdb.continue_execution_until_running():
|
|
|
|
print('Failed gdb continue')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
acurs.execute("VACUUM FULL t_heap")
|
|
|
|
|
|
|
|
if gdb.stopped_in_breakpoint():
|
|
|
|
if gdb.continue_execution_until_break(20) != 'breakpoint-hit':
|
|
|
|
print('Failed to hit breakpoint')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
2018-01-14 16:32:43 +02:00
|
|
|
options=['--log-level-file=verbose']
|
2018-01-10 15:03:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
2018-01-14 16:32:43 +02:00
|
|
|
options=['--log-level-file=verbose']
|
2018-01-10 15:03:33 +02:00
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
old_tablespace = self.get_tblspace_path(node, 'somedata')
|
|
|
|
new_tablespace = self.get_tblspace_path(node_restored, 'somedata_new')
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
options=["-j", "4", "-T", "{0}={1}".format(
|
|
|
|
old_tablespace, new_tablespace)]
|
|
|
|
)
|
2018-01-14 16:32:43 +02:00
|
|
|
|
|
|
|
# Physical comparison
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2018-01-14 16:32:43 +02:00
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
|
|
|
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
2018-03-06 16:10:55 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_ptrack_vacuum_truncate(self):
|
|
|
|
"""make node, create table, take full backup,
|
|
|
|
delete last 3 pages, vacuum relation,
|
|
|
|
take ptrack backup, take second ptrack backup,
|
|
|
|
restore last ptrack 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': '300s',
|
2018-02-26 17:34:56 +02:00
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
2018-01-10 15:03:33 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname),
|
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node_restored.cleanup()
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"create sequence t_seq; "
|
|
|
|
"create table t_heap tablespace somedata as select i as id, "
|
|
|
|
"md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(0,1024) i;"
|
|
|
|
)
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"vacuum t_heap"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"delete from t_heap where ctid >= '(11,0)'"
|
|
|
|
)
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"vacuum t_heap"
|
|
|
|
)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
2018-01-14 16:32:43 +02:00
|
|
|
options=['--log-level-file=verbose']
|
2018-01-10 15:03:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
2018-01-14 16:32:43 +02:00
|
|
|
options=['--log-level-file=verbose']
|
2018-01-10 15:03:33 +02:00
|
|
|
)
|
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
old_tablespace = self.get_tblspace_path(node, 'somedata')
|
|
|
|
new_tablespace = self.get_tblspace_path(node_restored, 'somedata_new')
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
options=["-j", "4", "-T", "{0}={1}".format(
|
|
|
|
old_tablespace, new_tablespace)]
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2018-01-14 16:32:43 +02:00
|
|
|
# Physical comparison
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
2018-03-01 21:25:43 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir,
|
|
|
|
ignore_ptrack=False
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2018-01-14 16:32:43 +02:00
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-10 15:03:33 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2017-12-28 11:02:53 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-12-28 11:27:40 +02:00
|
|
|
def test_ptrack_simple(self):
|
2017-12-28 11:02:53 +02:00
|
|
|
"""make node, make full and ptrack stream backups,"
|
|
|
|
" restore them 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': '300s',
|
|
|
|
'ptrack_enable': 'on'
|
|
|
|
}
|
|
|
|
)
|
2017-12-28 11:55:32 +02:00
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname),
|
|
|
|
)
|
|
|
|
|
2017-12-28 11:02:53 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2017-12-28 11:55:32 +02:00
|
|
|
node_restored.cleanup()
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-12-28 11:02:53 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
2017-12-28 11:02:53 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"create table t_heap as select i"
|
|
|
|
" as id from generate_series(0,1) i"
|
|
|
|
)
|
|
|
|
|
2017-12-28 11:27:40 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--log-level-file=verbose']
|
2017-12-28 11:02:53 +02:00
|
|
|
)
|
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"update t_heap set id = 100500")
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=['--stream']
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-12-28 11:02:53 +02:00
|
|
|
|
|
|
|
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-28 11:27:40 +02:00
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored, options=["-j", "4"])
|
2018-01-17 19:51:43 +02:00
|
|
|
|
|
|
|
# Physical comparison
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-12-28 11:02:53 +02:00
|
|
|
# Logical comparison
|
|
|
|
self.assertEqual(
|
|
|
|
result,
|
2017-12-28 11:55:32 +02:00
|
|
|
node_restored.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-28 11:02:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Clean after yourself
|
2018-01-10 15:03:33 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-12-28 11:02:53 +02:00
|
|
|
|
2017-12-22 01:04:59 +02:00
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_ptrack_get_block(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""make node, make full and ptrack stream backups,"
|
|
|
|
" restore them and check data correctness"""
|
2017-12-22 01:04:59 +02:00
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-12-25 10:27:38 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-12-22 01:04:59 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2017-12-25 10:27:38 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '300s',
|
|
|
|
'ptrack_enable': 'on'
|
|
|
|
}
|
|
|
|
)
|
2017-12-22 01:04:59 +02:00
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-12-22 01:04:59 +02:00
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +02:00
|
|
|
"create table t_heap as select i"
|
|
|
|
" as id from generate_series(0,1) i"
|
|
|
|
)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=['--stream'])
|
2017-12-25 10:27:38 +02:00
|
|
|
gdb = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--log-level-file=verbose'],
|
|
|
|
gdb=True
|
|
|
|
)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
gdb.set_breakpoint('make_pagemap_from_ptrack')
|
|
|
|
gdb.run_until_break()
|
2017-12-22 01:04:59 +02:00
|
|
|
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"update t_heap set id = 100500")
|
|
|
|
|
2018-01-10 15:03:33 +02:00
|
|
|
gdb.continue_execution_until_exit()
|
2017-12-22 01:04:59 +02:00
|
|
|
|
2017-12-25 10:27:38 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=['--stream']
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
|
|
|
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2018-01-26 11:52:15 +02:00
|
|
|
node.cleanup()
|
|
|
|
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
|
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
# Physical comparison
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-12-28 10:52:18 +02:00
|
|
|
# Logical comparison
|
2017-12-25 10:27:38 +02:00
|
|
|
self.assertEqual(
|
|
|
|
result,
|
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
2018-01-10 15:03:33 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-12-22 01:04:59 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
def test_ptrack_stream(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""make node, make full and ptrack stream backups,
|
|
|
|
restore them and check data correctness"""
|
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')
|
2017-12-25 10:27:38 +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'],
|
2017-12-25 10:27:38 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
2017-10-03 15:27:03 +02:00
|
|
|
node.safe_psql("postgres", "create sequence t_seq")
|
2017-07-12 16:28:28 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +02:00
|
|
|
"create table t_heap as select i as id, nextval('t_seq')"
|
|
|
|
" as t_seq, 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.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-25 10:27:38 +02:00
|
|
|
full_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['--stream'])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +02:00
|
|
|
"insert into t_heap select i as id, nextval('t_seq') as t_seq,"
|
|
|
|
" 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
|
|
|
ptrack_result = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-25 10:27:38 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node',
|
|
|
|
node, backup_type='ptrack',
|
|
|
|
options=['--stream', '--log-level-file=verbose']
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Restore and check full backup
|
2017-12-25 10:27:38 +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,
|
2018-04-11 18:47:19 +02:00
|
|
|
options=["-j", "4", "--recovery-target-action=promote"]
|
2017-12-25 10:27:38 +02:00
|
|
|
),
|
|
|
|
'\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.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Restore and check ptrack backup
|
2017-12-25 10:27:38 +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,
|
2018-04-11 18:47:19 +02:00
|
|
|
options=["-j", "4", "--recovery-target-action=promote"]
|
2017-12-25 10:27:38 +02:00
|
|
|
),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd)
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
def test_ptrack_archive(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""make archive node, make full and ptrack 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')
|
2017-12-25 10:27:38 +02:00
|
|
|
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',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
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)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +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.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
full_backup_id = self.backup_node(backup_dir, 'node', node)
|
2017-12-25 10:27:38 +02:00
|
|
|
full_target_time = self.show_pb(
|
|
|
|
backup_dir, 'node', full_backup_id)['recovery-time']
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +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
|
|
|
ptrack_result = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-25 10:27:38 +02:00
|
|
|
ptrack_backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack')
|
|
|
|
ptrack_target_time = self.show_pb(
|
|
|
|
backup_dir, 'node', ptrack_backup_id)['recovery-time']
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# Drop Node
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check full backup
|
2017-12-25 10:27:38 +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,
|
2018-04-11 18:47:19 +02:00
|
|
|
options=[
|
|
|
|
"-j", "4", "--recovery-target-action=promote",
|
|
|
|
"--time={0}".format(full_target_time)]
|
2017-12-25 10:27:38 +02:00
|
|
|
),
|
|
|
|
'\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()
|
2018-06-02 19:35:37 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
full_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(full_result, full_result_new)
|
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Check ptrack backup
|
2017-12-25 10:27:38 +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,
|
2018-04-11 18:47:19 +02:00
|
|
|
options=[
|
|
|
|
"-j", "4",
|
|
|
|
"--time={0}".format(ptrack_target_time),
|
|
|
|
"--recovery-target-action=promote"]
|
2017-12-25 10:27:38 +02:00
|
|
|
),
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(self.output), self.cmd)
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
2018-07-11 09:50:38 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
ptrack_result_new = node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.assertEqual(ptrack_result, ptrack_result_new)
|
2017-10-11 17:08:56 +02:00
|
|
|
|
2017-07-12 16:28:28 +02:00
|
|
|
node.cleanup()
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
def test_ptrack_pgpro417(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""Make node, take full backup, take ptrack backup,
|
|
|
|
delete ptrack backup. Try to take ptrack backup,
|
|
|
|
which should fail"""
|
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-01-17 19:51:43 +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-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level':
|
|
|
|
'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'}
|
2017-07-12 16:28:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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")
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"SELECT * FROM t_heap")
|
|
|
|
|
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='full', options=["--stream"])
|
|
|
|
|
|
|
|
start_lsn_full = self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id)['start-lsn']
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2018-01-17 19:51:43 +02:00
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
|
|
|
|
|
|
|
start_lsn_ptrack = self.show_pb(
|
|
|
|
backup_dir, 'node', backup_id)['start-lsn']
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
self.delete_pb(backup_dir, 'node', backup_id)
|
|
|
|
|
|
|
|
# SECOND PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
|
|
|
|
try:
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
2017-07-12 16:28:28 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because of LSN mismatch from ptrack_control "
|
|
|
|
"and previous backup start_lsn.\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-01-17 19:51:43 +02:00
|
|
|
self.assertTrue(
|
|
|
|
'ERROR: LSN from ptrack_control' in e.message,
|
|
|
|
'\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)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
def test_page_pgpro417(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make archive node, take full backup, take page backup,
|
|
|
|
delete page backup. Try to take ptrack backup, which should fail
|
|
|
|
"""
|
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-01-17 19:51:43 +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-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'}
|
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)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# PAGE BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2018-01-17 19:51:43 +02:00
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='page')
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
self.delete_pb(backup_dir, 'node', backup_id)
|
2017-10-05 11:06:01 +02:00
|
|
|
# sys.exit(1)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
|
|
|
|
try:
|
|
|
|
self.backup_node(backup_dir, 'node', node, backup_type='ptrack')
|
|
|
|
# we should die here because exception is what we expect to happen
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because of LSN mismatch from ptrack_control "
|
|
|
|
"and previous backup start_lsn.\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-01-17 19:51:43 +02:00
|
|
|
self.assertTrue(
|
|
|
|
'ERROR: LSN from ptrack_control' in e.message,
|
|
|
|
'\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
|
2017-10-09 14:32:48 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-07-12 16:28:28 +02:00
|
|
|
def test_full_pgpro417(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make node, take two full backups, delete full second backup.
|
|
|
|
Try to take ptrack backup, which should fail
|
|
|
|
"""
|
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-01-17 19:51:43 +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-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on', 'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +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
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--stream"])
|
|
|
|
|
|
|
|
# SECOND FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +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
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2017-12-25 10:27:38 +02:00
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=["--stream"])
|
2017-07-12 16:28:28 +02:00
|
|
|
|
|
|
|
self.delete_pb(backup_dir, 'node', backup_id)
|
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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
|
|
|
try:
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
2017-07-12 16:28:28 +02:00
|
|
|
# we should die here because exception is what we expect to happen
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because of LSN mismatch from ptrack_control "
|
|
|
|
"and previous backup start_lsn.\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-01-17 19:51:43 +02:00
|
|
|
self.assertTrue(
|
|
|
|
"ERROR: LSN from ptrack_control" in e.message and
|
|
|
|
"Create new full backup before "
|
|
|
|
"an incremental one" in e.message,
|
|
|
|
'\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)
|
2017-08-31 22:33:54 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-09-28 09:32:06 +02:00
|
|
|
def test_create_db(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make node, take full backup, create database db1, take ptrack backup,
|
|
|
|
restore database and check it presense
|
|
|
|
"""
|
2017-08-31 22:33:54 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-01-17 19:51:43 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-08-31 22:33:54 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_size': '10GB',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '5min',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
2017-08-31 22:33:54 +02:00
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-10-05 11:06:01 +02:00
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-08-31 22:33:54 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"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-08-31 22:33:54 +02:00
|
|
|
node.safe_psql("postgres", "SELECT * FROM t_heap")
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
options=["--stream", "--log-level-file=verbose"])
|
2017-08-31 22:33:54 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
# CREATE DATABASE DB1
|
2017-10-03 15:27:03 +02:00
|
|
|
node.safe_psql("postgres", "create database db1")
|
2018-01-17 19:51:43 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"db1",
|
|
|
|
"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-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack',
|
|
|
|
options=["--stream", "--log-level-file=verbose"]
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# RESTORE
|
2018-01-17 19:51:43 +02:00
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname)
|
|
|
|
)
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
node_restored.cleanup()
|
2018-01-17 19:51:43 +02:00
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
backup_id=backup_id, options=["-j", "4"])
|
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# COMPARE PHYSICAL CONTENT
|
2017-10-11 17:08:56 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2017-10-11 17:08:56 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# START RESTORED NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# DROP DATABASE DB1
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres", "drop database db1")
|
|
|
|
# SECOND PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"]
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# RESTORE SECOND PTRACK BACKUP
|
|
|
|
node_restored.cleanup()
|
2018-01-17 19:51:43 +02:00
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
backup_id=backup_id, options=["-j", "4"]
|
|
|
|
)
|
2017-10-05 15:47:32 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# COMPARE PHYSICAL CONTENT
|
2017-10-11 17:08:56 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2017-10-11 17:08:56 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
# START RESTORED NODE
|
|
|
|
node_restored.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(node_restored.port))
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
try:
|
|
|
|
node_restored.safe_psql('db1', 'select 1')
|
|
|
|
# we should die here because exception is what we expect to happen
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because we are connecting to deleted database"
|
|
|
|
"\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd)
|
|
|
|
)
|
2018-01-27 17:31:19 +02:00
|
|
|
except QueryException as e:
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertTrue(
|
|
|
|
'FATAL: database "db1" does not exist' in e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
|
|
|
|
repr(e.message), self.cmd)
|
|
|
|
)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2017-08-31 22:33:54 +02:00
|
|
|
|
2018-10-18 08:46:02 +02:00
|
|
|
# @unittest.skip("skip")
|
|
|
|
def test_create_db_on_replica(self):
|
|
|
|
"""
|
|
|
|
Make node, take full backup, create replica from it,
|
|
|
|
take full backup from replica,
|
|
|
|
create database db1, take ptrack backup from replica,
|
|
|
|
restore database and check it presense
|
|
|
|
"""
|
|
|
|
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',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
|
|
|
node.slow_start()
|
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"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")
|
|
|
|
|
|
|
|
replica = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/replica".format(module_name, fname))
|
|
|
|
replica.cleanup()
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['-j10'])
|
|
|
|
|
|
|
|
self.restore_node(backup_dir, 'node', replica)
|
|
|
|
|
|
|
|
# Add replica
|
|
|
|
self.add_instance(backup_dir, 'replica', replica)
|
|
|
|
self.set_replica(node, replica, 'replica', synchronous=True)
|
|
|
|
self.set_archiving(backup_dir, 'replica', replica, replica=True)
|
|
|
|
replica.slow_start(replica=True)
|
|
|
|
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'replica', replica,
|
|
|
|
options=[
|
|
|
|
'-j10',
|
|
|
|
'--master-host=localhost',
|
|
|
|
'--master-db=postgres',
|
|
|
|
'--master-port={0}'.format(node.port)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
# CREATE DATABASE DB1
|
|
|
|
node.safe_psql("postgres", "create database db1")
|
|
|
|
node.safe_psql(
|
|
|
|
"db1",
|
|
|
|
"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")
|
|
|
|
|
|
|
|
# Wait until replica catch up with master
|
|
|
|
self.wait_until_replica_catch_with_master(node, replica)
|
|
|
|
replica.safe_psql('postgres', 'checkpoint')
|
|
|
|
|
|
|
|
# PTRACK BACKUP
|
|
|
|
backup_id = self.backup_node(
|
|
|
|
backup_dir, 'replica',
|
|
|
|
replica, backup_type='ptrack',
|
|
|
|
options=[
|
|
|
|
'-j10',
|
|
|
|
'--master-host=localhost',
|
|
|
|
'--master-db=postgres',
|
|
|
|
'--master-port={0}'.format(node.port)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(replica.data_dir)
|
|
|
|
|
|
|
|
# RESTORE
|
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname)
|
|
|
|
)
|
|
|
|
node_restored.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'replica', node_restored,
|
|
|
|
backup_id=backup_id, options=["-j", "4"])
|
|
|
|
|
|
|
|
# COMPARE PHYSICAL CONTENT
|
|
|
|
if self.paranoia:
|
|
|
|
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)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-10-03 15:27:03 +02:00
|
|
|
def test_alter_table_set_tablespace_ptrack(self):
|
2017-12-25 10:27:38 +02:00
|
|
|
"""Make node, create tablespace with table, take full backup,
|
|
|
|
alter tablespace location, take ptrack backup, restore database."""
|
2017-10-03 15:27:03 +02:00
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2017-12-25 10:27:38 +02:00
|
|
|
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',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'
|
|
|
|
}
|
|
|
|
)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2017-12-25 10:27:38 +02:00
|
|
|
"create table t_heap tablespace somedata as select i as id,"
|
|
|
|
" md5(i::text) as text, md5(i::text)::tsvector as tsvector"
|
|
|
|
" from generate_series(0,100) i"
|
|
|
|
)
|
|
|
|
# FULL backup
|
2017-10-03 15:27:03 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--stream"])
|
|
|
|
|
|
|
|
# ALTER TABLESPACE
|
|
|
|
self.create_tblspace_in_node(node, 'somedata_new')
|
|
|
|
node.safe_psql(
|
2017-12-25 10:27:38 +02:00
|
|
|
"postgres",
|
|
|
|
"alter table t_heap set tablespace somedata_new"
|
|
|
|
)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-11-09 11:45:04 +02:00
|
|
|
# sys.exit(1)
|
2017-10-03 15:27:03 +02:00
|
|
|
# PTRACK BACKUP
|
2017-12-25 10:27:38 +02:00
|
|
|
result = node.safe_psql(
|
|
|
|
"postgres", "select * from t_heap")
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack',
|
|
|
|
options=["--stream", "--log-level-file=verbose"]
|
|
|
|
)
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-12-25 10:27:38 +02:00
|
|
|
# node.stop()
|
|
|
|
# node.cleanup()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# RESTORE
|
2017-12-25 10:27:38 +02:00
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname)
|
|
|
|
)
|
2017-10-03 15:27:03 +02:00
|
|
|
node_restored.cleanup()
|
|
|
|
|
2017-12-25 10:27:38 +02:00
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node', node_restored,
|
|
|
|
options=[
|
|
|
|
"-j", "4",
|
|
|
|
"-T", "{0}={1}".format(
|
|
|
|
self.get_tblspace_path(node, 'somedata'),
|
|
|
|
self.get_tblspace_path(node_restored, 'somedata')
|
|
|
|
),
|
|
|
|
"-T", "{0}={1}".format(
|
|
|
|
self.get_tblspace_path(node, 'somedata_new'),
|
|
|
|
self.get_tblspace_path(node_restored, 'somedata_new')
|
2018-04-11 18:47:19 +02:00
|
|
|
),
|
|
|
|
"--recovery-target-action=promote"
|
2017-12-25 10:27:38 +02:00
|
|
|
]
|
|
|
|
)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# GET RESTORED PGDATA AND COMPARE
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# START RESTORED NODE
|
2017-12-25 10:27:38 +02:00
|
|
|
node_restored.append_conf(
|
|
|
|
'postgresql.auto.conf', 'port = {0}'.format(node_restored.port))
|
2018-07-11 09:50:38 +02:00
|
|
|
node_restored.slow_start()
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-12-25 10:27:38 +02:00
|
|
|
result_new = node_restored.safe_psql(
|
|
|
|
"postgres", "select * from t_heap")
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
self.assertEqual(result, result_new, 'lost some data after restore')
|
|
|
|
|
|
|
|
# Clean after yourself
|
2018-01-10 15:03:33 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-10-03 15:27:03 +02:00
|
|
|
def test_alter_database_set_tablespace_ptrack(self):
|
2017-12-22 01:04:59 +02:00
|
|
|
"""Make node, create tablespace with database,"
|
|
|
|
" take full backup, alter tablespace location,"
|
|
|
|
" take ptrack backup, restore database."""
|
2017-10-03 15:27:03 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-01-17 19:51:43 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-10-03 15:27:03 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'}
|
2017-10-03 15:27:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# FULL BACKUP
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--stream"])
|
|
|
|
|
|
|
|
# CREATE TABLESPACE
|
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
|
|
|
|
# ALTER DATABASE
|
2018-01-17 19:51:43 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"template1",
|
2017-10-03 15:27:03 +02:00
|
|
|
"alter database postgres set tablespace somedata")
|
|
|
|
|
|
|
|
# PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=["--stream", '--log-level-file=verbose'])
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-10-03 15:27:03 +02:00
|
|
|
node.stop()
|
|
|
|
|
|
|
|
# RESTORE
|
2018-01-17 19:51:43 +02:00
|
|
|
node_restored = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node_restored".format(module_name, fname))
|
2017-10-03 15:27:03 +02:00
|
|
|
node_restored.cleanup()
|
2018-01-17 19:51:43 +02:00
|
|
|
self.restore_node(
|
|
|
|
backup_dir, 'node',
|
|
|
|
node_restored,
|
|
|
|
options=[
|
|
|
|
"-j", "4",
|
|
|
|
"-T", "{0}={1}".format(
|
|
|
|
self.get_tblspace_path(node, 'somedata'),
|
|
|
|
self.get_tblspace_path(node_restored, 'somedata'))])
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
# GET PHYSICAL CONTENT and COMPARE PHYSICAL CONTENT
|
2017-10-11 17:08:56 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
node_restored.data_dir, ignore_ptrack=False)
|
2017-10-11 17:08:56 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2018-01-17 19:51:43 +02:00
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# START RESTORED NODE
|
2018-10-18 15:37:34 +02:00
|
|
|
node_restored.port = node.port
|
2018-10-18 08:46:02 +02:00
|
|
|
node_restored.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-09-28 09:32:06 +02:00
|
|
|
def test_drop_tablespace(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make node, create table, alter table tablespace, take ptrack backup,
|
|
|
|
move table from tablespace, take ptrack backup
|
|
|
|
"""
|
2017-09-28 09:32:06 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-01-17 19:51:43 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-09-28 09:32:06 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s',
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'}
|
2017-09-28 09:32:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
|
|
|
|
# CREATE TABLE
|
2017-08-31 22:33:54 +02:00
|
|
|
node.safe_psql(
|
2017-09-28 09:32:06 +02:00
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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-09-28 09:32:06 +02:00
|
|
|
result = node.safe_psql("postgres", "select * from t_heap")
|
|
|
|
# FULL BACKUP
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--stream"])
|
2017-08-31 22:33:54 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
# Move table to tablespace 'somedata'
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres", "alter table t_heap set tablespace somedata")
|
|
|
|
# PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# Move table back to default tablespace
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres", "alter table t_heap set tablespace pg_default")
|
2017-08-31 22:33:54 +02:00
|
|
|
# SECOND PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# DROP TABLESPACE 'somedata'
|
2017-08-31 22:33:54 +02:00
|
|
|
node.safe_psql(
|
2017-09-28 09:32:06 +02:00
|
|
|
"postgres", "drop tablespace somedata")
|
|
|
|
# THIRD PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node,
|
|
|
|
backup_type='ptrack', options=["--stream"])
|
2017-08-31 22:33:54 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
tblspace = self.get_tblspace_path(node, 'somedata')
|
|
|
|
node.cleanup()
|
|
|
|
shutil.rmtree(tblspace, ignore_errors=True)
|
|
|
|
self.restore_node(backup_dir, 'node', node, options=["-j", "4"])
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
tblspc_exist = node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"select exists(select 1 from "
|
|
|
|
"pg_tablespace where spcname = 'somedata')")
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
if tblspc_exist.rstrip() == 't':
|
2018-01-17 19:51:43 +02:00
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because "
|
|
|
|
"tablespace 'somedata' should not be present")
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
result_new = node.safe_psql("postgres", "select * from t_heap")
|
|
|
|
self.assertEqual(result, result_new)
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2017-10-05 11:06:01 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-10-09 14:32:48 +02:00
|
|
|
def test_ptrack_alter_tablespace(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make node, create table, alter table tablespace, take ptrack backup,
|
|
|
|
move table from tablespace, take ptrack backup
|
|
|
|
"""
|
2017-09-28 09:32:06 +02:00
|
|
|
self.maxDiff = None
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-01-17 19:51:43 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-09-28 09:32:06 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica', 'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30s', 'ptrack_enable': 'on',
|
|
|
|
'autovacuum': 'off'}
|
2017-09-28 09:32:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
2017-11-09 11:45:04 +02:00
|
|
|
tblspc_path = self.get_tblspace_path(node, 'somedata')
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# CREATE TABLE
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-01-17 19:51:43 +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-09-28 09:32:06 +02:00
|
|
|
result = node.safe_psql("postgres", "select * from t_heap")
|
|
|
|
# FULL BACKUP
|
|
|
|
self.backup_node(backup_dir, 'node', node, options=["--stream"])
|
|
|
|
|
|
|
|
# Move table to separate tablespace
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres", "alter table t_heap set tablespace somedata")
|
2017-11-09 11:45:04 +02:00
|
|
|
# GET LOGICAL CONTENT FROM NODE
|
|
|
|
result = node.safe_psql("postgres", "select * from t_heap")
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
# FIRTS PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=["--stream", "--log-level-file=verbose"])
|
2017-11-09 11:45:04 +02:00
|
|
|
|
|
|
|
# GET PHYSICAL CONTENT FROM NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2017-11-09 11:45:04 +02:00
|
|
|
# Restore ptrack backup
|
2018-01-17 19:51:43 +02:00
|
|
|
restored_node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/restored_node".format(module_name, fname))
|
2017-09-28 09:32:06 +02:00
|
|
|
restored_node.cleanup()
|
2018-01-17 19:51:43 +02:00
|
|
|
tblspc_path_new = self.get_tblspace_path(
|
|
|
|
restored_node, 'somedata_restored')
|
2017-09-28 09:32:06 +02:00
|
|
|
self.restore_node(backup_dir, 'node', restored_node, options=[
|
2018-04-11 18:47:19 +02:00
|
|
|
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new),
|
|
|
|
"--recovery-target-action=promote"])
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
# GET PHYSICAL CONTENT FROM RESTORED NODE and COMPARE PHYSICAL CONTENT
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
restored_node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-10-11 17:08:56 +02:00
|
|
|
|
2017-10-09 14:32:48 +02:00
|
|
|
# START RESTORED NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
restored_node.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
2018-07-11 09:50:38 +02:00
|
|
|
restored_node.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2017-11-09 11:45:04 +02:00
|
|
|
# COMPARE LOGICAL CONTENT
|
2018-01-17 19:51:43 +02:00
|
|
|
result_new = restored_node.safe_psql(
|
|
|
|
"postgres", "select * from t_heap")
|
2017-09-28 09:32:06 +02:00
|
|
|
self.assertEqual(result, result_new)
|
2017-10-11 17:08:56 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
restored_node.cleanup()
|
|
|
|
shutil.rmtree(tblspc_path_new, ignore_errors=True)
|
|
|
|
|
|
|
|
# Move table to default tablespace
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres", "alter table t_heap set tablespace pg_default")
|
|
|
|
# SECOND PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=["--stream", "--log-level-file=verbose"])
|
|
|
|
|
|
|
|
if self.paranoia:
|
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# Restore second ptrack backup and check table consistency
|
|
|
|
self.restore_node(backup_dir, 'node', restored_node, options=[
|
2018-04-11 18:47:19 +02:00
|
|
|
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new),
|
|
|
|
"--recovery-target-action=promote"])
|
2017-10-09 14:32:48 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
# GET PHYSICAL CONTENT FROM RESTORED NODE and COMPARE PHYSICAL CONTENT
|
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
restored_node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-10-09 14:32:48 +02:00
|
|
|
|
|
|
|
# START RESTORED NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
restored_node.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
2018-07-11 09:50:38 +02:00
|
|
|
restored_node.slow_start()
|
2017-10-09 14:32:48 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
result_new = restored_node.safe_psql(
|
|
|
|
"postgres", "select * from t_heap")
|
2017-09-28 09:32:06 +02:00
|
|
|
self.assertEqual(result, result_new)
|
|
|
|
|
2017-08-31 22:33:54 +02:00
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-10-03 17:26:55 +02:00
|
|
|
# @unittest.skip("skip")
|
2017-11-09 11:45:04 +02:00
|
|
|
def test_ptrack_multiple_segments(self):
|
2018-06-02 19:35:37 +02:00
|
|
|
"""
|
|
|
|
Make node, create table, alter table tablespace,
|
|
|
|
take ptrack backup, move table from tablespace, take ptrack backup
|
|
|
|
"""
|
2017-10-03 15:27:03 +02:00
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
2018-01-17 19:51:43 +02:00
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
2017-10-03 15:27:03 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-01-17 19:51:43 +02:00
|
|
|
pg_options={
|
|
|
|
'wal_level': 'replica', 'max_wal_senders': '2',
|
2018-06-02 19:35:37 +02:00
|
|
|
'ptrack_enable': 'on', 'fsync': 'off',
|
|
|
|
'autovacuum': 'off',
|
|
|
|
'full_page_writes': 'off'
|
|
|
|
}
|
2017-10-03 15:27:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2017-11-07 08:40:13 +02:00
|
|
|
self.set_archiving(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-10-05 15:47:32 +02:00
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# CREATE TABLE
|
2017-10-09 14:32:48 +02:00
|
|
|
node.pgbench_init(scale=100, options=['--tablespace=somedata'])
|
2017-10-03 15:27:03 +02:00
|
|
|
# FULL BACKUP
|
2017-11-07 08:40:13 +02:00
|
|
|
self.backup_node(backup_dir, 'node', node)
|
|
|
|
|
|
|
|
# PTRACK STUFF
|
|
|
|
idx_ptrack = {'type': 'heap'}
|
|
|
|
idx_ptrack['path'] = self.get_fork_path(node, 'pgbench_accounts')
|
|
|
|
idx_ptrack['old_size'] = self.get_fork_size(node, 'pgbench_accounts')
|
|
|
|
idx_ptrack['old_pages'] = self.get_md5_per_page_for_fork(
|
|
|
|
idx_ptrack['path'], idx_ptrack['old_size'])
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-11-09 11:45:04 +02:00
|
|
|
pgbench = node.pgbench(options=['-T', '150', '-c', '2', '--no-vacuum'])
|
2017-10-03 15:27:03 +02:00
|
|
|
pgbench.wait()
|
2018-10-19 13:54:17 +02:00
|
|
|
|
2017-11-07 08:40:13 +02:00
|
|
|
node.safe_psql("postgres", "checkpoint")
|
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
idx_ptrack['new_size'] = self.get_fork_size(
|
|
|
|
node,
|
|
|
|
'pgbench_accounts'
|
|
|
|
)
|
|
|
|
idx_ptrack['new_pages'] = self.get_md5_per_page_for_fork(
|
|
|
|
idx_ptrack['path'],
|
|
|
|
idx_ptrack['new_size']
|
|
|
|
)
|
|
|
|
idx_ptrack['ptrack'] = self.get_ptrack_bits_per_page_for_fork(
|
|
|
|
node,
|
|
|
|
idx_ptrack['path']
|
|
|
|
)
|
2018-10-16 21:53:59 +02:00
|
|
|
|
|
|
|
if not self.check_ptrack_sanity(idx_ptrack):
|
|
|
|
self.assertTrue(
|
|
|
|
False, 'Ptrack has failed to register changes in data files'
|
|
|
|
)
|
2017-11-09 11:45:04 +02:00
|
|
|
|
2017-10-09 14:32:48 +02:00
|
|
|
# GET LOGICAL CONTENT FROM NODE
|
2018-10-19 13:54:17 +02:00
|
|
|
# it`s stupid, because hint`s are ignored by ptrack
|
|
|
|
#result = node.safe_psql("postgres", "select * from pgbench_accounts")
|
2017-10-09 14:32:48 +02:00
|
|
|
# FIRTS PTRACK BACKUP
|
2018-01-17 19:51:43 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
|
|
|
options=["--log-level-file=verbose"]
|
|
|
|
)
|
2017-10-09 14:32:48 +02:00
|
|
|
# GET PHYSICAL CONTENT FROM NODE
|
2017-10-03 17:26:55 +02:00
|
|
|
pgdata = self.pgdata_content(node.data_dir)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-10-03 17:26:55 +02:00
|
|
|
# RESTORE NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
restored_node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/restored_node".format(module_name, fname))
|
2017-10-03 15:27:03 +02:00
|
|
|
restored_node.cleanup()
|
2017-10-05 15:47:32 +02:00
|
|
|
tblspc_path = self.get_tblspace_path(node, 'somedata')
|
2018-01-17 19:51:43 +02:00
|
|
|
tblspc_path_new = self.get_tblspace_path(
|
|
|
|
restored_node,
|
|
|
|
'somedata_restored'
|
|
|
|
)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
self.restore_node(backup_dir, 'node', restored_node, options=[
|
2018-04-11 18:47:19 +02:00
|
|
|
"-j", "4", "-T", "{0}={1}".format(tblspc_path, tblspc_path_new),
|
|
|
|
"--recovery-target-action=promote"])
|
2017-10-09 14:32:48 +02:00
|
|
|
|
2017-10-03 15:27:03 +02:00
|
|
|
# GET PHYSICAL CONTENT FROM NODE_RESTORED
|
2018-01-17 19:51:43 +02:00
|
|
|
if self.paranoia:
|
2018-06-02 19:35:37 +02:00
|
|
|
pgdata_restored = self.pgdata_content(
|
|
|
|
restored_node.data_dir, ignore_ptrack=False)
|
2018-01-17 19:51:43 +02:00
|
|
|
self.compare_pgdata(pgdata, pgdata_restored)
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2017-10-05 15:47:32 +02:00
|
|
|
# START RESTORED NODE
|
2018-01-17 19:51:43 +02:00
|
|
|
restored_node.append_conf(
|
|
|
|
"postgresql.auto.conf", "port = {0}".format(restored_node.port))
|
2018-07-11 09:50:38 +02:00
|
|
|
restored_node.slow_start()
|
2017-10-03 15:27:03 +02:00
|
|
|
|
2018-01-17 19:51:43 +02:00
|
|
|
result_new = restored_node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"select * from pgbench_accounts"
|
|
|
|
)
|
2017-10-11 17:08:56 +02:00
|
|
|
|
|
|
|
# COMPARE RESTORED FILES
|
2018-10-19 13:54:17 +02:00
|
|
|
#self.assertEqual(result, result_new, 'data is lost')
|
2017-10-03 15:27:03 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
2017-11-09 11:45:04 +02:00
|
|
|
self.del_test_dir(module_name, fname)
|
2018-03-26 02:19:09 +02:00
|
|
|
|
|
|
|
# @unittest.skip("skip")
|
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_atexit_fail(self):
|
|
|
|
"""
|
|
|
|
Take backups of every available types and check that PTRACK is clean
|
|
|
|
"""
|
|
|
|
fname = self.id().split('.')[3]
|
|
|
|
node = self.make_simple_node(
|
|
|
|
base_dir="{0}/{1}/node".format(module_name, fname),
|
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
|
|
|
pg_options={
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'wal_level': 'replica',
|
2018-04-11 22:02:36 +02:00
|
|
|
'max_wal_senders': '2',
|
|
|
|
'max_connections': '15'})
|
2018-03-26 02:19:09 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2018-03-26 02:19:09 +02:00
|
|
|
|
|
|
|
# Take FULL backup to clean every ptrack
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['--stream'])
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, backup_type='ptrack',
|
2018-04-28 17:49:34 +02:00
|
|
|
options=[
|
|
|
|
"--stream", "-j 30",
|
|
|
|
"--log-level-file=verbose"]
|
2018-03-26 02:19:09 +02:00
|
|
|
)
|
|
|
|
# we should die here because exception is what we expect to happen
|
|
|
|
self.assertEqual(
|
|
|
|
1, 0,
|
|
|
|
"Expecting Error because we are opening too many connections"
|
|
|
|
"\n Output: {0} \n CMD: {1}".format(
|
|
|
|
repr(self.output), self.cmd)
|
|
|
|
)
|
|
|
|
except ProbackupException as e:
|
|
|
|
self.assertIn(
|
|
|
|
'setting its status to ERROR',
|
|
|
|
e.message,
|
|
|
|
'\n Unexpected Error Message: {0}\n'
|
|
|
|
' CMD: {1}'.format(repr(e.message), self.cmd)
|
|
|
|
)
|
|
|
|
|
2018-04-02 13:59:19 +02:00
|
|
|
self.assertEqual(
|
2018-03-26 02:19:09 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-04-02 13:59:19 +02:00
|
|
|
"select * from pg_is_in_backup()").rstrip(),
|
|
|
|
"f")
|
2018-03-26 02:19:09 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|