]> granicus.if.org Git - postgresql/blob - src/bin/pg_rewind/t/004_pg_xlog_symlink.pl
c5f72e2e3cde4807c5f1e1d6df5974f6419a750b
[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 = "$tmp_check/xlog_master";
27
28         rmtree($master_xlogdir);
29         RewindTest::setup_cluster();
30
31         # turn pg_xlog into a symlink
32         print("moving $test_master_datadir/pg_xlog to $master_xlogdir\n");
33         move("$test_master_datadir/pg_xlog", $master_xlogdir) or die;
34         symlink($master_xlogdir, "$test_master_datadir/pg_xlog") or die;
35
36         RewindTest::start_master();
37
38         # Create a test table and insert a row in master.
39         master_psql("CREATE TABLE tbl1 (d text)");
40         master_psql("INSERT INTO tbl1 VALUES ('in master')");
41
42         master_psql("CHECKPOINT");
43
44         RewindTest::create_standby();
45
46         # Insert additional data on master that will be replicated to standby
47         master_psql("INSERT INTO tbl1 values ('in master, before promotion')");
48
49         master_psql('CHECKPOINT');
50
51         RewindTest::promote_standby();
52
53         # Insert a row in the old master. This causes the master and standby
54         # to have "diverged", it's no longer possible to just apply the
55         # standy's logs over master directory - you need to rewind.
56         master_psql("INSERT INTO tbl1 VALUES ('in master, after promotion')");
57
58         # Also insert a new row in the standby, which won't be present in the
59         # old master.
60         standby_psql("INSERT INTO tbl1 VALUES ('in standby, after promotion')");
61
62         RewindTest::run_pg_rewind($test_mode);
63
64         check_query(
65                 'SELECT * FROM tbl1',
66                 qq(in master
67 in master, before promotion
68 in standby, after promotion
69 ),
70                 'table content');
71
72         RewindTest::clean_rewind_test();
73 }
74
75 # Run the test in both modes
76 run_test('local');
77 run_test('remote');
78
79 exit(0);