@@ -2510,3 +2510,123 @@ def test_incr_restore_issue_313(self):
2510
2510
backup_id = last_backup_id , options = ['--progress' , '--incremental-mode=checksum' ])
2511
2511
node .slow_start ()
2512
2512
self .compare_pgdata (pgdata , self .pgdata_content (node .data_dir ))
2513
+
2514
+ # @unittest.skip("skip")
2515
+ def test_skip_pages_at_non_zero_segment_checksum (self ):
2516
+ if self .remote :
2517
+ self .skipTest ("Skipped because this test doesn't work properly in remote mode yet" )
2518
+
2519
+ node = self .make_simple_node (
2520
+ base_dir = os .path .join (self .module_name , self .fname , 'node' ),
2521
+ initdb_params = ['--data-checksums' ],
2522
+ pg_options = {'wal_log_hints' : 'on' })
2523
+
2524
+ backup_dir = os .path .join (self .tmp_path , self .module_name , self .fname , 'backup' )
2525
+ self .init_pb (backup_dir )
2526
+ self .add_instance (backup_dir , 'node' , node )
2527
+ self .set_archiving (backup_dir , 'node' , node )
2528
+ node .slow_start ()
2529
+
2530
+ # create table of size > 1 GB, so it will have several segments
2531
+ node .safe_psql (
2532
+ 'postgres' ,
2533
+ "create table t as select i as a, i*2 as b, i*3 as c, i*4 as d, i*5 as e "
2534
+ "from generate_series(1,20600000) i; "
2535
+ "CHECKPOINT " )
2536
+
2537
+ filepath = node .safe_psql (
2538
+ 'postgres' ,
2539
+ "SELECT pg_relation_filepath('t')"
2540
+ ).decode ('utf-8' ).rstrip ()
2541
+
2542
+ # segment .1 must exist in order to proceed this test
2543
+ self .assertTrue (os .path .exists (f'{ os .path .join (node .data_dir , filepath )} .1' ))
2544
+
2545
+ # do full backup
2546
+ self .backup_node (backup_dir , 'node' , node )
2547
+
2548
+ node .safe_psql (
2549
+ 'postgres' ,
2550
+ "DELETE FROM t WHERE a < 101; "
2551
+ "CHECKPOINT" )
2552
+
2553
+ # do incremental backup
2554
+ self .backup_node (backup_dir , 'node' , node , backup_type = 'page' )
2555
+
2556
+ pgdata = self .pgdata_content (node .data_dir )
2557
+
2558
+ node .safe_psql (
2559
+ 'postgres' ,
2560
+ "DELETE FROM t WHERE a < 201; "
2561
+ "CHECKPOINT" )
2562
+
2563
+ node .stop ()
2564
+
2565
+ self .restore_node (
2566
+ backup_dir , 'node' , node , options = ["-j" , "4" , "--incremental-mode=checksum" , "--log-level-console=INFO" ])
2567
+
2568
+ self .assertNotIn ('WARNING: Corruption detected in file' , self .output ,
2569
+ 'Incremental restore copied pages from .1 datafile segment that were not changed' )
2570
+
2571
+ pgdata_restored = self .pgdata_content (node .data_dir )
2572
+ self .compare_pgdata (pgdata , pgdata_restored )
2573
+
2574
+ # @unittest.skip("skip")
2575
+ def test_skip_pages_at_non_zero_segment_lsn (self ):
2576
+ if self .remote :
2577
+ self .skipTest ("Skipped because this test doesn't work properly in remote mode yet" )
2578
+
2579
+ node = self .make_simple_node (
2580
+ base_dir = os .path .join (self .module_name , self .fname , 'node' ),
2581
+ initdb_params = ['--data-checksums' ],
2582
+ pg_options = {'wal_log_hints' : 'on' })
2583
+
2584
+ backup_dir = os .path .join (self .tmp_path , self .module_name , self .fname , 'backup' )
2585
+ self .init_pb (backup_dir )
2586
+ self .add_instance (backup_dir , 'node' , node )
2587
+ self .set_archiving (backup_dir , 'node' , node )
2588
+ node .slow_start ()
2589
+
2590
+ # create table of size > 1 GB, so it will have several segments
2591
+ node .safe_psql (
2592
+ 'postgres' ,
2593
+ "create table t as select i as a, i*2 as b, i*3 as c, i*4 as d, i*5 as e "
2594
+ "from generate_series(1,20600000) i; "
2595
+ "CHECKPOINT " )
2596
+
2597
+ filepath = node .safe_psql (
2598
+ 'postgres' ,
2599
+ "SELECT pg_relation_filepath('t')"
2600
+ ).decode ('utf-8' ).rstrip ()
2601
+
2602
+ # segment .1 must exist in order to proceed this test
2603
+ self .assertTrue (os .path .exists (f'{ os .path .join (node .data_dir , filepath )} .1' ))
2604
+
2605
+ # do full backup
2606
+ self .backup_node (backup_dir , 'node' , node )
2607
+
2608
+ node .safe_psql (
2609
+ 'postgres' ,
2610
+ "DELETE FROM t WHERE a < 101; "
2611
+ "CHECKPOINT" )
2612
+
2613
+ # do incremental backup
2614
+ self .backup_node (backup_dir , 'node' , node , backup_type = 'page' )
2615
+
2616
+ pgdata = self .pgdata_content (node .data_dir )
2617
+
2618
+ node .safe_psql (
2619
+ 'postgres' ,
2620
+ "DELETE FROM t WHERE a < 201; "
2621
+ "CHECKPOINT" )
2622
+
2623
+ node .stop ()
2624
+
2625
+ self .restore_node (
2626
+ backup_dir , 'node' , node , options = ["-j" , "4" , "--incremental-mode=lsn" , "--log-level-console=INFO" ])
2627
+
2628
+ self .assertNotIn ('WARNING: Corruption detected in file' , self .output ,
2629
+ 'Incremental restore copied pages from .1 datafile segment that were not changed' )
2630
+
2631
+ pgdata_restored = self .pgdata_content (node .data_dir )
2632
+ self .compare_pgdata (pgdata , pgdata_restored )
0 commit comments