Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id E12BB7ACC83 for ; Wed, 8 Aug 2012 14:35:38 -0300 (ADT) Received: from mx2.d2.com ([66.251.81.121]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SzAAO-0001kT-GI for pgsql-admin@postgresql.org; Wed, 08 Aug 2012 17:35:38 +0000 Received: from mxb.d2.com ([10.85.4.6]) by mx2.d2.com (8.13.8/8.13.8) with ESMTP id q78IV0mH019115 for ; Wed, 8 Aug 2012 11:31:14 -0700 X-ASG-Debug-ID: 1344447295-01d10a1afa111d30001-ysJW5H Received: from mail01.d2.com ([172.16.66.171]) by mxb.d2.com with ESMTP id GfFkxHcmsmUkoCXy; Wed, 08 Aug 2012 10:34:55 -0700 (PDT) X-Barracuda-Envelope-From: aalvarez@d2.com Received: from exbew2k3-02.d2.com (exbew2k3-02 [10.78.2.16]) by mail01.d2.com (8.13.8/8.13.8/Debian-3) with ESMTP id q78HYs0F001789; Wed, 8 Aug 2012 10:34:54 -0700 Received: from [10.126.2.222] ([10.126.2.222] RDNS failed) by exbew2k3-02.d2.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 8 Aug 2012 10:34:54 -0700 Message-ID: <5022A33E.6080500@d2.com> Date: Wed, 08 Aug 2012 10:34:54 -0700 From: Amador Alvarez User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 Thunderbird/3.1.19 MIME-Version: 1.0 To: Alexey Klyukin CC: pgsql-admin@postgresql.org Subject: Re: standby with a fixed lag behind the master References: <43742AE6-5297-428F-A04A-6A91BF68B54F@commandprompt.com> X-ASG-Orig-Subj: Re: [ADMIN] standby with a fixed lag behind the master In-Reply-To: <43742AE6-5297-428F-A04A-6A91BF68B54F@commandprompt.com> Content-Type: text/plain; charset=windows-1252; format=flowed X-OriginalArrivalTime: 08 Aug 2012 17:34:54.0638 (UTC) FILETIME=[1F67CCE0:01CD758C] X-Barracuda-Connect: UNKNOWN[172.16.66.171] X-Barracuda-Start-Time: 1344447295 X-Barracuda-URL: http://10.85.4.6:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at d2.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using per-user scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.105063 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: NO, score=-2.4 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, RATWARE_GECKO_BUILD autolearn=unavailable version=3.2.4 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on mx2.d2.com Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx2.d2.com id q78IV0mH019115 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/55 X-Sequence-Number: 39876 Hi there, And why not shipping older WAL files to the target on a regular basis ?. On the master you can control with a crontab job to ship the wanted WAL=20 files (n hours older than current time and clean the shipped up, check=20 rsync options up) in a regular basis. A.A. On 07/26/2012 02:24 AM, Alexey Klyukin wrote: > Hello, > > 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 fini= shed 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 n= o 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 i= f 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_ta= rget 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 combi= ned with WAL shipping). I wonder if there are other well established approa= ches at solving this problem and if there is an interest for adding such fe= ature to the -core? > > Thank you, > -- > Alexey Klyukin http://www.commandprompt.com > The PostgreSQL Company =96 Command Prompt, Inc. > > > > >