[3.0] Keeps a backup table from depending on the live table's sequence - #9650
Closed
albertlast wants to merge 1 commit into
Closed
[3.0] Keeps a backup table from depending on the live table's sequence#9650albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
LIKE ... INCLUDING DEFAULTS copies a default as the expression it is written with, so backup_smf_calendar_holidays.id_holiday defaulted to nextval on smf_calendar_holidays_seq. That makes the backup an object the sequence cannot be dropped without, and HolidaysToEvents drops it. Only the defaults that name a sequence are taken off, once the copy has been made. The others say what a column holds when nothing supplies it, which is part of what makes the backup worth restoring from. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
albertlast
marked this pull request as draft
September 6, 2026 09:57
albertlast
force-pushed
the
3.0/pg-backup-sequence-dependency
branch
from
September 6, 2026 09:57
21b4148 to
eeb76dc
Compare
Collaborator
Author
|
Closing this in favour of a different approach. Both shapes I tried here argue about defaults, which is the wrong axis. The backup is at once incomplete and over-coupled: Splitting the two — the #9649 is unaffected and still needed: without it a PostgreSQL upgrade with backups on stops at the first table. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On PostgreSQL, an upgrade that was asked to back up the database cannot finish. It gets as far as the migration that folds holidays into events and stops there:
backup_table()copies a table withCREATE TABLE backup_x (LIKE x INCLUDING DEFAULTS).A sequence in PostgreSQL is an object in its own right, related to the column it feeds but not carried along by a copy of that column.
INCLUDING DEFAULTScopies a default as the expression it is written with, sobackup_smf_calendar_holidays.id_holidayis given the defaultnextval('smf_calendar_holidays_seq'), pointing at the sequence behind the live table rather than at one of its own.Two things follow. The backup becomes an object that sequence cannot be dropped without, which is what
HolidaysToEventsis trying to do; and anything inserted into a backup table would draw its id from the live table's counter.The copy is still made
INCLUDING DEFAULTS, and only the defaults that name a sequence are taken off afterwards, a column at a time. Every other default is left alone: a default is part of what a column is, and a backup that has lost them is a poorer thing to rebuild from than one that has kept them.What the backup still does not carry is unchanged by this.
LIKEwithoutINCLUDING INDEXESorINCLUDING CONSTRAINTShas never copied indexes, primary keys or constraints, and the@todoabove the statement, asking whether sequences should be backed up as well, is left as it was. Giving each backup a sequence of its own is a larger question than an upgrade that cannot finish.How this was verified
Upgrading the 2.1.7 baseline from the 2.1 development environment with the backup step turned on. Reaching this at all needs #9649, which fixes an earlier failure in the same step; both were applied together.
Upgrade complete!Then reading the catalogue on the upgraded database, to confirm the change takes what it means to and nothing else:
backup_tablesbackup_tables, matching the live table column for columnThe eleven live defaults with no match on a backup table are all accounted for by the backup being a copy of an earlier moment:
smf_mail_queue.next_tryandtrieshave no column on the backup at all because a migration added them after the copy was taken, andsmf_pm_recipients.in_inboxreads'1'::smallintagainst a live1because the live column's type changed. None of them is a default this removes.Also with the upgrade killed part way and started again, with backups on. It recovered in one run, and every non-
backup_object matched an uninterrupted upgrade: 323 tables, sequences, indexes, constraints, functions, aggregates and operators, 65 row counts, 228 settings, and the position of all 38 sequences.MySQL is unaffected throughout: it copies with
CREATE TABLE backup_x LIKE x, and anAUTO_INCREMENTcounter belongs to its table rather than being a separate object, so a backup cannot hold the original's.Not reachable from the unit suite
backup_table()is a database driver method and needs a connection.Issues References (Fixes|Related|Closes)