Skip to content

Commit bef73b8

Browse files
committed
more usages for table_checksum
1 parent 6bd71d8 commit bef73b8

11 files changed

+185
-239
lines changed

tests/archive_test.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_pgpro434_1(self):
3535
"md5(repeat(i::text,10))::tsvector as tsvector from "
3636
"generate_series(0,100) i")
3737

38-
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
38+
result = node.table_checksum("t_heap")
3939
self.backup_node(
4040
backup_dir, 'node', node)
4141
node.cleanup()
@@ -58,7 +58,7 @@ def test_pgpro434_1(self):
5858
node.slow_start()
5959

6060
self.assertEqual(
61-
result, node.safe_psql("postgres", "SELECT * FROM t_heap"),
61+
result, node.table_checksum("t_heap"),
6262
'data after restore not equal to original data')
6363

6464
# @unittest.skip("skip")
@@ -152,7 +152,7 @@ def test_pgpro434_2(self):
152152

153153
backup_id = self.backup_node(backup_dir, 'node', node)
154154

155-
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
155+
result = node.table_checksum("t_heap")
156156
node.safe_psql(
157157
"postgres",
158158
"insert into t_heap select 100503 as id, md5(i::text) as text, "
@@ -204,11 +204,7 @@ def test_pgpro434_2(self):
204204
"select exists(select 1 from t_heap where id > 100500)")[0][0],
205205
'data after restore not equal to original data')
206206

207-
self.assertEqual(
208-
result,
209-
node.safe_psql(
210-
"postgres",
211-
"SELECT * FROM t_heap"),
207+
self.assertEqual(result, node.table_checksum("t_heap"),
212208
'data after restore not equal to original data')
213209

214210
# @unittest.skip("skip")
@@ -702,7 +698,7 @@ def test_replica_archive(self):
702698
"from generate_series(0,2560) i")
703699

704700
self.backup_node(backup_dir, 'master', master, options=['--stream'])
705-
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
701+
before = master.table_checksum("t_heap")
706702

707703
# Settings for Replica
708704
self.restore_node(backup_dir, 'master', replica)
@@ -713,7 +709,7 @@ def test_replica_archive(self):
713709
replica.slow_start(replica=True)
714710

715711
# Check data correctness on replica
716-
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
712+
after = replica.table_checksum("t_heap")
717713
self.assertEqual(before, after)
718714

719715
# Change data on master, take FULL backup from replica,
@@ -724,7 +720,7 @@ def test_replica_archive(self):
724720
"insert into t_heap select i as id, md5(i::text) as text, "
725721
"md5(repeat(i::text,10))::tsvector as tsvector "
726722
"from generate_series(256,512) i")
727-
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
723+
before = master.table_checksum("t_heap")
728724

729725
backup_id = self.backup_node(
730726
backup_dir, 'replica', replica,
@@ -748,7 +744,7 @@ def test_replica_archive(self):
748744
self.set_auto_conf(node, {'port': node.port})
749745
node.slow_start()
750746
# CHECK DATA CORRECTNESS
751-
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
747+
after = node.table_checksum("t_heap")
752748
self.assertEqual(before, after)
753749

754750
# Change data on master, make PAGE backup from replica,
@@ -760,7 +756,7 @@ def test_replica_archive(self):
760756
"md5(repeat(i::text,10))::tsvector as tsvector "
761757
"from generate_series(512,80680) i")
762758

763-
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
759+
before = master.table_checksum("t_heap")
764760

765761
self.wait_until_replica_catch_with_master(master, replica)
766762

@@ -787,7 +783,7 @@ def test_replica_archive(self):
787783

788784
node.slow_start()
789785
# CHECK DATA CORRECTNESS
790-
after = node.safe_psql("postgres", "SELECT * FROM t_heap")
786+
after = node.table_checksum("t_heap")
791787
self.assertEqual(before, after)
792788

793789
# @unittest.expectedFailure
@@ -831,7 +827,7 @@ def test_master_and_replica_parallel_archiving(self):
831827
# TAKE FULL ARCHIVE BACKUP FROM MASTER
832828
self.backup_node(backup_dir, 'master', master)
833829
# GET LOGICAL CONTENT FROM MASTER
834-
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
830+
before = master.table_checksum("t_heap")
835831
# GET PHYSICAL CONTENT FROM MASTER
836832
pgdata_master = self.pgdata_content(master.data_dir)
837833

@@ -849,7 +845,7 @@ def test_master_and_replica_parallel_archiving(self):
849845
replica.slow_start(replica=True)
850846

851847
# CHECK LOGICAL CORRECTNESS on REPLICA
852-
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
848+
after = replica.table_checksum("t_heap")
853849
self.assertEqual(before, after)
854850

855851
master.psql(
@@ -923,7 +919,7 @@ def test_basic_master_and_replica_concurrent_archiving(self):
923919
# TAKE FULL ARCHIVE BACKUP FROM MASTER
924920
self.backup_node(backup_dir, 'master', master)
925921
# GET LOGICAL CONTENT FROM MASTER
926-
before = master.safe_psql("postgres", "SELECT * FROM t_heap")
922+
before = master.table_checksum("t_heap")
927923
# GET PHYSICAL CONTENT FROM MASTER
928924
pgdata_master = self.pgdata_content(master.data_dir)
929925

@@ -942,7 +938,7 @@ def test_basic_master_and_replica_concurrent_archiving(self):
942938
replica.slow_start(replica=True)
943939

944940
# CHECK LOGICAL CORRECTNESS on REPLICA
945-
after = replica.safe_psql("postgres", "SELECT * FROM t_heap")
941+
after = replica.table_checksum("t_heap")
946942
self.assertEqual(before, after)
947943

948944
master.psql(
@@ -1107,7 +1103,7 @@ def test_archive_pg_receivexlog(self):
11071103
node,
11081104
backup_type='page'
11091105
)
1110-
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
1106+
result = node.table_checksum("t_heap")
11111107
self.validate_pb(backup_dir)
11121108

11131109
# Check data correctness
@@ -1117,9 +1113,7 @@ def test_archive_pg_receivexlog(self):
11171113

11181114
self.assertEqual(
11191115
result,
1120-
node.safe_psql(
1121-
"postgres", "SELECT * FROM t_heap"
1122-
),
1116+
node.table_checksum("t_heap"),
11231117
'data after restore not equal to original data')
11241118

11251119
# Clean after yourself
@@ -1176,7 +1170,7 @@ def test_archive_pg_receivexlog_compression_pg10(self):
11761170
backup_dir, 'node', node,
11771171
backup_type='page'
11781172
)
1179-
result = node.safe_psql("postgres", "SELECT * FROM t_heap")
1173+
result = node.table_checksum("t_heap")
11801174
self.validate_pb(backup_dir)
11811175

11821176
# Check data correctness
@@ -1185,7 +1179,7 @@ def test_archive_pg_receivexlog_compression_pg10(self):
11851179
node.slow_start()
11861180

11871181
self.assertEqual(
1188-
result, node.safe_psql("postgres", "SELECT * FROM t_heap"),
1182+
result, node.table_checksum("t_heap"),
11891183
'data after restore not equal to original data')
11901184

11911185
# Clean after yourself
@@ -2150,13 +2144,8 @@ def test_archive_pg_receivexlog_partial_handling(self):
21502144

21512145
node_restored.slow_start()
21522146

2153-
result = node.safe_psql(
2154-
"postgres",
2155-
"select sum(id) from t_heap").decode('utf-8').rstrip()
2156-
2157-
result_new = node_restored.safe_psql(
2158-
"postgres",
2159-
"select sum(id) from t_heap").decode('utf-8').rstrip()
2147+
result = node.table_checksum("t_heap")
2148+
result_new = node_restored.table_checksum("t_heap")
21602149

21612150
self.assertEqual(result, result_new)
21622151

tests/catchup_test.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_basic_full_catchup(self):
2222
src_pg.safe_psql(
2323
"postgres",
2424
"CREATE TABLE ultimate_question AS SELECT 42 AS answer")
25-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
25+
src_query_result = src_pg.table_checksum("ultimate_question")
2626

2727
# do full catchup
2828
dst_pg = self.make_empty_node(os.path.join(self.module_name, self.fname, 'dst'))
@@ -47,7 +47,7 @@ def test_basic_full_catchup(self):
4747
dst_pg.slow_start()
4848

4949
# 2nd check: run verification query
50-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
50+
dst_query_result = dst_pg.table_checksum("ultimate_question")
5151
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
5252

5353
# Cleanup
@@ -69,7 +69,7 @@ def test_full_catchup_with_tablespace(self):
6969
src_pg.safe_psql(
7070
"postgres",
7171
"CREATE TABLE ultimate_question TABLESPACE tblspace1 AS SELECT 42 AS answer")
72-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
72+
src_query_result = src_pg.table_checksum("ultimate_question")
7373

7474
# do full catchup with tablespace mapping
7575
dst_pg = self.make_empty_node(os.path.join(self.module_name, self.fname, 'dst'))
@@ -105,7 +105,7 @@ def test_full_catchup_with_tablespace(self):
105105
dst_pg.slow_start()
106106

107107
# 2nd check: run verification query
108-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
108+
dst_query_result = dst_pg.table_checksum("ultimate_question")
109109
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
110110

111111
# Cleanup
@@ -146,7 +146,7 @@ def test_basic_delta_catchup(self):
146146
pgbench = src_pg.pgbench(options=['-T', '10', '--no-vacuum'])
147147
pgbench.wait()
148148
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(42)")
149-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
149+
src_query_result = src_pg.table_checksum("ultimate_question")
150150

151151
# do delta catchup
152152
self.catchup_node(
@@ -171,7 +171,7 @@ def test_basic_delta_catchup(self):
171171
dst_pg.slow_start(replica = True)
172172

173173
# 2nd check: run verification query
174-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
174+
dst_query_result = dst_pg.table_checksum("ultimate_question")
175175
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
176176

177177
# Cleanup
@@ -218,7 +218,7 @@ def test_basic_ptrack_catchup(self):
218218
pgbench = src_pg.pgbench(options=['-T', '10', '--no-vacuum'])
219219
pgbench.wait()
220220
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(42)")
221-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
221+
src_query_result = src_pg.table_checksum("ultimate_question")
222222

223223
# do ptrack catchup
224224
self.catchup_node(
@@ -243,7 +243,7 @@ def test_basic_ptrack_catchup(self):
243243
dst_pg.slow_start(replica = True)
244244

245245
# 2nd check: run verification query
246-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
246+
dst_query_result = dst_pg.table_checksum("ultimate_question")
247247
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
248248

249249
# Cleanup
@@ -282,7 +282,7 @@ def test_tli_delta_catchup(self):
282282
src_pg.slow_start(replica = True)
283283
src_pg.promote()
284284
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
285-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
285+
src_query_result = src_pg.table_checksum("ultimate_question")
286286

287287
# do catchup (src_tli = 2, dst_tli = 1)
288288
self.catchup_node(
@@ -306,7 +306,7 @@ def test_tli_delta_catchup(self):
306306
dst_pg.slow_start(replica = True)
307307

308308
# 2nd check: run verification query
309-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
309+
dst_query_result = dst_pg.table_checksum("ultimate_question")
310310
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
311311

312312
dst_pg.stop()
@@ -364,7 +364,7 @@ def test_tli_ptrack_catchup(self):
364364
self.assertEqual(src_tli, "2", "Postgres didn't update TLI after promote")
365365

366366
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
367-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
367+
src_query_result = src_pg.table_checksum("ultimate_question")
368368

369369
# do catchup (src_tli = 2, dst_tli = 1)
370370
self.catchup_node(
@@ -388,7 +388,7 @@ def test_tli_ptrack_catchup(self):
388388
dst_pg.slow_start(replica = True)
389389

390390
# 2nd check: run verification query
391-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
391+
dst_query_result = dst_pg.table_checksum("ultimate_question")
392392
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
393393

394394
dst_pg.stop()
@@ -818,7 +818,7 @@ def test_tli_destination_mismatch(self):
818818

819819
# preparation 3: "useful" changes
820820
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
821-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
821+
src_query_result = src_pg.table_checksum("ultimate_question")
822822

823823
# try catchup
824824
try:
@@ -832,7 +832,7 @@ def test_tli_destination_mismatch(self):
832832
dst_options['port'] = str(dst_pg.port)
833833
self.set_auto_conf(dst_pg, dst_options)
834834
dst_pg.slow_start()
835-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
835+
dst_query_result = dst_pg.table_checksum("ultimate_question")
836836
dst_pg.stop()
837837
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
838838
except ProbackupException as e:
@@ -896,7 +896,7 @@ def test_tli_source_mismatch(self):
896896

897897
# preparation 4: "useful" changes
898898
src_pg.safe_psql("postgres", "CREATE TABLE ultimate_question AS SELECT 42 AS answer")
899-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
899+
src_query_result = src_pg.table_checksum("ultimate_question")
900900

901901
# try catchup
902902
try:
@@ -910,7 +910,7 @@ def test_tli_source_mismatch(self):
910910
dst_options['port'] = str(dst_pg.port)
911911
self.set_auto_conf(dst_pg, dst_options)
912912
dst_pg.slow_start()
913-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
913+
dst_query_result = dst_pg.table_checksum("ultimate_question")
914914
dst_pg.stop()
915915
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
916916
except ProbackupException as e:
@@ -979,7 +979,7 @@ def test_unclean_delta_catchup(self):
979979
pgbench = src_pg.pgbench(options=['-T', '10', '--no-vacuum'])
980980
pgbench.wait()
981981
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(42)")
982-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
982+
src_query_result = src_pg.table_checksum("ultimate_question")
983983

984984
# do delta catchup
985985
self.catchup_node(
@@ -1004,7 +1004,7 @@ def test_unclean_delta_catchup(self):
10041004
dst_pg.slow_start(replica = True)
10051005

10061006
# 2nd check: run verification query
1007-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1007+
dst_query_result = dst_pg.table_checksum("ultimate_question")
10081008
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
10091009

10101010
# Cleanup
@@ -1068,7 +1068,7 @@ def test_unclean_ptrack_catchup(self):
10681068
pgbench = src_pg.pgbench(options=['-T', '10', '--no-vacuum'])
10691069
pgbench.wait()
10701070
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(42)")
1071-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1071+
src_query_result = src_pg.table_checksum("ultimate_question")
10721072

10731073
# do delta catchup
10741074
self.catchup_node(
@@ -1093,7 +1093,7 @@ def test_unclean_ptrack_catchup(self):
10931093
dst_pg.slow_start(replica = True)
10941094

10951095
# 2nd check: run verification query
1096-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1096+
dst_query_result = dst_pg.table_checksum("ultimate_question")
10971097
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
10981098

10991099
# Cleanup
@@ -1367,9 +1367,9 @@ def test_config_exclusion(self):
13671367

13681368
# check: run verification query
13691369
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(42)")
1370-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1370+
src_query_result = src_pg.table_checksum("ultimate_question")
13711371
dst_pg.catchup() # wait for replication
1372-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1372+
dst_query_result = dst_pg.table_checksum("ultimate_question")
13731373
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
13741374

13751375
# preparation 4: make changes on master (source)
@@ -1397,9 +1397,9 @@ def test_config_exclusion(self):
13971397

13981398
# check: run verification query
13991399
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(2*42)")
1400-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1400+
src_query_result = src_pg.table_checksum("ultimate_question")
14011401
dst_pg.catchup() # wait for replication
1402-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1402+
dst_query_result = dst_pg.table_checksum("ultimate_question")
14031403
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
14041404

14051405
# preparation 5: make changes on master (source)
@@ -1426,9 +1426,9 @@ def test_config_exclusion(self):
14261426

14271427
# check: run verification query
14281428
src_pg.safe_psql("postgres", "INSERT INTO ultimate_question VALUES(3*42)")
1429-
src_query_result = src_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1429+
src_query_result = src_pg.table_checksum("ultimate_question")
14301430
dst_pg.catchup() # wait for replication
1431-
dst_query_result = dst_pg.safe_psql("postgres", "SELECT * FROM ultimate_question")
1431+
dst_query_result = dst_pg.table_checksum("ultimate_question")
14321432
self.assertEqual(src_query_result, dst_query_result, 'Different answer from copy')
14331433

14341434
# Cleanup

0 commit comments

Comments
 (0)