Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

446
Views
Postgres lock_timeout when CREATE UNIQUE INDEX CONCURRENTLY

Having trouble creating unique index on a table. Statement fails with following message

>CREATE UNIQUE INDEX CONCURRENTLY my_table_pkey_new ON my_table (new_id);
ERROR:  canceling statement due to lock timeout

It is not clear why I get lock timeout. Concurrent index creation shouldn't lock the table.

I also tried to increase lock timeout but without success

test=> show lock_timeout;
 lock_timeout
--------------
 5min
(1 row)

test=> set lock_timeout to 99999999;
SET
test=> show lock_timeout;
 lock_timeout
--------------
 5min
(1 row)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Concurrent index creation shouldn't lock the table.

Of course it locks the table. What should happen if someone tries to drop the table while it was being indexed? It just locks it in a mode which does not conflict with INSERT, UPDATE, or DELETE. But it does conflict with other operations, including VACUUM and (ironically, perhaps) other CREATE INDEX CONCURRENTLY. It also takes a stronger lock which conflicts with everything, but it only holds that lock momentarily. But if that lock is not immediately available, it can timeout while waiting for it.

test=> show lock_timeout;
 lock_timeout
--------------
 5min
(1 row)

test=> set lock_timeout to 99999999;
SET
test=> show lock_timeout;
 lock_timeout
--------------
 5min
(1 row)

Is all of this run in one session, with no intervening statements, as the contiguous code indentation would suggest? If so, then I think you must be running some modified version of PostgreSQL, as I don't think any version of the community PostgreSQL behaves that way.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!