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 1jYWS2-0007iG-EY for pgsql-general@arkaria.postgresql.org; Tue, 12 May 2020 15:04:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jYWS1-0001Ge-1a for pgsql-general@arkaria.postgresql.org; Tue, 12 May 2020 15:04:09 +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 1jYWRz-0001GX-Ik for pgsql-general@lists.postgresql.org; Tue, 12 May 2020 15:04:08 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jYWRu-00067D-HU for pgsql-general@postgresql.org; Tue, 12 May 2020 15:04:07 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E9D3D5C01C4; Tue, 12 May 2020 11:03:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 12 May 2020 11:03:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=Z +WOyj0HXmi3sFDvxjKOHwjRTZUOX2tvY/X1binwBpg=; b=Zas1uoB6UkdatGGYa fCmjseQ22i3rzXYdq+zXoZ8s2SHyPV3QaKFGtvdQwW704ue3Dr93aDhFOLTrKGfu RT3cALEeI3wAIJf0xlJVb+T6H9JEc7uv+avS3xy/dAeWYJqaihRJYifLCgXksE5X DFOO2pWfNBD16gq9E98NxBt4OC73OYN12uoUT7tdZA0+AWpFNGP1TqwbwRCWHzXG cV/NoS+fGyNBB7wpQSPMITKd3W1m5oiX3cxKdLJcNlYIReijslvfHGoogxK4D9sO jroZuiBGrqmVPXUE4mS2PkKyPEnKPi1jRqhtbW91zfdiQagpOuHRO9J4p7ddZzXR QEjuw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=Z+WOyj0HXmi3sFDvxjKOHwjRTZUOX2tvY/X1binwB pg=; b=XYI5eaDDYK9p951zPep5MMFd6L+MNFSKh+r7tsaJTFNeKz6UC1hrWinnZ trKgjI6osWDGYaeimU35qIIMg1EsqVyOaX5smZUhtk8PffQJ/yYsT+yGWinNSge3 YFolL1Kmen61R2FDsqhYHA31BojMNVLQuM5cXZeJz4hopqjfMpu7XS5lAEHRtfwX kR9GWepPlEd47jSLwFkNBNIOOY8tG7BmI10kyFDPJ7GnO6jOg7YwnnxE5ayTh2v4 bSy8+6WFc3YCcadAd88J9Hy7k5xojDLAdUIpYIP9xnpzCwOLyka50XdR0MWxGGDi /iisENB+3980TDtl/WwTCXNhZIAVQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrledvgdekudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuggftrfgrthhtvghrnhepveevfeevfeeugeffkeekhfegieeufffgteeujedvgffh ueejjefhkeejleegtdegnecukfhppeejhedrudejvddrhedrvdefudenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghv vghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 337243280063; Tue, 12 May 2020 11:03:59 -0400 (EDT) Subject: Re: pg_upgrade too slow on vacuum phase To: Kouber Saparev , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: <719b9852-6c4c-9999-8e12-76e62e20ccff@aklaver.com> Date: Tue, 12 May 2020 08:03:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/12/20 5:27 AM, Kouber Saparev wrote: > I am trying to upgrade PostgreSQL from 9.5 to 12 using pg_upgrade. > > /usr/lib/postgresql/12/bin/pg_upgrade \ >   --old-datadir=/var/lib/postgresql/9.5/main \ >   --new-datadir=/var/lib/postgresql/12/main \ >   --old-bindir=/usr/lib/postgresql/9.5/bin \ >   --new-bindir=/usr/lib/postgresql/12/bin \ >   --old-options '-c config_file=/etc/postgresql/9.5/main/postgresql.conf' \ >   --new-options '-c config_file=/etc/postgresql/12/main/postgresql.conf' \ >   --link \ >   --jobs=16 > > It takes 47 minutes for the upgrade to finish (for a 28 GB database). It > hangs on two particular steps: > > Analyzing all rows in the new cluster                       ok > Freezing all rows in the new cluster                        ok Are you sure? From here: ~/src/bin/pg_upgrade/pg_upgrade.c prepare_new_cluster(void) { /* * It would make more sense to freeze after loading the schema, but that * would cause us to lose the frozenids restored by the load. We use * --analyze so autovacuum doesn't update statistics later */ prep_status("Analyzing all rows in the new cluster"); exec_prog(UTILITY_LOG_FILE, NULL, true, true, "\"%s/vacuumdb\" %s --all --analyze %s", new_cluster.bindir, cluster_conn_opts(&new_cluster), log_opts.verbose ? "--verbose" : ""); check_ok(); /* -- NEW -- */ start_postmaster(&new_cluster, true); check_new_cluster(); report_clusters_compatible(); pg_log(PG_REPORT, "\n" "Performing Upgrade\n" "------------------\n"); prepare_new_cluster(); stop_postmaster(false); /* * Destructive Changes to New Cluster */ copy_xact_xlog_xid(); /* New now using xids of the old system */ /* -- NEW -- */ start_postmaster(&new_cluster, true); prepare_new_globals(); create_new_objects(); stop_postmaster(false); So the analyze(and freeze) are done before the new cluster are fully populated. Is the time being taken maybe for the loading schema/data portion? > > Which basically runs: > > vacuumdb --all --analyze > vacuumdb --all --freeze > > This is where all these 47 minutes are spent, yet I do not understand > neither why, nor how I can improve this part. Can I skip it somehow and > launch the vacuum manually afterwards? > > Per postgresql.conf, I gave: > > work_mem = 128MB > maintenance_work_mem = 8GB > max_parallel_maintenance_workers = 16 > max_parallel_workers = 16 > > The server has 44 GB available memory, and 24 cores. > > Do you have any ideas how to speed-up the entire process? > > -- > Kouber Saparev -- Adrian Klaver adrian.klaver@aklaver.com