Skip to content

[3.0] Says so when the table being described is unlogged - #9655

Open
albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/pg-table-sql-unlogged
Open

albertlast wants to merge 1 commit into
SimpleMachines:release-3.0from
albertlast:3.0/pg-table-sql-unlogged

Conversation

@albertlast

Copy link
Copy Markdown
Collaborator

Description

PostgreSQL::table_sql() always writes CREATE TABLE, so the SQL it produces does
not rebuild an unlogged table as one.

SMF makes three tables unlogged, in Sources/Maintenance/Migration/v2_1/PostgreSqlUnlogged.php
("UNLOGGED Table PG 9.1+"), via ALTER TABLE {db_prefix}{raw:table} SET UNLOGGED:

smf_log_floodcontrol
smf_log_online
smf_sessions

They are unlogged deliberately. None of them holds anything worth surviving a crash,
and keeping them out of the write-ahead log is the whole point of that migration.
Rebuilding one from table_sql() output gives it back a durability it was never
meant to pay for, and nothing afterwards says the change happened.

This reads pg_class.relpersistence for the table and puts UNLOGGED into the
CREATE when it is 'u'.

table_sql() is presently only reachable through the deprecated db_table_sql
alias in Subs-Compat.php, so nothing in the current tree exercises it — which is
also why this went unnoticed. I found it because I have local work that calls it to
record a table's shape before an upgrade migrates it: the three tables above came
back logged, and only a relpersistence check tells you so.

Verified against PostgreSQL 17 in the Docker environment, on a forum upgraded from
2.1.7, by comparing pg_class.relpersistence for every table before and after a
rebuild driven by this output.

Issues References (Fixes|Related|Closes)

A table that is not written to the write-ahead log is made that way, and
sessions, log_online and log_floodcontrol all are. table_sql() described
them as ordinary tables, so anything rebuilding one from that SQL gave
it a durability it was never meant to pay for, and the write cost that
goes with it.

Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant