PostgreSQL zero-downtime migration of a primary key from int to bigint (with Ruby on Rails specific notes)

A primary key integer field approaching overflow is a devops nightmare. We explain step by step to how we made the migration with zero downtime.You have an auto increment primary key int field and it’s nearing the maximum value for int: 2,147,483,647. If you run out of the values your PostgreSQL installation will go into a forced shutdown, most likely taking your application with it. The solution is, of course, to change the primary key to a bigint. However, if you’re running out of INTs, chances are that your table is also very large and a simple ALTER COLUMN command will take hours to run. Since it will lock the whole table it will require you to plan a maintenance window.
PostgreSQL zero-downtime migration of a primary key from int to bigint (with Ruby on Rails specific notes) #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/postgresql-zero-downtime-migration-of-a-primary-key-from-int-to-bigint-with-ruby-on-rails-specific-notes

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles