Skip to content

fix: table_async pre-creates and syncs sequences for serial columns - #36

Merged
valehdba merged 1 commit into
mainfrom
fix/table-async-sequences
Nov 17, 2026
Merged

valehdba merged 1 commit into
mainfrom
fix/table-async-sequences

Conversation

@valehdba

Copy link
Copy Markdown
Owner

Fixes #33

Summary

pgclone.table_async() failed on any table with a serial / bigserial column: the worker ran CREATE TABLE ... DEFAULT nextval('schema.tbl_id_seq') without creating the sequence first (relation "..._id_seq" does not exist). The sync pgclone.table() and the async schema path already handled this; only the single-table background path did not.

bgw_clone_one_table (src/pgclone_bgw.c) now, mirroring pgclone_table():

  • creates the sequences the table depends on (CREATE SEQUENCE IF NOT EXISTS) before CREATE TABLE, skipped when conflict=ignore keeps an existing table;
  • replays each owned sequence's current value with setval() after the data copy, so new inserts on the target don't reuse copied ids.

Both steps are idempotent, so the schema path (which already clones sequences) is unaffected.

Testing

test/test_async.sh test 9: clone a bigserial table with table_async; asserts the job completes, 3 rows are copied, and the next insert gets id 4.

Full ./test/run_all.sh passes on PG14, 15, 16, 17 and 18 (async 24/24, chaos 5/5).

Notes

  • The chaos fixture still uses a plain bigint key; it could go back to bigserial now, but I left it to keep this PR focused.
  • The conflict option is not yet applied to sequences in the async single-table path (replace/rename only act on the table), same as before this change.

🤖 Generated with Claude Code

)

bgw_clone_one_table now creates the sequences a table depends on before CREATE TABLE and replays their current values after the copy, mirroring pgclone_table(). Adds async test 9 (bigserial table).
@valehdba
valehdba merged commit 1b360fc into main Nov 17, 2026
22 checks passed
@valehdba
valehdba deleted the fix/table-async-sequences branch November 17, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

table_async fails for tables with serial/bigserial columns (sequence not pre-created)

1 participant