Urgent.News

What's breaking now, across thousands of outlets.

Tech

CREATE INDEX on a live Postgres table locks writes. CONCURRENTLY fixes that, if you keep it out of a transaction

Here is the failure. You ship a migration that adds an index on a busy table: CREATE INDEX idx_orders_customer_id ON orders ( customer_id ); Postgres builds the index with a SHARE lock. Other sessions can still SELECT . They cannot INSERT , UPDATE , or DELETE until the build finishes. On a large table that can be minutes or hours of blocked writes. The PostgreSQL CREATE INDEX docs say so…

When a migration adds an index to a frequently accessed Postgres table, PostgreSQL creates the index using a SHARE lock. This prevents other sessions from performing INSERT, UPDATE, or DELETE operations on the table until the index is fully built. This can lead to significant delays, ranging from minutes to hours, especially for large tables. The PostgreSQL documentation explicitly states that a standard index build locks out writes, but not reads, on the table.

To avoid this issue, PostgreSQL provides the CREATE INDEX CONCURRENTLY command. This command builds the index without taking locks that would block concurrent inserts, updates, or deletes. It performs more work, including two table scans and waiting on open transactions, but it is the recommended solution for maintaining read and write operations during index creation.

However, there is a crucial rule to follow when using CREATE INDEX CONCURRENTLY: it cannot be executed within a transaction block. Attempting to do so results in an error: "CREATE INDEX CONCURRENTLY cannot run inside a transaction block." This limitation causes problems for many migration tools that wrap their operations in transactions, such as Flyway and Rails.

To resolve this issue, create a dedicated migration file containing only the CREATE INDEX CONCURRENTLY statement. Configure your migration tool to exclude this migration from being wrapped in a transaction. Additionally, set a reasonable value for the lock_timeout parameter to ensure that blocked locks fail quickly instead of waiting indefinitely.

After the concurrent index build completes, verify that the index is valid by executing a query that checks the index validity status. If the index is found to be invalid, drop it and retry the CREATE INDEX CONCURRENTLY command.

It is common for agents, such as migration tools, to generate plain CREATE INDEX statements without realizing that the concurrent version requires a standalone migration with no surrounding transaction. To prevent this issue, agents should be configured to use CREATE INDEX CONCURRENTLY alone in its own migration, with the lock_timeout set first. This approach ensures that index creation does not interfere with ongoing read and write operations on the table.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Humanize Groq API Output in Ruby: A Stdlib-Only Checker for Em Dashes, Question Leads and Exclamations + 5 Free Tools (2026)

Last verified October 2026. Heads-up: my team makes UnAIMyText, which sits third in the list below. The Ruby is yours to copy. I help run the tech side of a small community platform built on Rails.

  • Ruby script created to humanize Groq API output for community-style emails
  • Script checks for em dash overuse, question lead paragraphs, and exclamation stacking
  • Uses Ruby 3.1+, standard library, and Groq's API without additional gems

NudgeBox: The Ghost in Your Inbox That Haunts You Before a Recruiter Can Ghost You

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine What I Built NudgeBox is a ghost that lives in a job seeker's inbox.

  • NudgeBox is AI tool for job seekers to manage interview invitations and assessments.
  • Monitors Gmail inbox for interview-related emails from specific platforms.
  • Sends reminders at critical times: 7 days, 1 day, interview day, and 1 hour before.

What Learning Frontend Development Is Teaching Me About Product Management

Moving from defining digital experiences to understanding how they are built. As a Product Manager, I'm used to thinking about problems, requirements, user journeys and the outcomes a product should…

  • Frontend development deepened understanding of product creation from conception to browser display.
  • HTML, CSS, and JavaScript exercises highlighted importance of user experience and layout decisions.

AfterHours — Some Signals Should Never Be Heard.

AfterHours — Some Signals Should Never Be Heard. This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine What I Built AfterHours is an AI-powered haunted…

  • AI-powered haunted radio game simulates mysterious broadcasts
  • Players investigate fictional town of Blackwood in 1988
  • AI-generated atmospheric content adds unpredictability

More from Saturday 31 October →