Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbU7s-0001t7-En for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 20:16:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbU7r-0002gu-3K for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 20:16:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbU7q-0002gm-S4 for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 20:16:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbU7o-0004TP-Sd for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 20:16:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 13RKG11U2720707; Tue, 27 Apr 2021 16:16:02 -0400 From: Tom Lane To: Tomas Pospisek cc: pgsql-general@lists.postgresql.org Subject: Re: very long secondary->primary switch time In-reply-to: <5064b6f7-e4bd-d550-482a-f0bdd527f3d9@sourcepole.ch> References: <5064b6f7-e4bd-d550-482a-f0bdd527f3d9@sourcepole.ch> Comments: In-reply-to Tomas Pospisek message dated "Tue, 27 Apr 2021 19:15:03 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2720705.1619554561.1@sss.pgh.pa.us> Date: Tue, 27 Apr 2021 16:16:01 -0400 Message-ID: <2720706.1619554561@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Pospisek writes: > I maintain a postgresql cluster that does failover via patroni. The > problem is that after a failover happens it takes the secondary too long > (that is about 35min) to come up and answer queries. The log of the > secondary looks like this: > 04:00:29.777 [9679] LOG: received promote request > 04:00:29.780 [9693] FATAL: terminating walreceiver process due to > administrator command > 04:00:29.780 [9679] LOG: invalid record length at 320/B95A1EE0: wanted > 24, got 0 > 04:00:29.783 [9679] LOG: redo done at 320/B95A1EA8 > 04:00:29.783 [9679] LOG: last completed transaction was at log time > 2021-03-03 03:57:46.466342+01 > 04:35:00.982 [9679] LOG: selected new timeline ID: 15 > 04:35:01.404 [9679] LOG: archive recovery complete > 04:35:02.337 [9662] LOG: database system is ready to accept connections > The cluster is "fairly large" with thousands of DBs (sic!) and ~1TB of data. Hm. WAL replay is already done at the "redo done" entry. There is a checkpoint after that, I believe, and there may be some effort to search for dead files as well. Still, if your I/O subsystem is better than a wet noodle, 35 minutes is a long time to finish that. One thing I'm not sure about is whether we try to do the checkpoint at maximum speed. If you have set GUC options to throttle checkpoint I/O hard, that could perhaps explain this. You could possibly learn more by strace'ing the startup process to see what it's doing. Also, what PG version is that exactly? regards, tom lane