public inbox for [email protected]  
help / color / mirror / Atom feed
From: vaibhave postgres <[email protected]>
To: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: pg_restore: fails to restore post-data items due to circular FK deadlock
Date: Sun, 25 Jan 2026 16:24:51 +0530
Message-ID: <CAM_eQjxFzak3yGrNbuj0ytSd4WexX5Wehs1ukqDG8mONK9EruQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAM_eQjwLbRsdPF2=Yip05QNb-tyb2LXkAqfSkuVKpZRNhRmJmA@mail.gmail.com>
	<[email protected]>

On Thu, May 30, 2024 at 11:59 PM Tom Lane <[email protected]> wrote:

> vaibhave postgres <[email protected]> writes:
> > 1. Create a database which has circular foreign key dependencies. (or use
> > the sql script which I have shared), restore the pre-data section first.
> > 2. pg_dump -Fc *--section=post-data*
> > 3. pg_restore --jobs > 1
>
> > pg_restore fails to record the dependency between the foreign keys and
> > tries to process them in parallel (see the attached log file for details)
>
> The reason this works in other cases is that pg_restore recognizes
> that two ADD CONSTRAINT steps shouldn't be run concurrently when they
> have dependencies on the same table(s).  However, when you use
> --section=post-data to create the dump file, there are no entries for
> the tables.
>
> So this seems like a "don't do that" case.  You could get the results
> you want by using --schema-only at dump time and then using
> --section=post-data as a pg_restore switch.  (That'd also avoid the
> need to make two separate dump files.)
>
> Possibly we should add something to the docs about this.
>
>                         regards, tom lane
>


Attachments:

  [application/octet-stream] 0001-doc-warn-about-post-data-only-schema-dumps-with-para.patch (1.4K, 3-0001-doc-warn-about-post-data-only-schema-dumps-with-para.patch)
  download | inline diff:
From 2d438278debf43215e2185611d2f996d09886268 Mon Sep 17 00:00:00 2001
From: Vaibhave Sekar <[email protected]>
Date: Sun, 25 Jan 2026 10:54:00 +0000
Subject: [PATCH] doc: warn about post-data-only schema dumps with parallel
 restore.

---
 doc/src/sgml/ref/pg_dump.sgml | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index 5ba167b33e7..cc410e00d7f 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -1272,6 +1272,17 @@ PostgreSQL documentation
           and constraints other than validated check constraints.
           Pre-data items include all other data definition items.
          </para>
+           <note>
+            <para>
+             Archives that contain only <option>post-data</option> omit table entries.
+             When such an archive is restored in parallel, constraint creation can
+             fail because <application>pg_restore</application> cannot order foreign
+             keys that depend on tables not present in the archive.  To avoid this,
+             take a schema-inclusive dump (for example, <option>--schema-only</option>
+             or the default), then filter sections at restore time, or restore the
+             post-data-only archive with <option>-j1</option>.
+            </para>
+           </note>
        </listitem>
      </varlistentry>
 
-- 
2.43.0



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: pg_restore: fails to restore post-data items due to circular FK deadlock
  In-Reply-To: <CAM_eQjxFzak3yGrNbuj0ytSd4WexX5Wehs1ukqDG8mONK9EruQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox