Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ezJDw-000841-9m for pgsql-admin@arkaria.postgresql.org; Fri, 23 Mar 2018 09:43:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ezJDv-0004u7-1T for pgsql-admin@arkaria.postgresql.org; Fri, 23 Mar 2018 09:42:59 +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.89) (envelope-from ) id 1ezJDu-0004ty-N8 for pgsql-admin@lists.postgresql.org; Fri, 23 Mar 2018 09:42:58 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ezJDr-00077q-Ac for pgsql-admin@lists.postgresql.org; Fri, 23 Mar 2018 09:42:57 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 0283B40FAD; Fri, 23 Mar 2018 10:42:50 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id UgW0vP4HwvOM; Fri, 23 Mar 2018 10:42:48 +0100 (CET) Message-ID: <1521798167.2471.21.camel@cybertec.at> Subject: Re: Very long standby database startup after doing pg_basebackup From: Laurenz Albe To: Mario =?UTF-8?Q?Mahovli=C4=87?= Cc: pgsql-admin@lists.postgresql.org Date: Fri, 23 Mar 2018 10:42:47 +0100 In-Reply-To: References: <1521705321.2459.24.camel@cybertec.at> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mario Mahovlić wrote: > Thank you for the reply, we will try using perf to see what exactly is going on. > As for the log file all we get from it (even when log level is set to debug5) is this: > > > >>> Starting postgres... > > LOG: database system was interrupted; last known up at 2018-03-20 08:25:18 UTC > > FATAL: the database system is starting up > > psql: FATAL: the database system is starting up > > >>> Db replication is still not accessible on *NODE* (trying 17255 times) > > ..... * This goes on for 6 hours * > > LOG: entering standby mode > > LOG: redo starts at 4B/A000028 > > LOG: consistent recovery state reached at 4B/A000130 > > LOG: database system is ready to accept read only connections > > LOG: started streaming WAL from primary at 4B/B000000 on timeline 35 > > DEBUG: CommitTransaction > > DEBUG: name: unnamed; blockState: STARTED; state: INPROGR, xid/subid/cid: 0/1/0, nestlvl: 1, children: > > DEBUG: StartTransactionCommand > > DEBUG: StartTransaction > > ... > > Lines with >>> are from our own scripts we use for startup and database management. > > So basically on startup all we get in logs is: > LOG: database system was interrupted; last known up at 2018-03-20 08:25:18 UTC > FATAL: the database system is starting up -> every time we query db until it starts up successfully > > Is there any other way to log more detail during postgres startup? > > As i said in initial mail we use -X stream option when doing pg_basebackup, here is exact pg_basebackup command that is being run: > > > INFO: executing: '/usr/lib/postgresql/9.6/bin/pg_basebackup -l "repmgr base backup" -D /var/lib/postgresql/data -h *NODE_IP* -p *PORT* -U *USER* -c fast -X stream ' > > So yes, we do copy the WAL files, and there is at most 30GB of them (that is how much we keep), however even if database had to restore all of them 6 hours seems a bit much. Sorry, I missed the pg_basebackup command. The strange thing is that you see the message "entering standby mode" only six hours after startup. This message is written when recovery *starts*, so (as expected) it is not that recovery takes long. By the way, you should add %m to your log_line_prefix so we see *when* messages are logged.