From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Veerendra Pulapa <veerendra.pulapa@ashnik.com>
To: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Re: Seeking Advice on Table Alterations without Downtime in PostgreSQL
Date: Mon, 17 Jul 2023 18:47:43 +0200
Message-ID: <b8359b9dc8b8ce7cb66477fcc7a993d9e6edfe5c.camel@cybertec.at> (raw)
In-Reply-To: <SE1P216MB2309B830057A3DFA53D938E1F13BA@SE1P216MB2309.KORP216.PROD.OUTLOOK.COM>
References: <SE1P216MB2309B830057A3DFA53D938E1F13BA@SE1P216MB2309.KORP216.PROD.OUTLOOK.COM>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: laurenz.albe@cybertec.at, veerendra.pulapa@ashnik.com
Subject: Re: Seeking Advice on Table Alterations without Downtime in PostgreSQL
In-Reply-To: <b8359b9dc8b8ce7cb66477fcc7a993d9e6edfe5c.camel@cybertec.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox