Skip to content

Commit 1da7886

Browse files
authored
Merge pull request #5 from getkalido/fix/lock
Change table lock to SHARE ROW EXCLUSIVE
2 parents 9c9fb18 + 222c67f commit 1da7886

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

migrations.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,10 @@ func lockTable(tx *pg.Tx) error {
391391
if err != nil {
392392
return err
393393
}
394-
_, err = tx.Exec("LOCK ? ", pg.Ident(migrationTableName))
394+
// https://www.postgresql.org/docs/current/explicit-locking.html
395+
// This mode protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.
396+
// This means only one migration can run at a time, but pg_dump can still COPY from the table (since it acquires a ACCESS SHARE lock, or so I am told)
397+
_, err = tx.Exec("LOCK ? in SHARE ROW EXCLUSIVE MODE", pg.Ident(migrationTableName))
395398

396399
return err
397400
}

0 commit comments

Comments
 (0)