|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use PostgresNode; |
| 5 | +use TestLib; |
| 6 | +use Test::Moretests=> 9; |
| 7 | + |
| 8 | +my$tempdir = TestLib::tempdir; |
| 9 | + |
| 10 | +command_fails_like(['pg_ctl','-D',"$tempdir/nonexistent",'promote' ], |
| 11 | +qr/directory .* does not exist/, |
| 12 | +'pg_ctl promote with nonexistent directory'); |
| 13 | + |
| 14 | +my$node_primary = get_new_node('primary'); |
| 15 | +$node_primary->init(allows_streaming=> 1); |
| 16 | + |
| 17 | +command_fails_like(['pg_ctl','-D',$node_primary->data_dir,'promote' ], |
| 18 | +qr/PID file .* does not exist/, |
| 19 | +'pg_ctl promote of not running instance fails'); |
| 20 | + |
| 21 | +$node_primary->start; |
| 22 | + |
| 23 | +command_fails_like(['pg_ctl','-D',$node_primary->data_dir,'promote' ], |
| 24 | +qr/not in standby mode/, |
| 25 | +'pg_ctl promote of primary instance fails'); |
| 26 | + |
| 27 | +my$node_standby = get_new_node('standby'); |
| 28 | +$node_primary->backup('my_backup'); |
| 29 | +$node_standby->init_from_backup($node_primary,'my_backup',has_streaming=> 1); |
| 30 | +$node_standby->start; |
| 31 | + |
| 32 | +is($node_standby->safe_psql('postgres','SELECT pg_is_in_recovery()'), |
| 33 | +'t','standby is in recovery'); |
| 34 | + |
| 35 | +command_ok(['pg_ctl','-D',$node_standby->data_dir,'promote' ], |
| 36 | +'pg_ctl promote of standby runs'); |
| 37 | + |
| 38 | +ok($node_standby->poll_query_until('postgres','SELECT NOT pg_is_in_recovery()'), |
| 39 | +'promoted standby is not in recovery'); |