From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Veerendra Pulapa <veerendra(dot)pulapa(at)ashnik(dot)com>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: Seeking Advice on Table Alterations without Downtime in PostgreSQL |
Date: | 2023-07-17 16:47:43 |
Message-ID: | b8359b9dc8b8ce7cb66477fcc7a993d9e6edfe5c.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
On Mon, 2023-07-17 at 16:31 +0000, Veerendra Pulapa wrote:
> I am interested in techniques or approaches that allow for seamless alterations such
> as adding/removing columns, modifying column data types, renaming columns, and
> altering constraints.
Adding, dropping and renaming columns is always fast.
Unless you have long running transactions, they will never give you trouble.
Changing the column data type is only fast if the types are binary compatible,
for example varchar(20) -> varchar(100) or varchar(10) -> text.
Other than that, the table has to be rewritten.
To do that without down time, you could define an additional column with
the new data type, fill ot with the value from the old column and then
drop the old column. This will cause bloat if you do it in a single
UPDATE, and constraints will require extra attention, but it is possible.
You cannot alter constraints in PostgreSQL. You have to drop and re-create
them.
Yours,
Laurenz Albe
From | Date | Subject | |
---|---|---|---|
Next Message | srinivas oguri | 2023-07-17 18:03:32 | Re: PostgreSQL 12 VS PostgreSQL 15 |
Previous Message | Veerendra Pulapa | 2023-07-17 16:31:55 | Seeking Advice on Table Alterations without Downtime in PostgreSQL |