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 1oRCDb-0004pJ-TF for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Aug 2022 12:44:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oRCDa-0002Kz-6A for pgsql-bugs@arkaria.postgresql.org; Thu, 25 Aug 2022 12:44:18 +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 1oRCDZ-0002Kp-S6 for pgsql-bugs@lists.postgresql.org; Thu, 25 Aug 2022 12:44:17 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oRCDV-0007LZ-BC for pgsql-bugs@lists.postgresql.org; Thu, 25 Aug 2022 12:44:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=Content-Type:MIME-Version:Reply-To:Message-ID:Subject:To: Sender:From:Date:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=lB6uliBikETnMWT6L/ko7WeFxUj+qjyLvMTI2rExpgg=; b=Sd5BnYY9e8PdASdwRZivb+07y+ RQeG16Xbhttx96rndMdvbe18yEK7mKnQ6Pr4Lq2iM1+PMnPrAPYi5sCwd6+16kxRhAbZbZrOGWw10 oJHCePTWu7Bp2czyvUMciG+E2b8NFXNWSamljpx5XK0y6Vs0Ax1j1c5wfuS2a4J8d/2o=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1oRCDU-0004IL-2o for pgsql-bugs@lists.postgresql.org; Thu, 25 Aug 2022 14:44:12 +0200 Date: Thu, 25 Aug 2022 14:44:11 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: PostgreSQL mailing lists Subject: pg_restore deadlocks with itself Message-ID: <20220825124411.GA8257@depesz.com> Reply-To: depesz@depesz.com MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I have Pg 14.4 on arm64, and I'm loading schema dump from pg12. Specifically, command to run it is: sudo -u postgres pg_restore -j 64 -d database -L /tmp/schema-post-data.nopkey.list /tmp/schema-post-data.dump where /tmp/schema-post-data.dump is dump made using: sudo -u postgres pg_dump --schema-only --compress=9 --format=c --section='post-data' --schema='*(something|else|xxx)*' database and /tmp/schema-post-data.nopkey.list is made using: #v+ pkey_regexp='^\d+; \d+ \d+ CONSTRAINT \S+ \S+ \S+_pkey ' pg_restore -l "${local_dump_dir}/schema-post-data.dump" | grep -vP "${pkey_regexp}" > "${local_dump_dir}/schema-post-data.nopkey.list" #v- The thing is that the list file has 7676 lines, out of which 2313 are foreign keys. database has basically 3 schemas, and fkeys NEVER cross schema. When loading the dump I got reported 4 errors, but log shows 2 deadlocks. perhaps all sides got cancelled, not sure, will investigate further, but logs show: 2022-08-24 20:01:04.466 UTC,"postgres","database",3343477,"[local]",630624ad.330475,42,"ALTER TABLE waiting",2022-08-24 13:16:29 UTC,21/1932,0,LOG,00000,"process 3343477 detected deadlock while waiting for ShareRowExclusiveLock on relation 742617610 of database 16641 after 1000.647 ms","Process holding the lock: 3587718. Wait queue: .",,,,,"ALTER TABLE ONLY some_schema.table_a_o ADD CONSTRAINT table_a_o_q_id_fk FOREIGN KEY (q_id) REFERENCES some_schema.table_q(id); ",,,"pg_restore","client backend",,3355460102417501954 2022-08-24 20:01:50.291 UTC,"postgres","database",3343477,"[local]",630624ad.330475,46,"ALTER TABLE waiting",2022-08-24 13:16:29 UTC,21/1933,0,LOG,00000,"process 3343477 detected deadlock while waiting for ShareRowExclusiveLock on relation 742617610 of database 16641 after 1000.030 ms","Process holding the lock: 3587718. Wait queue: .",,,,,"ALTER TABLE ONLY some_schema.table_a ADD CONSTRAINT fk_rails_46718e626a FOREIGN KEY (migrate_from_id) REFERENCES some_schema.table_q(id); ",,,"pg_restore","client backend",,-2548896815899838768 Now, I know I can fix the situation by adding missing fkeys myself, but I don't think pg_restore should be putting itself in deadlock. Best regards, depesz