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

PostgreSQL hot-standby replication support #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/DBIx/Class/Storage/DBI/Pg.pm
Expand Up @@ -237,6 +237,23 @@ sub deployment_statements {
$self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
}

sub is_replicating {
my $repl = 'select pg_last_xlog_receive_location() AS replicating';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even simpler:

return scalar shift->_get_dbh->selectrow_array('select pg_last_xlog_receive_location() is not null');`

my $status = shift->_get_dbh->selectrow_hashref($repl);
return 1 if defined $status->{replicating};
return 0;
}

sub lag_behind_master {
my $repl = 'SELECT '
.'CASE WHEN pg_last_xlog_receive_location() = pg_last_xlog_replay_location() '
.'THEN 0 '
.'ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())'
.'END AS log_delay';
my $status = shift->_get_dbh->selectrow_hashref($repl);
return $status->{log_delay};
}

1;

__END__
Expand Down