Diagnostic Queries
Symptoms
Logical replication apply could not find the target relation that a publication is streaming changes for. PostgreSQL raises SQLSTATE 42P01 (undefined_table).
- The subscriber is missing the target table.
- Common when schema isn’t synced to the subscriber.
- Apply stalls until the table exists.
What the server log shows
ERROR: logical replication target relation "public.orders" does not exist
Why PostgreSQL raises this — what the manual says
As Chapter 29 Logical Replication explains:
Logical replication delivers changes to tables that must already exist on the subscriber with a matching schema-qualified name and compatible columns — create the missing target table on the subscriber before replication can apply rows to it.
The apply worker maps each replicated change to a local relation by name. If the subscriber lacks that table (schema not migrated), the mapping fails and PostgreSQL reports 42P01, pausing apply.
Common causes
- The table’s DDL was not created on the subscriber.
- A schema/table-name mismatch between publisher and subscriber.
- A table added to the publication but not yet to the subscriber.
How to fix it
- Create the matching table on the subscriber (DDL is not replicated).
- Keep publisher and subscriber schemas in sync via migrations.
- After creating the table, the apply worker resumes automatically.
Related & next steps
Reference: PostgreSQL 18 Section 31 “Logical Replication”.
Thanks — noted. This helps keep the database accurate.