forked from ThomWright/postgres-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Poll once per second trying to acquire the lock, rather than waiting in a long-running transaction. CREATE INDEX CONCURRENTLY needs to wait for all running txs to finish before starting, which can lead to deadlocks. Fixes ThomWright#36
- Loading branch information
1 parent
cfff57b
commit 3fc9fde
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE IF NOT EXISTS concurrent ( | ||
id integer | ||
); |
7 changes: 7 additions & 0 deletions
7
src/__tests__/fixtures/concurrent-index-2/2_insert-million-rows.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- will acquire ROW EXCLUSIVE table-level locks for the rest of the (reasonably long-running) transaction | ||
INSERT INTO concurrent (id) SELECT i FROM generate_series(1, 1000000) as t(i); | ||
|
||
-- will attempt to acquire ACCESS EXCLUSIVE table-level lock | ||
-- will deadlock if this same transaction is running concurrently: | ||
-- - both transactions will be waiting for the other to release the conflicting ROW EXCLUSIVE locks | ||
ALTER TABLE concurrent ADD PRIMARY KEY (id); |
3 changes: 3 additions & 0 deletions
3
src/__tests__/fixtures/concurrent-index-2/3_index-concurrently.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- postgres-migrations disable-transaction | ||
|
||
CREATE INDEX CONCURRENTLY concurrent_index ON concurrent (id); |
This file contains 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
This file contains 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