Sample Header Ad - 728x90

Alter columnt type from int to bigint with minimal downtime

1 vote
2 answers
843 views
I have several tables with id columns that are declared to be serial (i.e. integer type with default nextval()). Converting them to bigint seem to be quite straightforward:
ALTER TABLE my_table
ALTER COLUMN id
TYPE bigint;
But that might take a lot of time and lock the whole table. It's okay-ish solution for cases when the whole site is already down due to integer overflow, but not so good for provisional changes. How would one do that concurrently?
Asked by Eduard Sukharev (129 rep)
Dec 25, 2023, 12:12 PM
Last activity: Nov 28, 2024, 01:50 PM