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

  • SEARCH
  • Home
  • 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 6578125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:43:51+00:00 2026-05-25T15:43:51+00:00

On a Postgres backed Rails application running on Heroku I am trying to add

  • 0

On a Postgres backed Rails application running on Heroku I am trying to add a boolean column with default set to false and null set to false (NOT NULL).

The migration takes hours upon hours to run (there are actually about 15 or so such fields that need to get added). Memory usage goes through the roof (5-6gb or more). I think this is because Postgres is wrapping the migration in a transaction and trying to load the whole table into memory so it can rollback on failure.

Without the field default or the NOT NULL the column is added in just a moment.

As an interim solution, I am adding the new column without any restrictions, updating all of the records with a false default value in batches of 1000 records, and then finally altering the column to have the default and NOT NULL requirements.

Now, the migration takes about 3-4 hours to run and uses only about 100mb of RAM.

Is there any better solution out there?

  • 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-05-25T15:43:51+00:00Added an answer on May 25, 2026 at 3:43 pm

    From your timing, I expect that you perform your ‘upgrade’ via RoR, which possibly means ‘row at a time’ processing. I just tested on a 300K rows table with a a primary key and 3 foreign keys, and adding a boolean costs about 5 seconds (too short to benchmark it exact, for me) The query:

    ALTER TABLE mine.trivally
        ADD COLUMN the_bool boolean NOT NULL DEFAULT 'True' ;
    

    Which suggests that your framework produces sub-optimal code. To say the least.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Rails app with a Postgres backend. I need to add full text
Since Postgres can only add columns at the end of tables, I end up
I have a (Postgres) DB table that I'd like to add a manual 'sort'
POSTGRES- I want update the Employees.zipcode_mod column in the Employees table for the 'invalid
In Postgres, is it possible to change the default format mask for a timestamp?
I am developing a windows application and using Postgres as backend database. At some
I'm new to postgres, so please take it easy on me. I'm trying to
Lets say I have two tables in Postgres: Name: table_rad Column Type id integer
I'm using Postgres and I'm trying to write a query like this: select count(*)
Connecting to postgres with rails was no big deal. rails -d postgresql app_name, setup

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.