Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:18:11+00:00 2026-06-03T05:18:11+00:00

In my project having 23 million records and around 6 fields has been indexed

  • 0

In my project having 23 million records and around 6 fields has been indexed of that table.

Earlier I tested to add delta column for Thinking Sphinx search but it turns in holding the whole database lock for an hour. Afterwards when the file is added and I try to rebuild indexes this is the query that holds the database lock for around 4 hours:

"update user_messages set delta = false where delta = true"

Well for making the server up I created a new database from db dump and promote it as database so server can be turned live.

Now what I am looking is that adding delta column in my table with out table lock is it possible? And once the column delta is added then why is the above query executed when I run the index rebuild command and why does it block the server for so long?

PS.: I am on Heroku and using Postgres with ika db model.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:18:13+00:00Added an answer on June 3, 2026 at 5:18 am

    Postgres 11 or later

    Since Postgres 11, only volatile default values still require a table rewrite. The manual:

    Adding a column with a volatile DEFAULT or changing the type of an existing column will require the entire table and its indexes to be rewritten.

    Bold emphasis mine. false is immutable. So just add the column with DEFAULT false. Super fast, job done:

    ALTER TABLE tbl ADD column delta boolean DEFAULT false;
    

    Postgres 10 or older, or for volatile DEFAULT

    Adding a new column without DEFAULT or DEFAULT NULL will not normally force a table rewrite and is very cheap. Only writing actual values to it creates new rows. But, quoting the manual:

    Adding a column with a DEFAULT clause or changing the type of an
    existing column will require the entire table and its indexes to be rewritten.

    UPDATE in PostgreSQL writes a new version of the row. Your question does not provide all the information, but that probably means writing millions of new rows.

    While doing the UPDATE in place, if a major portion of the table is affected and you are free to lock the table exclusively, remove all indexes before doing the mass UPDATE and recreate them afterwards. It’s faster this way. Related advice in the manual.

    If your data model and available disk space allow for it, CREATE a new table in the background and then, in one transaction: DROP the old table, and RENAME the new one. Related:

    • Best way to populate a new column in a large table?

    While creating the new table in the background: Apply all changes to the same row at once. Repeated updates create new row versions and leave dead tuples behind.

    If you cannot remove the original table because of constraints, another fast way is to build a temporary table, TRUNCATE the original one and mass INSERT the new rows – sorted, if that helps performance. All in one transaction. Something like this:

    BEGIN
    
    SET temp_buffers = 1000MB;  -- or whatever you can spare temporarily
    
    -- write-lock table here to prevent concurrent writes - if needed
    LOCK TABLE tbl IN SHARE MODE;    
    
    CREATE TEMP TABLE tmp AS
    SELECT *, false AS delta
    FROM   tbl;                -- copy existing rows plus new value
    -- ORDER BY ???            -- opportune moment to cluster rows
    
    -- DROP all indexes here
    
    TRUNCATE tbl;              -- empty table - truncate is super fast
    
    ALTER TABLE tbl ADD column delta boolean DEFAULT FALSE; -- NOT NULL?
    
    INSERT INTO tbl
    TABLE tmp;                 -- insert back surviving rows.
    
    -- recreate all indexes here
    
    COMMIT;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use MVC for a new project after having been around the
If you have the following: Asp.Net MVC 2 project having object classes that define
I'm having a problem when I try to insert an array that has a
When some project is having all that ltmain, aclocal.m4 and other autogen.sh it brings
I am working on a project that has the potential to have a large
I'm having some trouble with references to an external project that contains services for
This has been asked a million times it appears, but I must be feeling
I have web application Project having RPC call. one RPC async is working fine.
I have a Delphi XE2 project having components like Label1 , BitBtn1 and Image1
I want to implement a html audio player in my project having playlist with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.