Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u01x8-00AJsw-2H for pgsql-general@arkaria.postgresql.org; Wed, 02 Apr 2025 17:32:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u01x6-00GbzA-Ga for pgsql-general@arkaria.postgresql.org; Wed, 02 Apr 2025 17:32:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u01x6-00Gbyt-2F for pgsql-general@lists.postgresql.org; Wed, 02 Apr 2025 17:32:36 +0000 Received: from mout.gmx.net ([212.227.15.18]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u01x3-0030j1-3A for pgsql-general@lists.postgresql.org; Wed, 02 Apr 2025 17:32:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1743615152; x=1744219952; i=jimis@gmx.net; bh=OOBhlCsle8ghCK+CE7qtkHodG/Vt3RuiRAOwbAJLGeY=; h=X-UI-Sender-Class:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=kLuhXPiHJmsxHbNrkTcMmdt42En4oE4+Vr84jpUUUXl/6ofgP/P41rOGLKYyCb+b ojOzwO6UGvO0Gj1W1cIRyuzRDJ9DQZTixgJu2sU3bdAeuxwm45adOOpLbGW8LLnVB 0TowMSSL/gZe4s4QpPH7l9CpvvCHBzLSz3MLWzeNOkG4IiMpKAOh+MnbEsw/0sra2 N2OkklhbzCYjYS4gEkjtNm4D87CSg8RhzZsYPqa8gXjwk1oTh92bHeqADb+5N9Sd1 ajuJHw6cj4OkQYVvB7sP4UvBSTE3IyeEdkOHfLgE9oScbAA+DijpSx8M8DX8tR+0x z1DxLhmqkPCRaY6XXw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.9.70.81] ([185.55.106.54]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MFKGZ-1tt77Z1kAT-005xxj for ; Wed, 02 Apr 2025 19:32:32 +0200 Date: Wed, 2 Apr 2025 19:32:31 +0200 (CEST) From: Dimitrios Apostolou To: pgsql-general@lists.postgresql.org Subject: Performance issues during pg_restore -j with big partitioned table Message-ID: <84379bfb-bbda-84e6-cacc-e863ba9d6c37@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Provags-ID: V03:K1:tl4cWzgDN3H8oV/UFIsmKTUs6fA4eJSdASPhvF/S0YToequoczz I3Zr3fkpX/+xyG1kBsC9PR2owmcoPCw5NU+Axc+2kMm/fTKy0s8uyLpYv5qRdPLUaArN0Il FoG4UMRe+89QkVSzJxecmn9uPwwxq4eKAMGKylh/b5bDP6M7/o0WqZT04BTxVzGLnjO/FAm vPCZG4zlDmajZm1TE97Mg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:BaMygxJ1kA4=;NmYZSrT6PYzsaaOCjLpRbTNft8x /uMg11HEy58PBLlVtkV2/l5mjM7K2vqHg3OxL7iooMnNDp7cylVwqo3u+nnA59oD5Sxbya+XI JlUB2+XoyMHZdYQNe+jJ6lIOP6mQf44ea++hipLtNzsVyb615gJ28lNsuZn3mkAbMzGVHTfX4 5iEnP+s07th8WB/SN+Vamhp3lkt1bjE/N9pM2hCcIkU8oJi0SRs6WO7KaiO8FEwCu6fQIRM/1 kUgY0fScL3Zmqgs5ZnftKC7vhwX7EUS+zWkkcGw9KYzUEukjV+8wcA9x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3VFTkLk+0GdKb9JA+sdZGf6I7ciMJ5g1cq8XZMJzD1AYC7Ueuloo4k fQt1PaqUPdObxlqd25+lAyH7DBc8B8BiU78wZ+RkO6bAxSNpAktc2R0Q2W1optqaL8zENJwZQ +2f8eYO9utH+1nwiK7YepT0TZfig= Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello list. My database includes one table with 1000 partitions, all of them rather sizeable. I run: pg_restore -j12 --no-tablespaces --disable-triggers --exit-on-error --n= o-owner --no-privileges -n public -d newdb custom_format_dump.pgdump Right now after 24h of restore, I notice weird behaviour, so I have several questions about it: + 11 postgres backend processes are sleeping as "TRUNCATE TABLE waiting". I see that they are waiting to issue a TRUNCATE for one of the partitions and then COPY data to it. Checking the log I see that several partitions have already been copied finished, but many more are left to start. Why is a TRUNCATE needed at the start of a partition's COPY phase? I didn't issue a --clean on the command line (I don't need it as my database is newly created), and I don't see a mention of related TRUNCATE in the pg_restore manual. + 1 postgres backend process is doing: ALTER TABLE the_master_partitioned_table ADD CONSTRAINT ... FOREIGN KEY (columnX) REFERENCES another_table(columnX) According to my logs this started right after COPY DATA for another_table was finished. And apparently it has a lock on the_master_partitioned_table that all other TRUNCATE have to wait for. Is this a bug in the dependency resolution? Wouldn't it make sense for this to wait until all 1000 partitions have finished their COPY DATA phase? + Investigating why the above ALTER TABLE takes so long, I notice that it is issuing a lot of writes to the WAL. Digging deeper shows a lot of time spent in SetHintBits(). Is there a way to avoid that in a clean pg_restore? Thanks in advance, Dimitris