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

Conversation

akkornel
Copy link

Hello!

We have been using some customizations to DBIx::Class::Storage::DBI::Pg for a while, which makes DBIx::Class replication-aware for Postgres. I'd like to push the changes upstream.

The changes work with PostgreSQL hot-standby replication, which was introduced in PostgreSQL 9.0. I don't know if it would work in other forms of PostgreSQL master-slave replication (such as Slony); I'm sure it won't work with PostgreSQL master-master replication (such as BDR), although I'm not sure you'd even want to use this in a multi-master environment.

The code was written by a co-worker, but I've gotten his OK to push this upstream.

Add the is_replicating and lag_behind_master calls that
DBIx::Class::Storage::DBI::Replicated::Pool::validate_replicants needs.

This works with PostgreSQL's hot-standby functionality that was introduced in
PostgreSQL 9.0.  It may not work with other replication methods, like BDR or
Slony.  More info on hot-standby is available here:

* https://wiki.postgresql.org/wiki/Hot_Standby

Signed-off-by: Karl Kornel <akkornel@stanford.edu>
@ribasushi
Copy link
Collaborator

Hello @akkornel Thanks for sending this upstream! I am going to poke a couple folks below, and also did shout out to the mailing list. Let's see what comes back...

@ilmari That'd be something for you to look at, I am not sure of the specifics

@wchristian IIRC you had a modified copy of the Replicated pipeline at $somejob - please take a look whether this conflicts with anything

@ilmari
Copy link
Contributor

ilmari commented Apr 22, 2016

This looks good to me, but a slight nitpick would be that using ->selectrow_hashref is wasteful when getting a single scalar, just use ->selectrow_array in scalar context.

@@ -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');`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants