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.96) (envelope-from ) id 1vaH0W-006Dyv-0C for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Dec 2025 17:26:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vaH0U-00HZdL-04 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Dec 2025 17:26:10 +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.96) (envelope-from ) id 1vaH0T-00HZdD-28 for pgsql-hackers@lists.postgresql.org; Mon, 29 Dec 2025 17:26:10 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vaH0P-003Cyz-2N for pgsql-hackers@postgresql.org; Mon, 29 Dec 2025 17:26:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5BTHQ1SW2885945; Mon, 29 Dec 2025 12:26:01 -0500 From: Tom Lane To: Nathan Bossart cc: Michael Paquier , Euler Taveira , pgsql-hackers Subject: Re: improve performance of pg_dump with many sequences In-reply-to: References: <3578088.1721242766@sss.pgh.pa.us> <3585715.1721243507@sss.pgh.pa.us> <3640163.1721275101@sss.pgh.pa.us> Comments: In-reply-to Nathan Bossart message dated "Wed, 31 Jul 2024 10:19:01 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2885943.1767029161.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 29 Dec 2025 12:26:01 -0500 Message-ID: <2885944.1767029161@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathan Bossart writes: > Committed. In the no-good-deed-goes-unpunished department: pg_dump's use of pg_get_sequence_data() (nee pg_sequence_read_tuple()) is evidently responsible for the complaint in bug #19365 [1] that pg_dump can no longer survive concurrent sequence drops. Given that that function already silently returns NULLs if the sequence isn't readable for other reasons, I think it'd be sane to make it silently return NULL if the sequence isn't there anymore. Unfortunately, that looks like it'd require nontrivial restructuring of init_sequence(). Or maybe we could make it not use init_sequence()? For the moment a plain try_relation_open and check that it's a sequence should do, but I'm not sure how that'd fit into people's plans for future improvement of the sequence API. There are other reasons not to like use of init_sequence in this code path, too. pg_dump's session will build a SeqTable entry for every sequence in the database, which there could be a lot of, and it will acquire RowExclusiveLock on every sequence and hold that to the end of the dump, which seems likely to be troublesome from a concurrency standpoint. Since pg_get_sequence_data is a read-only operation this lock level feels wrong. BTW, I'm unconvinced that pg_dump behaves sanely when this function does return nulls. I think the ideal thing would be for it to skip issuing setval(), but right now it looks like it will issue one with garbage values. regards, tom lane [1] https://www.postgresql.org/message-id/19365-6245240d8b926327%40postgre= sql.org