Skip site navigation (1) Skip section navigation (2)

standby with a fixed lag behind the master

From: Alexey Klyukin <alexk(at)commandprompt(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: standby with a fixed lag behind the master
Date: 2012-07-26 09:24:04
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin

I've recently come across the task of setting up a PostgreSQL 9.1 standby server that is N hours behind the master, i.e. only transactions that finished N hours in the past or older should be replayed on a standby. The goal is to have a  known good state server to perform backups from and possibly revert to in case of unwanted changes on primary. It seems that there is no mechanism in PostgreSQL to just ask the standby to keep a fixed distance (in terms of either WAL segments or time) between the primary, so these are possible solutions:

1. Use restore command on standby to fetch the current WAL segment only if it has been created not less than N hours in the past (according to ctime).
2. Pause the restore process on standby if the lag * is less than N hours (with pg_xlog_replay_pause()) and resume if it is more than that.
3. Set recovery_target_time to current - 6 hours and pause_at_recovery_target to true, periodically check whether the recovery is paused, reset the recovery target time to a new value (and restart the standby) if it is.

* - the lag would be calculated as now() - pg_last_xact_replay_timestamp() on standby.

Both 2 and 3 requires external cron job to pause/resume the recovery, and 1, while being the easiest of all, doesn't work with SR (unless it's combined with WAL shipping). I wonder if there are other well established approaches at solving this problem and if there is an interest for adding such feature to the -core?

Thank you,
Alexey Klyukin
The PostgreSQL Company – Command Prompt, Inc.


pgsql-admin by date

Next:From: Craig RingerDate: 2012-07-26 09:30:33
Subject: Re: problems with access into system catalogs
Previous:From: Mark LaneDate: 2012-07-26 09:20:50
Subject: Re: "Data import from Mysql to MS Sql Server"

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group