Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdmu0-0008K8-Up for pgsql-admin@arkaria.postgresql.org; Wed, 28 Nov 2012 19:02:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tdmu0-0005RZ-3g for pgsql-admin@arkaria.postgresql.org; Wed, 28 Nov 2012 19:02:32 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdmtz-0005RU-Bi for pgsql-admin@postgresql.org; Wed, 28 Nov 2012 19:02:31 +0000 Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tdmtw-00087V-IK for pgsql-admin@postgresql.org; Wed, 28 Nov 2012 19:02:30 +0000 Received: from [192.168.1.179] (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id F2E60E00EC84 for ; Wed, 28 Nov 2012 11:02:26 -0800 (PST) Message-ID: <50B65FC2.3030508@pinpointresearch.com> Date: Wed, 28 Nov 2012 11:02:26 -0800 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: Re: Fwd: Monitoring Replication on Master/Slave Postgres(9.1) References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.3 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org On 11/28/2012 10:21 AM, Shams Khan wrote: > ...how do we ensure my replication is working fine?... > Below is the core of one of my bash-script tools. It could use some tweaking (comments welcome) but works well. The script is run every minute by cron on master and standby servers. It auto-determines whether the server is currently a master or standby so the same script can be deployed to all servers. If a master-server, it updates a one-record test table with a current timestamp to ensure there is activity on the master. If a standby-server, it determines the lag based both on the age of pg_last_xact_replay_timestamp() and on the age of the record in the test table then returns the worst of the two. The delay value is set in $standby_delay which is a value in seconds. It's up to you to decide what constitutes an issue that requires attention (but remember that 60-seconds does not necessarily indicate a problem on an idle server). My first-level alert triggers at 130-seconds and I have never hit that much of a delay. #!/bin/bash # # Check PostgreSQL sync-status # # Requires table "sync_status" with column "sync_time" of type timestamp with time zone # We need a temp file tempquery="$(mktemp /tmp/monitor_db_synchronizationXXXXXXXXXX)" # If master, update sync_status timestamp and return 0. If standby, check both age # of log-replay location and of timestamp in sync_status table and set $standby_delay # to the greater of the two (in seconds) # standby_delay=$( psql -q --tuples-only --no-align 2>/dev/null <