Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bv5qQ-00038H-Kx for pgsql-admin@arkaria.postgresql.org; Fri, 14 Oct 2016 17:00:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bv5qQ-0000V6-7S for pgsql-admin@arkaria.postgresql.org; Fri, 14 Oct 2016 17:00:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bv5oh-0005io-OB for pgsql-admin@postgresql.org; Fri, 14 Oct 2016 16:58:43 +0000 Received: from imx6.etecsa.cu ([200.55.152.141]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bv5od-0002Lu-IK for pgsql-admin@postgresql.org; Fri, 14 Oct 2016 16:58:43 +0000 Received: from nodo1.etecsa.cu (unknown [192.168.91.200]) by imx6.etecsa.cu (Postfix) with ESMTP id B6DB9122; Fri, 14 Oct 2016 12:58:33 -0400 (CDT) Received: from webmail.etecsa.cu (unknown [192.168.91.6]) by nodo1.etecsa.cu (Postfix) with ESMTP id 9F2423008993; Fri, 14 Oct 2016 12:58:33 -0400 (CDT) Received: from 192.168.207.54 (SquirrelMail authenticated user gilberto.castillo) by webmail.etecsa.cu with HTTP; Fri, 14 Oct 2016 12:58:11 -0500 (GMT+5) Message-ID: <59498.192.168.207.54.1476467891.squirrel@webmail.etecsa.cu> In-Reply-To: References: Date: Fri, 14 Oct 2016 12:58:11 -0500 (GMT+5) Subject: Re: [MASSMAIL]Re: Help with synchronous replication automation From: "Gilberto Castillo" To: "Keith" Cc: "Todd Nine" , "pgsql-admin" Reply-To: gilberto.castillo@etecsa.cu User-Agent: SquirrelMail/1.4.8-5.el5_4.10 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 104287 [Oct 14 2016] X-KLMS-AntiSpam-Version: 5.6.0.28 X-KLMS-AntiSpam-Envelope-From: gilberto.castillo@etecsa.cu X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Info: LuaCore: 127 127 f45f197f4bf642be8a97f748431e08105685b479, {msgid_created_by_recepient}, Auth:dkim=none X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, 2016/10/13 09:05:39 X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2016/10/14 07:33:00 #7919683 X-KLMS-AntiVirus-Status: Clean, skipped X-Pg-Spam-Score: -3.0 (---) 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 Use 9.6 With synchronous_commit = 'remote_apply' > On Thu, Oct 13, 2016 at 5:39 PM, Todd Nine wrote: > >> Hi all, >> I'm in the process of writing an application/api that will perform >> similar functionality to RDS on Kuberentes using Postgres. For our >> first >> use case, I have the following setup. >> >> Master (0) --(synchronous replica) -> Standby 1 >> >> --(synchronous replica) -> Standby 2 >> >> >> I have the following configuration in my postgresql.conf on the master. >> >> synchronous_standby_names = '1,2' >> >> And the following connections in standby 1 and standby 2, respectively. >> >> >> standby_mode = on >> primary_conninfo = 'host=postgres-toddtest-write port=5432 >> user=postgres >> application_name=1' >> trigger_file = '/tmp/postgresql.trigger.5432' >> recovery_target_timeline=latest >> >> >> standby_mode = on >> primary_conninfo = 'host=postgres-toddtest-write port=5432 >> user=postgres >> application_name=2' >> trigger_file = '/tmp/postgresql.trigger.5432' >> recovery_target_timeline=latest >> >> Replication appears to be working. In my master, I see the following in >> my logs. >> >> LOG: database system is ready to accept connections >> LOG: standby "1" is now the synchronous standby with priority 1 >> LOG: standby "2" is now the synchronous standby with priority 2 >> LOG: standby "2" is now the synchronous standby with priority 2 >> LOG: standby "1" is now the synchronous standby with priority 1 >> >> >> However, when I run the following on my slave nodes, the lag time seems >> enormous. >> >> SELECT now() - pg_last_xact_replay_timestamp() AS time_lag; >> time_lag >> ---------------- >> 00:21:26.33019 >> >> As a result, I have a few questions I can't seem to find the answers to >> in >> the documentation, any help would be greatly appreciated. >> >> >> 1) In this doc, it states ". If the standby is the first matching >> standby, as specified in synchronous_standby_names on the primary, the >> reply messages from that standby will be used to wake users waiting for >> confirmation that the commit record has been received." >> >> https://www.postgresql.org/docs/9.5/static/warm-standby.html >> >> My understanding is that means if Standby 1 has successfully fsynced >> that >> commit to disk, the server will return a response to the client as a >> successful commit. What happens to Standby 2? I'm assuming it's sent >> the >> same WAL entry asynchronously, but wanted to be sure. >> > > I believe you have this correct. I'd still get confirmation on this from > someone else, though. As of 9.6, you also have the option of requiring a > minimum number of synchronous standbys that must respond. Before 9.6, it > just went down the list in order and the first one to respond was all that > was necessary for the master to confirm the transaction. > > https://www.postgresql.org/docs/9.6/static/warm-standby.html#SYNCHRONOUS-REPLICATION > > >> >> 2) How can I validate the replication latency in standbys that are NOT >> the >> current hot standby? For instance, I want to deploy or upgrade the PG >> nodes automatically. I would add more hot standbys, wait for them to >> catch >> up. I would then fail over to one of them as the new master node. Once >> this is complete and working, I'd remove the old master and replicas. >> >> In order to automate 2), I need some way to verify that the standby >> that's >> just been created is up to date, as well as receiving the latest >> traffic. >> >> Thanks in advance! >> Todd >> >> >> > To more reliably get the status of the slaves, you'll want to query from > the master for the byte lag vs querying the slave for the last transaction > replay. If the master is getting no writes, then checking for replay on > the > slave will give a false report that it is falling behind simply because > it's run no transactions. I've explained this in more detail and have some > example queries on my blog > > https://www.keithf4.com/monitoring_streaming_slave_lag/ > > It's still a good monitor to have, though, and I recommend monitoring both > byte lag from the master and replay from the slave. Just set your > monitoring alerts appropriately > -- Saludos, Gilberto Castillo ETECSA, La Habana, Cuba -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin