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 1wb3dm-002GaT-2p for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Jun 2026 21:54: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 1wb3cm-002M9A-1D for pgsql-bugs@arkaria.postgresql.org; Sat, 20 Jun 2026 21:53:12 +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 1wb3cl-002M91-37 for pgsql-bugs@lists.postgresql.org; Sat, 20 Jun 2026 21:53:12 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wb3ck-00000001LkU-19am for pgsql-bugs@lists.postgresql.org; Sat, 20 Jun 2026 21:53:10 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-490ac357c55so33138355e9.1 for ; Sat, 20 Jun 2026 14:53:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1781992383; x=1782597183; darn=lists.postgresql.org; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=LAgbJpl7wONoynvkxjQoZcJ+jsfFuNbonp9UViD+Oy4=; b=fMFyv9K+mwSMmeM42fM1FxibYprX44ulX/i8mSZ0N0Ly8TY0Tn38+2OMeG79uO1p5C 3vsSm2YvR3i04KU5w96mXwH1Gdzmz3Kyor/yF+MqjD4RFH9OAhbu6RxS+o5zesDpH+lK EVMHWfyfVcm+ccI9Tr9u/QoX7OsSFxrDDbl5DB9C2EJC0nYntNxIzCxyMrAo8HDQJBcY 6MQVuB7XKzwXxrkI/2QMs2IedqYPV6OjjxTxmx5PyNYZ2u4MMsmYKiPtgxo/sfssRKhp ydDR3CnANpK9qVoMBSdmPru2q1mK2fTfINmS9GUjl5kpkQXuNn0FAqLqol5QVyHXsDGQ JAOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781992383; x=1782597183; h=mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=LAgbJpl7wONoynvkxjQoZcJ+jsfFuNbonp9UViD+Oy4=; b=moypFyC8dqrO4bBnQ0yKaisDooYk9JTinD4Hjn1tOm7w6kelcqMSskLHzbWy+WZ25y 3Q+gzK0QhdEAYCQxBrP8kHs076T6kMa1ui/JZ+sNgPLzcGTbSgUwFQIZO+0fHnHlB1Ut l7mXMNWlgDjaGZ2ntTz5BQPyd3BCTtiy2zdAzw8E6DMzgDR/8Knc+b+EI4rcok4Cg3MQ YoUo9fP7d6swcCaPOgpySnqoyro2081VC6udMGeC+jyMeALsU1QO6QM0DObV/P2sYRLd Zf88nogQ/O8f+d60odaSigzSoiQkqtB48AcGuyas1ht9nRe5HzXiuV2vwAg822IkauZe ZZWg== X-Forwarded-Encrypted: i=1; AFNElJ9O/yuGE+ZHHzv5FN2gRLGivuDsjOiW5Qq3fq6iN1Sq5gL6vVKMAyZNes5GJEszpmXpxMBCwp9HiSMQ@lists.postgresql.org X-Gm-Message-State: AOJu0YzJlfxT7P4djOc2wT3qL00q920WsVPNWIccMAWzY3rOQ36iPNQH GEgEkKq/SW98GHm936vSc5lveS+zft/Ji0df/OaN1pt+BFGym/VMPUxneGU2//x33Qc= X-Gm-Gg: AfdE7ck0ekbcQBU6HKQfvjifnfc4D4TCKrg8Bh93pD9PzNiQm8W0YHC0I6MQXiGg0rD DXIpJBCtiD9TX7oeGp6KvtGHMNBrfrW+YWfXc8DCyDgzJWjmpGQ71mn1NdzKOtwZpvlqDxpLD/O d31Nw+IiVIOY/R7rV+0ZncL20mJh/8G18ADw1aw5f3EU29o/uIEfoY+/Lz71Ha30yeVqK1tJ/VQ NKfRRGMnsUaVEcKTN8vvPPDcHqWUez6IJj5s0n+n5LZI3sHwaJ0mar+mm6iGjo8zkn3628BsuOG RRGvcgtYAv6S3fiz0jiQUJkua4GYDHpqdHZvF4rSe9AMCl4QaE57Q+Kv40KLyfAz6REXLBeR8m4 SgGC2Jh5i4ciK5Ed6gj2pI+FNz2aepDHwqE8U7GB1B6fjzb4k6Aw6grDTQcOm4odzo+N1genUG5 1GN1lxss31QQ6ku/UWZhhC7kbDvzM1/XzE1ouNrsMehFA= X-Received: by 2002:a05:600c:a115:b0:492:37a5:422d with SMTP id 5b1f17b1804b1-49240df7c3fmr147664235e9.7.1781992383180; Sat, 20 Jun 2026 14:53:03 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:270:b5dd:d75a:6339:d2c8:1d69]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-466667881bfsm12112470f8f.22.2026.06.20.14.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 14:53:02 -0700 (PDT) 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 , Tom Lane Cc: Greg Sabino Mullane , pgsql-bugs@lists.postgresql.org Date: Sat, 20 Jun 2026 23:53:01 +0200 In-Reply-To: References: <19483-80de42dc4e62cfd6@postgresql.org> <104812.1780847519@sss.pgh.pa.us> Content-Type: multipart/mixed; boundary="=-AxJGncXanuvfxNCLJPDe" User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-AxJGncXanuvfxNCLJPDe Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2026-06-19 at 09:40 +0200, H=C3=BCseyin Demir wrote: > Found a problem and fixed it quickly. I think that we need something like this fix, because a failing upgrade is a bug. For the same reason I think that the fix should be backpatched. I looked at your patch and found that the query you added doesn't cover the important case where the grantor is a non-existing role (that is, the original extension owner was dropped). The grantor appears in SET SESSION AUTHORIZATION commands in the dump, which make the restore and consequently the upgrade fail. I suggest a query like this one: SELECT pip.objoid, pip.classoid, pip.objsubid, pip.privtype, NULLIF( ARRAY( SELECT elt FROM pg_catalog.unnest(pip.initprivs) AS elt /* that is valid, that is, there is not ... */ WHERE NOT EXISTS ( /* ... a non-existing grantor ... */ SELECT 1 FROM pg_catalog.aclexplode(ARRAY[elt]) ace WHERE NOT EXISTS ( SELECT 1 FROM pg_catalog.pg_roles AS r1 WHERE r1.oid =3D ace.grantor ) /* ... or a non-existing grantee that isn't 0 */ OR ace.grantee <> 0 AND NOT EXISTS ( SELECT 1 FROM pg_catalog.pg_roles AS r2 WHERE r2.oid =3D ace.grantee ) ) ), ARRAY[]::pg_catalog.aclitem[] ) AS initprivs FROM pg_catalog.pg_init_privs pip; You see that I added some comments, because the query is almost incomprehensible. I couldn't think of a more elegant solution. I think that you also should add an extensive code comment that explains why this hack is needed. I am undecided if the regression test with the artificially created broken initial privileges is a good idea or not. After all, we are not testing the real thing here (for example, the test didn't catch the omission described above). I am attaching a test extension that I installed in a v14 database to test your patch; perhaps you'll find it useful. It creates all kinds of objects that have an ACL. Dropping the role that created the extension leaves various junk entries in pg_init_privs that you can use to test your patch. Yours, Laurenz Albe --=-AxJGncXanuvfxNCLJPDe Content-Type: application/x-compressed-tar; name="ext.tgz" Content-Disposition: attachment; filename="ext.tgz" Content-Transfer-Encoding: base64 H4sIAAAAAAAAA+1YbW+jRhDO5/yK/VAJrPpyxrHvIl0SaYPXBBWDy4tzaVUhbG84JAwOYN9VV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