Skip to content

[resharding] ERROR: XX000 could not open relation with OID 0 #847

@vitabaks

Description

@vitabaks

Hi! I got this error when running the COPY_DATA command:

2026-03-24T10:38:14.419195Z  INFO copy_data "db1" to "db1_sharded", publication="pgdog"
2026-03-24T10:38:14.419296Z DEBUG transaction finished [0.135ms]
2026-03-24T10:38:14.419295Z  INFO loading tables from publication "pgdog" on 1 shards [db1]
2026-03-24T10:38:14.424153Z DEBUG [cleanup] no cleanup needed, server in "idle" state [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.424169Z  INFO dumping schema [276, postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.811578Z DEBUG [cleanup] no cleanup needed, server in "idle" state [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.811605Z DEBUG => postgres@10.*.**.236:5434/db1
2026-03-24T10:38:14.811727Z DEBUG requesting TLS connection with verify mode: Prefer [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.813677Z DEBUG server does not support TLS, continuing without encryption [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.819227Z  INFO new server connection [postgres@10.*.**.236:5434/db1, auth: md5, reason: replication] 
2026-03-24T10:38:14.819264Z  INFO creating replication slot "__pgdog_repl_9vek6wzv1cgcicsqb12_0" [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.853143Z  INFO replication slot "__pgdog_repl_9vek6wzv1cgcicsqb12_0" at lsn 8B5FD/2A87EA90 created [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.892008Z DEBUG [cleanup] no cleanup needed, server in "idle" state [postgres@10.*.**.236:5434/db1]
2026-03-24T10:38:14.896837Z  INFO closing server connection [postgres@10.*.**.236:5434/db1, state: idle, reason: other]
2026-03-24T10:38:14.896901Z ERROR [task: 1] backend: ERROR: XX000 could not open relation with OID 0

I suspect that this is due to the fact that some tables do not contain PK.

db1=# select count(*)
from information_schema.tables tab
left join information_schema.table_constraints tco 
  on tab.table_schema = tco.table_schema
  and tab.table_name = tco.table_name 
  and tco.constraint_type = 'PRIMARY KEY'
where
  tab.table_type = 'BASE TABLE'
  and tab.table_schema not in ('pg_catalog', 'information_schema')
  and tco.constraint_name is null
;
 count 
-------
   294
(1 row)

I usually set REPLICA IDENTITY FULL for logical replication in this case.

db1=# select 'ALTER TABLE '||tab.table_schema||'.'||tab.table_name||' REPLICA IDENTITY FULL ;'
from information_schema.tables tab
left join information_schema.table_constraints tco 
  on tab.table_schema = tco.table_schema
  and tab.table_name = tco.table_name 
  and tco.constraint_type = 'PRIMARY KEY'
where tab.table_type = 'BASE TABLE'
  and tab.table_schema not in ('pg_catalog', 'information_schema')
  and tco.constraint_name is null
order by tab.table_name \gexec
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
...

ERROR: XX000 could not open relation with OID 0 Why?

Primary key (PK) is this a strict requirement?

pgdog v0.1.32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions