@@ -1472,6 +1472,89 @@ sub issues_sql_like
1472
1472
1473
1473
=pod
1474
1474
1475
+ =item $node->lsn(mode)
1476
+
1477
+ Look up WAL locations on the server:
1478
+
1479
+ * insert location (master only, error on replica)
1480
+ * write location (master only, error on replica)
1481
+ * flush location (master only, error on replica)
1482
+ * receive location (always undef on master)
1483
+ * replay location (always undef on master)
1484
+
1485
+ mode must be specified.
1486
+
1487
+ =cut
1488
+
1489
+ sub lsn
1490
+ {
1491
+ my ($self , $mode ) = @_ ;
1492
+ my %modes = (
1493
+ ' insert' => ' pg_current_xlog_insert_location()' ,
1494
+ ' flush' => ' pg_current_xlog_flush_location()' ,
1495
+ ' write' => ' pg_current_xlog_location()' ,
1496
+ ' receive' => ' pg_last_xlog_receive_location()' ,
1497
+ ' replay' => ' pg_last_xlog_replay_location()' );
1498
+
1499
+ $mode = ' <undef>' if !defined ($mode );
1500
+ die " unknown mode for 'lsn': '$mode ', valid modes are "
1501
+ . join (' , ' , keys %modes )
1502
+ if !defined ($modes {$mode });
1503
+
1504
+ my $result = $self -> safe_psql(' postgres' , " SELECT $modes {$mode }" );
1505
+ chomp ($result );
1506
+ if ($result eq ' ' )
1507
+ {
1508
+ return ;
1509
+ }
1510
+ else
1511
+ {
1512
+ return $result ;
1513
+ }
1514
+ }
1515
+
1516
+ =pod
1517
+
1518
+ =item $node->wait_for_catchup(standby_name, mode, target_lsn)
1519
+
1520
+ Wait for the node with application_name standby_name (usually from node->name)
1521
+ until its replication position in pg_stat_replication equals or passes the
1522
+ upstream's xlog insert point at the time this function is called. By default
1523
+ the replay_location is waited for, but 'mode' may be specified to wait for any
1524
+ of sent|write|flush|replay.
1525
+
1526
+ If there is no active replication connection from this peer, waits until
1527
+ poll_query_until timeout.
1528
+
1529
+ Requires that the 'postgres' db exists and is accessible.
1530
+
1531
+ target_lsn may be any arbitrary lsn, but is typically $master_node->lsn('insert').
1532
+
1533
+ This is not a test. It die()s on failure.
1534
+
1535
+ =cut
1536
+
1537
+ sub wait_for_catchup
1538
+ {
1539
+ my ($self , $standby_name , $mode , $target_lsn ) = @_ ;
1540
+ $mode = defined ($mode ) ? $mode : ' replay' ;
1541
+ my %valid_modes = ( ' sent' => 1, ' write' => 1, ' flush' => 1, ' replay' => 1 );
1542
+ die " unknown mode $mode for 'wait_for_catchup', valid modes are " . join (' , ' , keys (%valid_modes )) unless exists ($valid_modes {$mode });
1543
+ # Allow passing of a PostgresNode instance as shorthand
1544
+ if ( blessed( $standby_name ) && $standby_name -> isa(" PostgresNode" ) )
1545
+ {
1546
+ $standby_name = $standby_name -> name;
1547
+ }
1548
+ die ' target_lsn must be specified' unless defined ($target_lsn );
1549
+ print " Waiting for replication conn " . $standby_name . " 's " . $mode . " _location to pass " . $target_lsn . " on " . $self -> name . " \n " ;
1550
+ my $query = qq[ SELECT '$target_lsn ' <= ${mode} _location FROM pg_catalog.pg_stat_replication WHERE application_name = '$standby_name ';] ;
1551
+ $self -> poll_query_until(' postgres' , $query )
1552
+ or die " timed out waiting for catchup, current position is " . ($self -> safe_psql(' postgres' , $query ) || ' (unknown)' );
1553
+ print " done\n " ;
1554
+ }
1555
+
1556
+ =pod
1557
+
1475
1558
=back
1476
1559
1477
1560
=cut
0 commit comments