SET UNLOGGED is accepted for relations published only via FOR ALL TABLES, TABLES IN SCHEMA, or FOR ALL SEQUENCES ================================================================================================================ AI-generated bug report from the AI Annex Report ID: 01a1ddc5-8fb8-7b9f-8fa0-e77167be2c46 Filed: 2026-11-15 05:54:34 UTC Severity: 58/100 Blamed commit: 665d1fad99e7b11678b0d5fa24d2898424243cd6 ## Summary ALTER TABLE ... SET UNLOGGED is supposed to fail when the table is referenced by a publication, because unlogged relations cannot be published. The check only looks at pg_publication_rel, so it misses tables that are published implicitly by FOR ALL TABLES or FOR TABLES IN SCHEMA, and it likewise misses sequences published by FOR ALL SEQUENCES. After the command succeeds, later DML on the table is not WAL-logged and is never replicated, with no error on either side. A later REFRESH PUBLICATION drops the relation from the subscription, leaving the already diverged rows in place. ## Reproduction On the publisher: CREATE TABLE t (id int PRIMARY KEY, n int); CREATE PUBLICATION pub FOR ALL TABLES; On the subscriber (same table definition): CREATE TABLE t (id int PRIMARY KEY, n int); CREATE SUBSCRIPTION sub CONNECTION '...' PUBLICATION pub; Insert one row on the publisher and wait for it to appear on the subscriber. Then on the publisher: ALTER TABLE t SET UNLOGGED; -- succeeds; should fail INSERT INTO t VALUES (2, 20); The subscriber still has only the first row. The subscription remains in a ready state. ALTER SUBSCRIPTION sub REFRESH PUBLICATION then removes t from pg_subscription_rel and does not recover the missing row. The same SET UNLOGGED succeeds for a table published only by FOR TABLES IN SCHEMA, and for a sequence published only by FOR ALL SEQUENCES (the sequence stays in pg_subscription_rel, and REFRESH SEQUENCES still copies last_value until a REFRESH PUBLICATION drops it). By contrast, an explicitly published table is rejected as intended: CREATE PUBLICATION p3 FOR TABLE t; ALTER TABLE t SET UNLOGGED; -- ERROR: cannot change table "t" to unlogged because -- it is referenced by a publication ## Analysis ATPrepChangePersistence() rejects SET UNLOGGED when RelationHasPublication() is true. That helper only searches pg_publication_rel (PUBLICATIONRELMAP). FOR ALL TABLES and FOR ALL SEQUENCES set flags on pg_publication and do not create per-relation rows. FOR TABLES IN SCHEMA records the schema, not each table. The same narrow lookup has been used since the check was added in 665d1fad99e7, including after it was later widened to also reject tables named in an EXCEPT clause (those do have a pg_publication_rel row). is_publishable_class() requires RELPERSISTENCE_PERMANENT, so after SET UNLOGGED the relation is no longer a FOR ALL TABLES member and table changes are not written to WAL. The apply worker therefore has nothing to apply, and the subscriber's already-copied rows quietly go stale. The documented rule that unlogged tables and sequences are excluded from those publication types describes membership filtering; it does not say that SET UNLOGGED may put an already-subscribed relation into that state without error. Because a table in an EXCEPT clause is also rejected, a database with a FOR ALL TABLES publication currently has no supported way to change a table to unlogged short of dropping or rewriting the publication, other than this implicit path. ## Notes Confirmed at master 81b2179b492e3af891544813b7e22a42386b34d0. Not security-sensitive. Explicit FOR TABLE membership is already rejected and is a workaround if the publication can be expressed that way. REFRESH PUBLICATION after the fact does not recover missed rows. Related but distinct: Annex report 01a1cba0-1107-7dc6-942e-faa8aacc1704 (unlogged partition leaves under publish_via_partition_root = false).