|
13 | 13 | $node1->append_conf('postgresql.conf','summarize_wal = on');
|
14 | 14 | $node1->start;
|
15 | 15 |
|
16 |
| -# See what's been summarized up until now. |
17 |
| -my$progress =$node1->safe_psql('postgres',<<EOM); |
18 |
| -SELECT summarized_tli, summarized_lsn FROM pg_get_wal_summarizer_state() |
19 |
| -EOM |
20 |
| -my ($summarized_tli,$summarized_lsn) =split(/\|/,$progress); |
21 |
| -note("before insert, summarized TLI$summarized_tli through$summarized_lsn"); |
22 |
| - |
23 | 16 | # Create a table and insert a few test rows into it. VACUUM FREEZE it so that
|
24 | 17 | # autovacuum doesn't induce any future modifications unexpectedly. Then
|
25 | 18 | # trigger a checkpoint.
|
|
31 | 24 | FROM
|
32 | 25 | generate_series(1, 400) g;
|
33 | 26 | VACUUM FREEZE;
|
| 27 | +EOM |
| 28 | + |
| 29 | +# Record the current WAL insert LSN. |
| 30 | +my$base_lsn =$node1->safe_psql('postgres',<<EOM); |
| 31 | +SELECT pg_current_wal_insert_lsn() |
| 32 | +EOM |
| 33 | +note("just after insert, WAL insert LSN is$base_lsn"); |
| 34 | + |
| 35 | +# Now perform a CHECKPOINT. |
| 36 | +$node1->safe_psql('postgres',<<EOM); |
34 | 37 | CHECKPOINT;
|
35 | 38 | EOM
|
36 | 39 |
|
37 |
| -# Wait for a new summary to show up. |
38 |
| -$node1->poll_query_until('postgres',<<EOM); |
| 40 | +# Wait for a new summary to show up, one that includes the inserts we just did. |
| 41 | +my$result =$node1->poll_query_until('postgres',<<EOM); |
39 | 42 | SELECT EXISTS (
|
40 | 43 | SELECT * from pg_available_wal_summaries()
|
41 |
| - WHEREtli =$summarized_tli ANDend_lsn > '$summarized_lsn' |
| 44 | + WHERE end_lsn >= '$base_lsn' |
42 | 45 | )
|
43 | 46 | EOM
|
| 47 | +ok($result,"WAL summarization caught up after insert"); |
44 | 48 |
|
45 |
| -#Again check the progressofWAL summarization. |
46 |
| -$progress =$node1->safe_psql('postgres',<<EOM); |
| 49 | +#Get a listofwhat summaries we now have. |
| 50 | +my$progress =$node1->safe_psql('postgres',<<EOM); |
47 | 51 | SELECT summarized_tli, summarized_lsn FROM pg_get_wal_summarizer_state()
|
48 | 52 | EOM
|
49 |
| -($summarized_tli,$summarized_lsn) =split(/\|/,$progress); |
| 53 | +my($summarized_tli,$summarized_lsn) =split(/\|/,$progress); |
50 | 54 | note("after insert, summarized TLI$summarized_tli through$summarized_lsn");
|
51 | 55 | note_wal_summary_dir("after insert",$node1);
|
52 | 56 |
|
|
56 | 60 | CHECKPOINT;
|
57 | 61 | EOM
|
58 | 62 |
|
59 |
| -#Again wait for a new summary to show up. |
60 |
| -$node1->poll_query_until('postgres',<<EOM); |
| 63 | +#Wait for a new summary to show up. |
| 64 | +$result =$node1->poll_query_until('postgres',<<EOM); |
61 | 65 | SELECT EXISTS (
|
62 | 66 | SELECT * from pg_available_wal_summaries()
|
63 | 67 | WHERE tli =$summarized_tli AND end_lsn > '$summarized_lsn'
|
64 | 68 | )
|
65 | 69 | EOM
|
| 70 | +ok($result,"got new WAL summary after update"); |
66 | 71 |
|
67 | 72 | # Figure out the exact details for the new summary file.
|
68 | 73 | my$details =$node1->safe_psql('postgres',<<EOM);
|
69 | 74 | SELECT tli, start_lsn, end_lsn from pg_available_wal_summaries()
|
70 | 75 | WHERE tli =$summarized_tli AND end_lsn > '$summarized_lsn'
|
71 | 76 | EOM
|
72 |
| -my ($tli,$start_lsn,$end_lsn) =split(/\|/,$details); |
| 77 | +my@lines =split(/\n/,$details); |
| 78 | +is(0+@lines, 1,"got exactly one new WAL summary"); |
| 79 | +my ($tli,$start_lsn,$end_lsn) =split(/\|/,$lines[0]); |
73 | 80 | note("examining summary for TLI$tli from$start_lsn to$end_lsn");
|
74 | 81 | note_wal_summary_dir("after new summary",$node1);
|
75 | 82 |
|
|
81 | 88 | ok(-f$filename,"WAL summary file exists");
|
82 | 89 | note_wal_summary_dir("after existence check",$node1);
|
83 | 90 |
|
84 |
| -# Run pg_walsummary on it. We expect block 0 to be modified, but depending |
85 |
| -# on where the new tuple ends up, block 1 might also be modified, so we |
86 |
| -# pass -i to pg_walsummary to make sure we don't end up with a 0..1 range. |
| 91 | +# Run pg_walsummary on it. We expect exactly two blocks to be modified, |
| 92 | +# block 0 and one other. |
87 | 93 | my ($stdout,$stderr) = run_command(['pg_walsummary','-i',$filename ]);
|
| 94 | +note($stdout); |
| 95 | +@lines =split(/\n/,$stdout); |
88 | 96 | like($stdout,qr/FORK main: block 0$/m,"stdout shows block 0 modified");
|
89 | 97 | is($stderr,'','stderr is empty');
|
| 98 | +is(0+@lines, 2,"UPDATE modified 2 blocks"); |
90 | 99 | note_wal_summary_dir("after pg_walsummary run",$node1);
|
91 | 100 |
|
92 | 101 | done_testing();
|
|