pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
4+ messages / 4 participants
[nested] [flat]

* BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
@ 2025-12-27 23:57  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Bug reporting form @ 2025-12-27 23:57 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: pavel.tyslacki@gmail.com

The following bug has been logged on the website:

Bug reference:      19365
Logged by:          Paveł Tyślacki
Email address:      pavel.tyslacki@gmail.com
PostgreSQL version: 18.1
Operating system:   docker: Debian 14.2.0-19 14.2.0, 64-bit
Description:        

POSTGRES VERSION: PostgreSQL 18.1 (Debian 18.1-1.pgdg13+2) on
x86_64-pc-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
PG_DUMP VERSION: pg_dump (PostgreSQL) 18.1

My code creates many schemas in parallel, runs DDL SQL on them, runs
`pg_dump` for each one, and then drops the schemas. This works fine for
postgres 13, 14, 15, 16, and 17.

In postgres 18, I started getting random errors from `pg_dump`:

```
pg_dump: error: query failed: ERROR:  could not open relation with OID 16741
pg_dump: detail: Query was: SELECT seqrelid, format_type(seqtypid, NULL),
seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle, last_value,
is_called FROM pg_catalog.pg_sequence, pg_get_sequence_data(seqrelid) ORDER
BY seqrelid;
```

The following python code reproduces the issue by creating and dropping
table with sequence while running `pg_dump` concurrently.

```
import asyncio
from asyncio.subprocess import PIPE

CONN = "postgresql://postgres:test@127.0.0.1:5432/postgres"
MAX_CONCURRENCY = 20
NUMBER_OF_SCHEMAS = 20

async def run_command(cmd: list[str]) -> str:
    proc = await asyncio.create_subprocess_exec(*cmd, stdout=PIPE,
stderr=PIPE)
    stdout, stderr = await proc.communicate()
    if proc.returncode != 0:
        raise RuntimeError(
            f"Command failed: {' '.join(cmd)}\n{stderr.decode()}"
        )
    return stdout.decode()

async def run_test(i: int, sem: asyncio.Semaphore):
    async with sem:
        schema = f"test_{i}"
        await run_command([
            "psql",
            CONN,
            "-c",
            f"""
            DROP SCHEMA IF EXISTS {schema} CASCADE;
            CREATE SCHEMA {schema};
            CREATE TABLE {schema}.main (
                id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
                value TEXT NOT NULL
            );
            """
        ])
        await run_command([
            "pg_dump",
            CONN,
            f"--schema={schema}",
        ])
        await run_command([
            "psql",
            CONN,
            "-c",
            f"""
            DROP SCHEMA IF EXISTS {schema} CASCADE;
            """
        ])

async def main():
    sem = asyncio.Semaphore(MAX_CONCURRENCY)
    await asyncio.gather(*[
        asyncio.create_task(run_test(i, sem))
        for i in range(NUMBER_OF_SCHEMAS)
    ])

if __name__ == "__main__":
    asyncio.run(main())
```

I expected `pg_dump` to be able to handle sequences being dropped in
parallel without errors.

I’m not sure what output `pg_dump` should produce when trying to dump
sequences that are being dropped, but I believe it should behave similarly
to how it handles standard relations, constraints, indexes, etc.



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
@ 2025-12-29 17:28  Tom Lane <tgl@sss.pgh.pa.us>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2025-12-29 17:28 UTC (permalink / raw)
  To: pavel.tyslacki@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> In postgres 18, I started getting random errors from `pg_dump`:
> pg_dump: error: query failed: ERROR:  could not open relation with OID 16741
> pg_dump: detail: Query was: SELECT seqrelid, format_type(seqtypid, NULL),
> seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle, last_value,
> is_called FROM pg_catalog.pg_sequence, pg_get_sequence_data(seqrelid) ORDER
> BY seqrelid;

Thanks for the report.  I posted an analysis here:

https://www.postgresql.org/message-id/2885944.1767029161%40sss.pgh.pa.us

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
@ 2026-01-09 16:19  Nathan Bossart <nathandbossart@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Nathan Bossart @ 2026-01-09 16:19 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pavel.tyslacki@gmail.com; pgsql-bugs@lists.postgresql.org

On Mon, Dec 29, 2025 at 12:28:07PM -0500, Tom Lane wrote:
> PG Bug reporting form <noreply@postgresql.org> writes:
>> In postgres 18, I started getting random errors from `pg_dump`:
>> pg_dump: error: query failed: ERROR:  could not open relation with OID 16741
>> pg_dump: detail: Query was: SELECT seqrelid, format_type(seqtypid, NULL),
>> seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle, last_value,
>> is_called FROM pg_catalog.pg_sequence, pg_get_sequence_data(seqrelid) ORDER
>> BY seqrelid;
> 
> Thanks for the report.  I posted an analysis here:
> 
> https://www.postgresql.org/message-id/2885944.1767029161%40sss.pgh.pa.us

I've committed the following in an attempt to fix this:

	https://postgr.es/c/7a485bd641 (master)
	https://postgr.es/c/39d5555766 (v18)

Could you please verify that it fixes your use-case?

-- 
nathan





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
@ 2026-01-09 22:56  Paveł Tyślacki <pavel.tyslacki@gmail.com>
  parent: Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Paveł Tyślacki @ 2026-01-09 22:56 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-bugs@lists.postgresql.org

I have a simple test `pg_get_sequence_data(0)` that works fine with patch,
concurrent pg_dump works fine for my case too.

Thanks
Pavel

On Fri, 9 Jan 2026 at 16:19, Nathan Bossart <nathandbossart@gmail.com>
wrote:

> On Mon, Dec 29, 2025 at 12:28:07PM -0500, Tom Lane wrote:
> > PG Bug reporting form <noreply@postgresql.org> writes:
> >> In postgres 18, I started getting random errors from `pg_dump`:
> >> pg_dump: error: query failed: ERROR:  could not open relation with OID
> 16741
> >> pg_dump: detail: Query was: SELECT seqrelid, format_type(seqtypid,
> NULL),
> >> seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle, last_value,
> >> is_called FROM pg_catalog.pg_sequence, pg_get_sequence_data(seqrelid)
> ORDER
> >> BY seqrelid;
> >
> > Thanks for the report.  I posted an analysis here:
> >
> > https://www.postgresql.org/message-id/2885944.1767029161%40sss.pgh.pa.us
>
> I've committed the following in an attempt to fix this:
>
>         https://postgr.es/c/7a485bd641 (master)
>         https://postgr.es/c/39d5555766 (v18)
>
> Could you please verify that it fixes your use-case?
>
> --
> nathan
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2026-01-09 22:56 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-27 23:57 BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently PG Bug reporting form <noreply@postgresql.org>
2025-12-29 17:28 ` Tom Lane <tgl@sss.pgh.pa.us>
2026-01-09 16:19   ` Nathan Bossart <nathandbossart@gmail.com>
2026-01-09 22:56     ` Paveł Tyślacki <pavel.tyslacki@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox