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 1eyv4P-0004OU-Dw for pgsql-admin@arkaria.postgresql.org; Thu, 22 Mar 2018 07:55:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eyv4O-0005lA-53 for pgsql-admin@arkaria.postgresql.org; Thu, 22 Mar 2018 07:55:32 +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 1eyv4N-0005l1-Pr for pgsql-admin@lists.postgresql.org; Thu, 22 Mar 2018 07:55:31 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eyv4J-0005PY-Qc for pgsql-admin@lists.postgresql.org; Thu, 22 Mar 2018 07:55:30 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 0B901429EE; Thu, 22 Mar 2018 08:55:24 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id H0V9mY9k6QT0; Thu, 22 Mar 2018 08:55:22 +0100 (CET) Message-ID: <1521705321.2459.24.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?= , pgsql-admin@lists.postgresql.org Date: Thu, 22 Mar 2018 08:55:21 +0100 In-Reply-To: References: 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: > However, our issue is not with primary cloning, but with database startup after > clone/basebackup is done. > Startup of standby database is successful but it takes around 6 hours, during > which time all we get from DB is: FATAL: the database system is starting up. > We have noticed that this startup process uses only 1 cpu core on our machine > which has 8. > > Our database size is around 570GB, and we are using schema per tenant data > distribution, so we have separate schemas for each of the users of our > application, as it suits our needs well. > Because of this our database has about 40000 schemas with 5 tables per each > schema. > We suspect the reason behind this long startup is amount of data and/or large > number of schemas/tables on database, however we would like to confirm that somehow. > > So our questions are following: > What could be possible reasons for startup as long as this? > How can we figure out what exactly does postgres startup process do all this time, > is there any documentation on what exactly does postgres database do on startup as > we have not found any info on this? > Is there any way to speed up this startup process? > Can we mitigate this startup time in cases when we do planned switchover for > maintenance by using pg_rewind instead of pulling all data from primary again? > So if we shut down the database gracefully and use pg_rewind will startup process > be faster? You could use "perf top" to see where the time is spent or have a look at the PostgeSQL log file. pg_basebackup creates a checkpoint when it starts, so checkpoints that happen too rarely cannot be the problem. Did you use "pg_basebackup -X stream" to copy the WAL files along with the data? If yes, is there a lot of them? If no, how do you restore the required WAL files? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com