Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_replication_slots check to check the delay on any replication slots. #109

Closed
wants to merge 4 commits into from

Conversation

glynastill
Copy link
Contributor

"Delay" is measured as size of transaction logs retained for the slot e.g:
check_postgres_replication_slots -db=TEST -H=192.168.0.106 -warning=32M -critical=64M

…on slots.

"Delay" is measured as size of transaction logs retained for the slot e.g:
    check_postgres_replication_slots -db=TEST -H=192.168.0.106 -warning=32M -critical=64M
@df7cb
Copy link
Collaborator

df7cb commented Jun 2, 2016

Hi,

thanks for the pull request! Some comments:

  • this needs a testcase. I'll paste below what I got when I tried this action, but there's some bits to resolve first
  • it just doesn't work for me with pg_create_physical_replication_slot(). The regexp passed to run_command doesn't match the output at all.
  • after removing the regex => \d bit, it doesn't seem to like the fact that the physical slot is inactive:
    'Argument "" isn't numeric in numeric ge (>=) at check_postgres.pl line 5216.
    POSTGRES_REPLICATION_SLOTS WARNING: DB "postgres" (host:/tmp/cptesting_socket) cp_testing_slot: (physical inactive) | time=0.02s cp_testing_slot=;0
  • I haven't tried logical decoding slots yet
  • there's quite a bunch of trailing whitespace and stray tabs

t/02_replication_slots.t:

#!perl

## Test the "replication_slots" action

use 5.006;
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 15;
use lib 't','.';
use CP_Testing;

use vars qw/$dbh $result $t $port $host $dbname/;

my $cp = CP_Testing->new( {default_action => 'replication_slots'} );

$dbh = $cp->test_database_handle();
$dbh->{AutoCommit} = 1;
$port = $cp->get_port();
$host = $cp->get_host();
$dbname = $cp->get_dbname;

diag "Connected as $port:$host:$dbname\n";

my $S = q{Action 'replication_slots'};
my $label = 'POSTGRES_REPLICATION_SLOTS';

$t = qq{$S self-identifies correctly};
$result = $cp->run(q{-w 0});
like ($result, qr{^$label}, $t);

$t = qq{$S identifies host};
like ($result, qr{host:$host}, $t);

$t = qq{$S reports no replication slots};
like ($result, qr{No replication slots found}, $t);

$t = qq{$S accepts valid -w input};
for my $arg (
     '1 MB',
     '1 GB',
    ) {
   like ($cp->run(qq{-w "$arg"}), qr{^$label}, "$t ($arg)");
}

$t = qq{$S rejects invalid -w input};
for my $arg (
     '-1 MB',
     'abc'
    ) {
   like ($cp->run(qq{-w "$arg"}), qr{^ERROR: Invalid size}, "$t ($arg)");
}

$dbh->do ("SELECT * FROM pg_create_physical_replication_slot('cp_testing_slot')");

$t = qq{$S reports replication slots};
$result = $cp->run(q{-w 0});
like ($result, qr{Some replication slots found}, $t);
# ... more tests here

$dbh->do ("SELECT pg_drop_replication_slot('cp_testing_slot')");

exit;
--- a/t/CP_Testing.pm
+++ b/t/CP_Testing.pm
@@ -143,6 +143,12 @@ sub test_database_handle {
             print $cfh qq{max_fsm_pages = 99999\n};
         }

+        ## >= 9.4
+        if ($imaj > 9 or ($imaj==9 and $imin >= 4)) {
+            print $cfh qq{wal_level = hot_standby\n};
+            print $cfh qq{max_replication_slots = 1\n};
+        }
+
         print $cfh "\n";
         close $cfh or die qq{Could not close "$cfile": $!\n};

@glynastill
Copy link
Contributor Author

Thanks very much Christoph!

Looks like I never tested it on a physical replication slot that hadn't been "started up" yet with START_REPLICATION. This should be resolved now, as well as the sloppy whitespace.

I've added some test cases to the file you supplied, with most of the tests done on logical slots because of the requirement for physical slots to be started up, but the tests on the physical slots would be the same anyway so I'm not sure it's required.

If we needed to I guess we could start the physical slots up with psql over the replication protocol; that'd require a way to add the relevent entries in pg_hba.conf for the test_database and I couldn't see an existing way to do that ... and I didn't want to roll my own if there was a way to do it already?

@df7cb
Copy link
Collaborator

df7cb commented Jun 3, 2016

Thanks for the update, just pushed as a3ea525.

Physical slots were just what I was trying first, from skimming over your testcases the code looks very much good enough.

@df7cb df7cb closed this Jun 3, 2016
bucardo pushed a commit that referenced this pull request Jun 3, 2016
@glynastill glynastill deleted the check_replication_slots branch June 7, 2016 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants