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 1u0grG-005ygk-Gk for pgsql-general@arkaria.postgresql.org; Fri, 04 Apr 2025 13:13:18 +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 1u0grE-0001hf-E1 for pgsql-general@arkaria.postgresql.org; Fri, 04 Apr 2025 13:13:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0grE-0001gT-0P for pgsql-general@lists.postgresql.org; Fri, 04 Apr 2025 13:13:16 +0000 Received: from mout.gmx.net ([212.227.15.19]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0grB-002v7K-2O for pgsql-general@lists.postgresql.org; Fri, 04 Apr 2025 13:13:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1743772391; x=1744377191; i=jimis@gmx.net; bh=V5xQF73eYmTessBnfPQuTJSqGCf9o8Xd7SsMmDbCVrU=; h=X-UI-Sender-Class:Date:From:To:Subject:In-Reply-To:Message-ID: References:MIME-Version:Content-Type:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=SX1TxW0YBTQWm4/dPNQMpB5JrjqHguqgb73VHpelJ8N7HaXecw05POWBMyIuandK 8YfZA9T4ZQ5CJDv2X7LtkEx9ojCvK2s9tRExHlwYnEKMe7f+ThcvDHlKxd2LdpdwQ R4rlU2MQEBI2qqOvEVNLnSk3VUCxfz4BdjewPT8YoyRKI8WXKwbJbITeM87haLzWL K6h9Vy32LhP41jN3SjrueNqF34fN4FfXcmuzu1G2NNfsdWx0vkTWEnvx732gYRttn ll99BNB3gpGSCjM5mdwoSjCDv1U4FWmCmRniVFZQciqV3URTnl5XhFBNGmQ0M+HlC Gishzmc3EJnq/h6DsQ== 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 1MKsjH-1tfRc20c73-00Qsel for ; Fri, 04 Apr 2025 15:13:11 +0200 Date: Fri, 4 Apr 2025 15:13:09 +0200 (CEST) From: Dimitrios Apostolou To: pgsql-general@lists.postgresql.org Subject: Re: Performance issues during pg_restore -j with big partitioned table In-Reply-To: <84379bfb-bbda-84e6-cacc-e863ba9d6c37@gmx.net> Message-ID: <67469c1c-38bc-7d94-918a-67033f5dd731@gmx.net> References: <84379bfb-bbda-84e6-cacc-e863ba9d6c37@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Provags-ID: V03:K1:xk6I2DkhdHdjmKOvPpggZkTjfL6ef1Kn/iv1orGfnrF30ResPvS 3Zfq1fXnPQlVJbSbNwc1fAJfOvlh9E6Jsj7j7hB4VSY/ZU9z37r+SSr/kMhrfQk2t7IkYId dhJPhp9NeEMMpO57ccRwkcpSNT4mOd77+wwdbTG+udSueSIlEvapIYBqh2c9HFfgShBDyz0 THG2tRtPvVYG8tiqmAyUg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:1AVlbgujL9w=;cvN71ZExidixF5HFN4+WPd5GV+4 1Qy0nVusBxDRX/uBJCCh9d145O+0uV5pAddSPntPne8VXggk+/+cvtrQONSllxZOU7qZIK7mQ ++zVdIh0kDbvk4pXgOcgQafF83LHWzFOsvDS7t0HF/1AYkyvZrbn7Z+laWuHXNwkdfO/O0lg9 abC8zLWREiKPzDLbZjeExYWv/enwH2leBD3v5ZA+ef7Ba8sFnmdh+X5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FDxyBOo/fDgBsMQbqd1Tk0JaGcdxvNAbzUiDiOkHnziGqfB4hvVq YeU80RoOAQJISSreiN0rccvmhvjg2UknlfuSYeXrelyEXg3Tu+hqsJdumDrWCjNDrpRLJ3QCl Hj75LiwtIEr5Ji3S6jUu9nBa0uR+oevMfIBloMxGtZDM46DHBfOuzr+mZ8vOv1wqrW0Yduj3/ hNr1LUw== Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, 2 Apr 2025, Dimitrios Apostolou wrote: > Hello list. > > My database includes one table with 1000 partitions, all of them rather I was not clear here: my database dump has all that, and the database is brand new and empty. > sizeable. I run: > > pg_restore -j12 --no-tablespaces --disable-triggers --exit-on-error > --no-owner --no-privileges -n public -d newdb custom_format_dump.pgdump > > Right now after 24h of restore, I notice weird behaviour, so I have seve= ral > 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? Trying again, pg_restore exited with error after almost 24h: pg_restore: while PROCESSING TOC: pg_restore: from TOC entry 8904; 2606 16529 CONSTRAINT test_runs_raw test_= runs_raw_partitioned_pkey pg_restore: error: could not execute query: ERROR: deadlock detected DETAIL: Process 465409 waits for AccessExclusiveLock on relation 44437 of= database 44090; blocked by process 465408. Process 465408 waits for AccessShareLock on relation 44383 of database 440= 90; blocked by process 465409. HINT: See server log for query details. =46rom the logs I see that: + Process 465409 waits for AccessExclusiveLock on relation 44437 of databa= se 44090; blocked by process 465408. --> 44437 is test_runs_raw__part_max10120k (a single partition) + Process 465408 waits for AccessShareLock on relation 44383 of databa= se 44090; blocked by process 465409. --> 44383 is test_runs_raw (the master partitioned table) Process 465409: ALTER TABLE ONLY public.test_runs_raw ADD CONSTRAINT test_runs_raw_partitioned_pkey PRIMARY KEY (workitem_n= , run_n); Process 465408: COPY public.test_runs_raw__part_max10120k(...) FROM stdin; Bug? This happened on a postgres compiled from last week's master branch. The dump I'm trying to restore is from postgres 17.4. Thanks Dimitris