Skip to content

postgres: disable the session timeouts that cancel COPY - #6

Merged
tbarbugli merged 1 commit into
mainfrom
session-timeouts
Aug 13, 2026
Merged

postgres: disable the session timeouts that cancel COPY#6
tbarbugli merged 1 commit into
mainfrom
session-timeouts

Conversation

@tbarbugli

Copy link
Copy Markdown
Member

Summary

A COPY part, pg_dump, and pg_restore are each one statement, and a COPY part holds its transaction until it finishes. Inherited statement_timeout, lock_timeout, idle_in_transaction_session_timeout, and idle_session_timeout cancel that work with SQLSTATE 57014.

  • Every SQL session pgmigrate opens now SETs those four GUCs to 0 before BEGIN (postgres.Connect). Replication connections are unchanged.
  • pg_dump / pg_restore get the same via PGOPTIONS.
  • Preflight warns when the inherited values are non-zero so they are visible before a long run. pgmigrate does not ALTER ROLE.
  • SQLSTATE 57014 is still not retried: after the timeouts are off, a cancel is external (pg_cancel_backend, a proxy idle timeout). --retry-base-copy is not the fix for that.

Closes #5.

Test plan

  • gofmt, vet, unit tests, race
  • Integration: inherited statement_timeout is SET to 0, pg_sleep survives, preflight warns and stays acknowledgeable, COPY of a table completes under statement_timeout=1ms
  • make e2e (migration-e2e=ok)
  • CI green on this PR

Made with Cursor

A COPY part is one statement and holds its transaction until it finishes.
So are pg_dump and pg_restore. Inherited statement_timeout, lock_timeout,
idle_in_transaction_session_timeout, and idle_session_timeout cancel that
work with SQLSTATE 57014, and pgmigrate never cleared them.

Every SQL session it opens now sets those four GUCs to 0 before BEGIN.
pg_dump and pg_restore get the same via PGOPTIONS. Preflight warns when the
inherited values are non-zero, so they are visible before a long run;
pgmigrate does not ALTER ROLE for itself. 57014 is still not retried: after
the timeouts are off, a cancel is external. --retry-base-copy is not the
fix for that.

Closes #5.

Co-authored-by: Cursor <cursoragent@cursor.com>
@tbarbugli
tbarbugli merged commit 3af87a1 into main Aug 13, 2026
1 check passed
@tbarbugli
tbarbugli deleted the session-timeouts branch August 13, 2026 17:42
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.

Session timeouts cancel long COPY and restore

1 participant