Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ccU8f-0007IR-JG for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Feb 2017 09:38:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ccU8e-00077i-Uc for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Feb 2017 09:38:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ccU8d-00076o-CM for pgsql-hackers@postgresql.org; Sat, 11 Feb 2017 09:38:39 +0000 Received: from gauss.credativ.com ([93.94.130.89]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1ccU8Z-000748-4w for pgsql-hackers@postgresql.org; Sat, 11 Feb 2017 09:38:37 +0000 Received: from gauss.credativ.com (localhost [127.0.0.1]) by gauss.credativ.com (Postfix) with ESMTP id C90A01E18EB; Sat, 11 Feb 2017 10:38:12 +0100 (CET) Received: from fock (ppp-88-217-106-205.dynamic.mnet-online.de [88.217.106.205]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: mba@gauss.credativ.com) by gauss.credativ.com (Postfix) with ESMTPSA id 28DA61E18BB; Sat, 11 Feb 2017 10:38:12 +0100 (CET) Message-ID: <1486805889.24568.96.camel@credativ.de> Subject: gitlab post-mortem: pg_basebackup waiting for checkpoint From: Michael Banck To: Pg Hackers Date: Sat, 11 Feb 2017 10:38:09 +0100 Organization: credativ GmbH Content-Type: multipart/mixed; boundary="=-cCnxyn1VU7wamcyajv6f" X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --=-cCnxyn1VU7wamcyajv6f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Hi, one take-away from the Gitlab Post-Mortem[1] appears to be that after their secondary lost replication, they were confused about what pg_basebackup was doing when they tried to rebuild it. It just sat there and did nothing (even with --verbose), so they assumed something was wrong with either the primary or the connection, and restarted it several times. AFAICT, it turns out the checkpoint was written on the master (they probably did not use -c fast), but this wasn't obvious to them: "One of the engineers went to the secondary and wiped the data directory, then ran pg_basebackup. Unfortunately pg_basebackup would hang, producing no meaningful output, despite the --verbose option being set." [...] "Unfortunately this did not resolve the problem of pg_basebackup not starting replication immediately. One of the engineers decided to run it with strace to see what it was blocking on. strace showed that pg_basebackup was hanging in a poll call, but that did not provide any other meaningful information that might have explained why." [...] "It would later be revealed by another engineer (who wasn't around at the time) that this is normal behavior: pg_basebackup will wait for the primary to start sending over replication data and it will sit and wait silently until that time. Unfortunately this was not clearly documented in our engineering runbooks nor in the official pg_basebackup document." ISTM that even with WAL streaming, nothing would be written on the client server until the checkpoint is complete, as do_pg_start_backup() runs the checkpoint and only returns the starting WAL location afterwards. The attached (untested) patch is to kick of a discussion on how to improve the situation, it is supposed to mention the checkpoint when --verbose is used and adds a paragraph about the checkpoint being run to the Notes section of the documentation. Michael [1]https://about.gitlab.com/2017/02/10/postmortem-of-database-outage-of-january-31/ -- Michael Banck Projektleiter / Senior Berater Tel.: +49 2166 9901-171 Fax: +49 2166 9901-100 Email: michael.banck@credativ.de credativ GmbH, HRB Mönchengladbach 12080 USt-ID-Nummer: DE204566209 Trompeterallee 108, 41189 Mönchengladbach Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer --=-cCnxyn1VU7wamcyajv6f Content-Disposition: attachment; filename="pg_basebackup.patch" Content-Type: text/x-patch; name="pg_basebackup.patch"; charset="UTF-8" Content-Transfer-Encoding: base64 ZGlmZ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=-cCnxyn1VU7wamcyajv6f Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --=-cCnxyn1VU7wamcyajv6f--