]> granicus.if.org Git - postgresql/blob - src/bin/pg_rewind/t/004_pg_xlog_symlink.pl
Refactor Perl test code
[postgresql] / src / bin / pg_rewind / t / 004_pg_xlog_symlink.pl
1 #
2 # Test pg_rewind when the target's pg_xlog directory is a symlink.
3 #
4 use strict;
5 use warnings;
6 use File::Copy;
7 use File::Path qw(rmtree);
8 use TestLib;
9 use Test::More;
10 if ($windows_os)
11 {
12         plan skip_all => 'symlinks not supported on Windows';
13         exit;
14 }
15 else
16 {
17         plan tests => 4;
18 }
19
20 use RewindTest;
21
22 sub run_test
23 {
24         my $test_mode = shift;
25
26         my $master_xlogdir = "${TestLib::tmp_check}/xlog_master";
27
28         rmtree($master_xlogdir);
29         RewindTest::setup_cluster();
30
31         my $test_master_datadir = $node_master->data_dir;
32
33         # turn pg_xlog into a symlink
34         print("moving $test_master_datadir/pg_xlog to $master_xlogdir\n");
35         move("$test_master_datadir/pg_xlog", $master_xlogdir) or die;
36         symlink($master_xlogdir, "$test_master_datadir/pg_xlog") or die;
37
38         RewindTest::start_master();
39
40         # Create a test table and insert a row in master.
41         master_psql("CREATE TABLE tbl1 (d text)");
42         master_psql("INSERT INTO tbl1 VALUES ('in master')");
43
44         master_psql("CHECKPOINT");
45
46         RewindTest::create_standby();
47
48         # Insert additional data on master that will be replicated to standby
49         master_psql("INSERT INTO tbl1 values ('in master, before promotion')");
50
51         master_psql('CHECKPOINT');
52
53         RewindTest::promote_standby();
54
55         # Insert a row in the old master. This causes the master and standby
56         # to have "diverged", it's no longer possible to just apply the
57         # standy's logs over master directory - you need to rewind.
58         master_psql("INSERT INTO tbl1 VALUES ('in master, after promotion')");
59
60         # Also insert a new row in the standby, which won't be present in the
61         # old master.
62         standby_psql("INSERT INTO tbl1 VALUES ('in standby, after promotion')");
63
64         RewindTest::run_pg_rewind($test_mode);
65
66         check_query(
67                 'SELECT * FROM tbl1',
68                 qq(in master
69 in master, before promotion
70 in standby, after promotion
71 ),
72                 'table content');
73
74         RewindTest::clean_rewind_test();
75 }
76
77 # Run the test in both modes
78 run_test('local');
79 run_test('remote');
80
81 exit(0);