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 1wd25j-003q0g-1P for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jun 2026 08:39:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wd25i-009yTz-0O for pgsql-bugs@arkaria.postgresql.org; Fri, 26 Jun 2026 08:39:14 +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 1wd1xS-009yCB-1O for pgsql-bugs@lists.postgresql.org; Fri, 26 Jun 2026 08:30:42 +0000 Received: from smtpout08.a1.net ([80.75.33.8] helo=smtpout00.a1.net) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wd1xQ-00000000JHG-01B8 for pgsql-bugs@lists.postgresql.org; Fri, 26 Jun 2026 08:30:41 +0000 Received: from laurenz.albe-K4N0CV00F97414D (unknown [152.96.94.163]) by smtpout00.a1.net (Postfix) with ESMTPSA id 4gmplT0yswzGrqyn; Fri, 26 Jun 2026 10:30:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aon.at; s=resmail1; t=1782462635; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qeUjioIaluKKYcXeaPJ97R8vF5Cak+5QyPpUVC9tkcw=; b=SY6i9nFRLUiLnzEGWQsEYbGQPlfeP56froI965gwCk8ZjPjrjUSyYv0+1dsARYEEUa/+IP +TXWeqJflOFFjQgzQSiW4hWq9iwW3Vgz2RsuS7NPV1wR5xRWtuVxtM6XFdg2AlfYiHkL01 xySw7B9DcI30lC8IC9SLWxKNxELrfs1KPpfWcFxH0tRD/9B+P4tTBBBt/sQhTkAHDmLwpP 8J3FUc9vCfUblwpemoSBXIEGDUUtMJWXgpIjLD5wmthC43E7ega0+gOHK7tcv4VSbgT/iv 5UzXi4cTK8344yrjxB97IVI5WhKoKf7kwLJeRerFoObnilvpIT2ZtOn3XN/7lr5EMZDRdd fdrc7sQpw7zBSMd0F5wcVGHg2oAHyP7GTs3y7GZRFz7MpKPs46ZxfmnuOui6Xm11oRL+AO ACbSfsUOWLnrZ95vPlModU9uEGH/adWbQnh2QViceqjSSS9xNO+OY4iLMD13arB3dfqOFK wgPKZbVNCEtc2G2nk3VrY7U4HIU96JRCuZm9LbrZfv1CZO9UnlV/v4h/gN4RYbcnpcJeTj dpEjBgjJvf0p0u+1DnJm8U1sp5JK9vsIbhc0tQzqt2alC/ba3oF4zjaOOvYQ1nUGBOfM/E VChGLZe0FI+RIO0Yggv3PKRq0vtb88Um+xsSPh0ZmP7bMgI+Uae+s= Message-ID: Subject: Re: BUG #19483: pg_upgrade fails with orphan records in pg_init_priv catalog table From: Laurenz Albe To: =?ISO-8859-1?Q?H=FCseyin?= Demir Cc: Tom Lane , Greg Sabino Mullane , pgsql-bugs@lists.postgresql.org Date: Fri, 26 Jun 2026 10:30:28 +0200 In-Reply-To: References: <19483-80de42dc4e62cfd6@postgresql.org> <104812.1780847519@sss.pgh.pa.us> <5184088806e70ed5db7e83bd6540a016b3802c1d.camel@cybertec.at> <0d7531c192859057c6aad54c89a8d453376bd00c.camel@cybertec.at> <592839.1782153054@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 X-Spam-Level: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2026-06-26 at 08:56 +0200, H=C3=BCseyin Demir wrote: > > > This v6 patch adds a SAFE_INITPRIVS macro that filters aclitem[] > > > arrays server-side by checking that each entry's grantor and grantee > > > OID still exists in pg_roles. It is applied in exactly two queries: > > >=20 > > > 1. getAdditionalACLs() -- the one-time fetch of pg_init_privs at star= tup > > > 2. dumpTable() column ACL prepared statement -- per-table column init= privs > >=20 > > No, that's not good. If you are running the complicated subquery for > > every table dumped, you are re-introducing the performance regression > > from the v4 patch that Tom justly complained about. >=20 > The correlated subquery in getAdditionalACLs adds overhead > proportional to pg_init_privs row count =C3=97 aclitems per row, with eac= h > check being an indexed OID lookup. For a database with 5,000 > pg_init_privs rows this is probably a few extra milliseconds. I added > performance test results with v6. I think it's a sustainable operation > but If I'm missing sth. let me know. I have no problem with the subquery being in getAdditionalACLs(). But dumpTable() is executed once per table that gets dumped, right? So the complicated subquery will run once per table. > > Here is my latest idea (hold your noses): > > Instead of having pg_dump query "FROM pg_catalog.pg_init_privs pip", > > how about writing "(FROM (VALUES (...), (...), ...) AS pip", where the > > VALUES clause is composed from a query against pg_init_privs run once > > at the beginning of pg_dump that excludes the bad entries? > > Critizism I forsee is that a) this is ugly and b) very long VALUES > > statements might also constitute a performance regression. > > However, I have yet to see an extension that produces a hundred > > initial privilege entries. >=20 > I'm not against this approach but the tradeoff is the same with v6 I > suppose. Since the overhead of processing the full VALUES clause on > every EXECUTE is unnecessary. v6 goes directly to pg_init_privs > indexed by objoid =3D $1. Ah, so you are saying that the effort per table will be much less. Could you measure the difference with a database with - say - 10000 tables? > But definitely we can prepare a new patch to cover these expectations. Let's agree on the proper approach before you go to the effort of writing another patch. > With that in mind, I would like to propose splitting the work into two > separate patches: >=20 > 1. pg_dump fix (backpatch to 14): the v6 SQL OID-level filter. Works > on any server >=3D 9.6 without requiring a source-side update. Fixes the > known breakage for users upgrading from pre-17 clusters that > accumulated dangling entries via DROP ROLE. >=20 > 2. putid() fix (HEAD only): improve aclitemout so that a dangling OID > is rendered in a form that is unambiguously distinct from a valid role > name. This is the right long-term fix for the text representation and > would benefit any future tool that processes aclitem output. It is > independent of the pg_dump fix and does not need to be backpatched for > patch 1 to be correct. I think that we all agree on that. > New dangling entries will not live on modern servers. However, users > upgrading from pre-17 clusters may have years of accumulated dangling > entries that pg_upgrade will carry forward silently. ... or rather fail doing so ... > The pg_dump fix > is a one-time for that migration window. Right. > Does this split make sense to the reviewers? If so, I will prepare v7 > of the pg_dump patch (incorporating any further feedback on v6) and a > separate patch for the putid() fix in HEAD. It makes sense to me. I'd say that your v6 patch is fine if the performance impact can be shown to be small. Yours, Laurenz Albe