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 1wWB89-002RJQ-0g for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Jun 2026 10:53:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wWB87-00HAbG-2X for pgsql-bugs@arkaria.postgresql.org; Sun, 07 Jun 2026 10:53:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wWB87-00HAb8-1O for pgsql-bugs@lists.postgresql.org; Sun, 07 Jun 2026 10:53:23 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wWB84-00000001jBr-2iav for pgsql-bugs@lists.postgresql.org; Sun, 07 Jun 2026 10:53:22 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-69e1eae4eb4so2202541eaf.2 for ; Sun, 07 Jun 2026 03:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780829598; cv=none; d=google.com; s=arc-20240605; b=TdlHv8TcDAXT0EHTqz6Ba3/SyiLTySNeKZ/RfHDpp8Uotm/FMnL8xe8WpJJ3u6xyy3 vvq8i2tHan6aIR1fWXleX6r8hv4e13Wlyh3Brx6T5Pcn5l7DwRf6oKlN4kaXBJOnS/Ep keXOGtBB2kKKWqtP6V2nz/9JYrRpHrQFkr3NBadQe/zTSsVdohcC9zqHqhFLzK+VH9g3 D8/pc7jnF0G+y/iItOToajChJ941AXVX5dhnIHhp/B/tW2Y/zjmu38h/LriaPpKxAz6a 9Dr1IPVUTCFDNcbCXrConQ8/ODYLQD9v5siTy1H2iUsfflUQLm7adpk59xmhvDfwpe1s j2ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=7+Id7hatWlhcUk0MQ3NNe9k+KLUDTopZGXDYRT0mzi0=; fh=PE1xl+gt3axCXZHLkcc4Wpx4rm3nA593nXV8w9ZO4jY=; b=LnmGly3xoPp2KXDWNddtdv6q1jrKP2/3E6MOgzPd8PEmGQTJcoiIqvayFxNYHD623J PJZXbkBOVFhJ8P7osaONlZZQtzFLszcYSOHyFeXsA82tqSqeWYynaq+BmF6PAk3Ta4Y0 5Rm6XcJ0hB2O3VBuQqP1GIsRqznYKtlfZCh2tfEulpVkbD6XIgHliCVAE3KaekcEkT9O O1ndDJA3FAiz9cAHfRzbK1xgXGmb8IJ0W2ZRlN71OSUtNPk97HjOrbc+Jfc3A/pl5tpv phz2u3zoX2umDnXupzjuEjLHfKlM6A2sZru5ZZHx4Mv2DMxBNHHTGfGZJGhG2I2IfulR nFMg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780829598; x=1781434398; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7+Id7hatWlhcUk0MQ3NNe9k+KLUDTopZGXDYRT0mzi0=; b=T9oW6sA6+rhYx9rKkEiavyuZKAW2jeaFST6kp4nbNBdhTtbytN8FbxuTPgr5/hAxqJ +X3PZ3SAvWUo2S4HVejUwGkZA4Vov6p40/SO117zxc2COvSvPCvFf5uXX3cF2K7yYEJl AxI8CQzjfpeWJo2I0q8PUqQSJdhVIy6fClq96aUWa+7/QSiYJRCLVVLSyN20Q/JP0Y/6 +vTJdcIksD/fr9f3salZBc35TxtPUREFj8Q5K0Kqk8dUybyUXUZpIMpD8vKlEmryg/bO OiteOZwt6GH1Ox8I8MyYFg530o7b4oz82swc8dQ2LU4RdSs8YUi3ekFSPTk7mQsxuyAB 9MRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780829598; x=1781434398; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7+Id7hatWlhcUk0MQ3NNe9k+KLUDTopZGXDYRT0mzi0=; b=ao5ovbGRkJnHmtTxSehKcizRNefpD0IBE6oktQyT87lTD7kqBcwmLaOnK2eKexCwzj n8qF3lY6/DQ/umbJDZRV3kThsm3jYjeG32FX+9AicL4nZiWGXwiphswchSF6LK3llbW0 MGfgEoOO5h0thix30UpnPDku5EI4S6gtuq1A1q+Bkj7TqAOhBBn0NBqAM9ZdAXA3O5L4 8xyAUlO81w+u6pXucComsTZFSZu7koBbs59nDZAtxqiNfV2EYYZVqQN310q1fv6PAQur Z5szFOqbg86T809OOR3LvEpfLW5MNhzoTtl1eHRmru4N1kX9vtw2c/SjhpxoE7jEH+DR jZaA== X-Gm-Message-State: AOJu0Yz9f2yrlfxW6AqZKbZuT/m0oy3AhFOPwyMsUVn8bRw6TLxTELaT 7MXRzKBTTC84uWyzzoRWCGe7M73/TkXNAWtp7bvnNo1qkddGOCZzIAxteQHu+cX+VaeAeBiXPtZ /rs67o8HERGbfy1XBnTfzLZBjcm/m5yI= X-Gm-Gg: Acq92OFsa/4JRp/z33SdBs40kddfS7SPMsL4dSTI/b+X/FyfwwzAaAMutoweGxf9wMx fMJeiIeewWLYc8PWRRYwKchSPtsugPNid/zGHDrm6nF3tzlgMEVQLJU/GiXq9nQTm7BVPdqI065 ihfggFpgGL0DLRkzmC07IS8uormF3MSH1Va+zYsQyZ7j5jr2ChLetTxyjy6kmlo/h3xJEBuBW6N 6367jRvzKGef9zPTb2uRM4QFSinz4nFpmtP1RqF2O1AN0RukBiwjWsee477omyETln7PXrZW11L 3aTjQTOe0uM2xaL4Fxp7tdpAkgoPpMmoOh1Hh17AucQKpxWhyTefbJ1XJcvygWWDffIqNRBzp2m VX7110rdVBJOa8px8jWKisp7p2rzBRRQnwly0 X-Received: by 2002:a05:6820:1609:b0:69e:8976:77d9 with SMTP id 006d021491bc7-69e897678c5mr1351314eaf.40.1780829598363; Sun, 07 Jun 2026 03:53:18 -0700 (PDT) MIME-Version: 1.0 References: <19483-80de42dc4e62cfd6@postgresql.org> In-Reply-To: From: =?UTF-8?Q?H=C3=BCseyin_Demir?= Date: Sun, 7 Jun 2026 12:53:07 +0200 X-Gm-Features: AVVi8CexnIZ5orsfmPPwXl_33ggzec2lAv9l6Uc2IFnk6kh4NFxca0H2eLrIoTg Message-ID: Subject: Re: BUG #19483: pg_upgrade fails with orphan records in pg_init_priv catalog table To: Greg Sabino Mullane Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009db3c10653a7b3cf" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009db3c10653a7b3cf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, sorry for the late reply. There was a problem in my mailbox. I was able to reproduce the same issue with the pg_stat_statements extension. The problem is valid for orphan pg_init_privs records. Therefore, I created a simple patch to introduce a new check to pg_upgrade binary. PS: I'm working on PostgreSQL 14 (on different minor versions) Please see [1] to see and review the problem I try to solve. ``` my_db_v2=3D# SELECT pip.objoid, pip.classoid, pip.privtype, pip.initprivs, e.extname FROM pg_init_privs pip JOIN pg_depend d ON d.objid =3D pip.objoid JOIN pg_extension e ON e.oid =3D d.refobjid WHERE e.extname =3D 'pg_stat_statements' AND pip.privtype =3D 'e'; objoid | classoid | privtype | initprivs | extname --------+----------+----------+--------------------------------+-----------= --------- 16458 | 1255 | e | {16449=3DX/16449} | pg_stat_statements 16466 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements 16471 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements (3 rows) ``` I applied the following steps. 1. Create the role and database on postgres database. ``` CREATE ROLE benchmark_owner SUPERUSER; CREATE DATABASE my_db OWNER benchmark_owner; ``` 2. Connect to the my_db and execute the following commands. ``` SET ROLE benchmark_owner; create extension pg_stat_statements; ``` Afterwards, I see the records in pg_init_privs my_db=3D# reset role; RESET my_db=3D# SELECT pip.objoid, pip.classoid, pip.privtype, pip.initprivs, e.extname FROM pg_init_privs pip JOIN pg_depend d ON d.objid =3D pip.objoid JOIN pg_extension e ON e.oid =3D d.refobjid WHERE e.extname =3D 'pg_stat_statements' AND pip.privtype =3D 'e'; objoid | classoid | privtype | initprivs | extname --------+----------+----------+--------------------------------------------= ------------------+-------------------- 16458 | 1255 | e | {benchmark_owner=3DX/benchmark_owner} | pg_stat_statemen= ts 16466 | 1259 | e | {benchmark_owner=3DarwdDxt/benchmark_owner,=3Dr/benchmark_owner} | pg_stat_statements 16471 | 1259 | e | {benchmark_owner=3DarwdDxt/benchmark_owner,=3Dr/benchmark_owner} | pg_stat_statements (3 rows) 3. Connect to postgres database and execute the following ones. ``` SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname =3D 'my_db';ALTER DATABASE my_db RENAME TO my_db_v2; ``` 4. Connect to my_db_2 and execute the following ones. ``` REASSIGN OWNED BY benchmark_owner TO postgres; DROP OWNED BY benchmark_owner; ``` 5. Connect to postgres database and drop the role we created the extension ``` DROP ROLE benchmark_owner; ``` 6. Connect to my_db_2 and check the dangling/orphan records. ``` my_db_v2=3D# SELECT pip.objoid, pip.classoid, pip.privtype, pip.initprivs, e.extname FROM pg_init_privs pip JOIN pg_depend d ON d.objid =3D pip.objoid JOIN pg_extension e ON e.oid =3D d.refobjid WHERE e.extname =3D 'pg_stat_statements' AND pip.privtype =3D 'e'; objoid | classoid | privtype | initprivs | extname --------+----------+----------+--------------------------------+-----------= --------- 16458 | 1255 | e | {16449=3DX/16449} | pg_stat_statements 16466 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements 16471 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements (3 rows) ``` [1] https://www.postgresql.org/message-id/flat/CAB5wL7aig++XphVjyBjvXG-=3DUE+= =3Dmk3xfZZxkxV5XS4Hb58aHA@mail.gmail.com Greg Sabino Mullane , 20 May 2026 =C3=87ar, 15:07 tarih= inde =C5=9Funu yazd=C4=B1: > PostgreSQL version: 18.3 >> ... > > 5. Verify orphan records remain in pg_init_privs:erprise Postgres Softwar= e >> Products & Tech Support >> > > Thanks for providing a failing use case. I ran this on a 18.3 server and > found no orphaned rows - but I used the pg_stat_statements extension > instead of pg_wait_sampling. Could you try your experiment using > pg_stat_statements? And could you also show us the contents of the errant > rows in pg_init_privs for the failing case? > > > > --0000000000009db3c10653a7b3cf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi, sorry for the late reply. There was a problem in my ma= ilbox.

I was able to reproduce the same issue with the pg_stat_state= ments extension. The problem is valid for orphan pg_init_privs records. The= refore, I created a simple patch to introduce a new check to pg_upgrade bin= ary.

PS: I'm working on PostgreSQL 14 (on different minor versio= ns)

Please see [1= ] to see and review the problem I try to solve.

```
my_db_v2= =3D# SELECT pip.objoid, pip.classoid, pip.privtype, pip.initprivs, e.extnam= e
FROM pg_init_privs pip
JOIN pg_depend d ON d.objid =3D pip.objoidJOIN pg_extension e ON e.oid =3D d.refobjid
WHERE e.extname =3D 'p= g_stat_statements'
AND pip.privtype =3D 'e';
objoid | cla= ssoid | privtype | initprivs | extname
--------+----------+----------+--= ------------------------------+--------------------
16458 | 1255 | e | {= 16449=3DX/16449} | pg_stat_statements
16466 | 1259 | e | {16449=3DarwdDx= t/16449,=3Dr/16449} | pg_stat_statements
16471 | 1259 | e | {16449=3Darw= dDxt/16449,=3Dr/16449} | pg_stat_statements
(3 rows)

```

I= applied the following steps.

1. Create the role and database on pos= tgres database.

```
CREATE ROLE benchmark_owner SUPERUSER;
CRE= ATE DATABASE my_db OWNER benchmark_owner;
```

2. Connect to the m= y_db and execute the following commands.

```
SET ROLE benchmark_o= wner;
create extension pg_stat_statements;
```

Afterwards, I s= ee the records in pg_init_privs

my_db=3D# reset role;
RESET
my= _db=3D# SELECT pip.objoid, pip.classoid, pip.privtype, pip.initprivs, e.ext= name
FROM pg_init_privs pip
JOIN pg_depend d ON d.objid =3D pip.objoi= d
JOIN pg_extension e ON e.oid =3D d.refobjid
WHERE e.extname =3D = 9;pg_stat_statements'
AND pip.privtype =3D 'e';
objoid | = classoid | privtype | initprivs | extname
--------+----------+----------= +--------------------------------------------------------------+-----------= ---------
16458 | 1255 | e | {benchmark_owner=3DX/benchmark_owner} | pg_= stat_statements
16466 | 1259 | e | {benchmark_owner=3DarwdDxt/benchmark_= owner,=3Dr/benchmark_owner} | pg_stat_statements
16471 | 1259 | e | {ben= chmark_owner=3DarwdDxt/benchmark_owner,=3Dr/benchmark_owner} | pg_stat_stat= ements
(3 rows)

3. Connect to postgres database and execute the f= ollowing ones.

```
SELECT pg_terminate_backend(pid)
FROM pg_st= at_activity
WHERE datname =3D 'my_db';ALTER DATABASE my_db RENAM= E TO my_db_v2;
```

4. Connect to my_db_2 and execute the followin= g ones.

```
REASSIGN OWNED BY benchmark_owner TO postgres;
DRO= P OWNED BY benchmark_owner;
```

5. Connect to postgres database a= nd drop the role we created the extension

```
DROP ROLE benchmark= _owner;
```

6. Connect to my_db_2 and check the dangling/orphan r= ecords.

```
my_db_v2=3D# SELECT pip.objoid, pip.classoid, pip.pri= vtype, pip.initprivs, e.extname
FROM pg_init_privs pip
JOIN pg_depend= d ON d.objid =3D pip.objoid
JOIN pg_extension e ON e.oid =3D d.refobjid=
WHERE e.extname =3D 'pg_stat_statements'
AND pip.privtype = =3D 'e';
objoid | classoid | privtype | initprivs | extname
-= -------+----------+----------+--------------------------------+------------= --------
16458 | 1255 | e | {16449=3DX/16449} | pg_stat_statements
16= 466 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements16471 | 1259 | e | {16449=3DarwdDxt/16449,=3Dr/16449} | pg_stat_statements=
(3 rows)
```


Greg Sabino Mullane <htamfi= ds@gmail.com>, 20 May 2026 =C3=87ar, 15:07 tarihinde =C5=9Funu yazd= =C4=B1:
PostgreSQL version: 18.3
...
5. Verify orphan records remain in pg_init_pr= ivs:erprise Postgres Software Products & Tech Support
<= div>
Thanks for providing a failing use case. I ran this on a= 18.3 server and found no orphaned rows - but I used the pg_stat_statements= extension instead of pg_wait_sampling. Could you try your experiment using= pg_stat_statements? And could you also show us the contents of the errant = rows in pg_init_privs for the failing case?

=C2=A0=

--0000000000009db3c10653a7b3cf--