pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedSeeking Advice on Table Alterations without Downtime in PostgreSQL
2+ messages / 2 participants
[nested] [flat]
* Seeking Advice on Table Alterations without Downtime in PostgreSQL
@ 2023-07-17 16:31 Veerendra Pulapa <veerendra.pulapa@ashnik.com>
0 siblings, 1 reply; 2+ messages in thread
From: Veerendra Pulapa @ 2023-07-17 16:31 UTC (permalink / raw)
To: pgsql-admin
Dear PostgreSQL Community,
I am writing to seek guidance on performing table alterations without incurring downtime. As a member of the community, I would greatly appreciate any insights or best practices you could provide in this regard.
Specifically, 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.
Thank you for your time and support. Your expertise will be highly valuable to me.
Br,
Veerendra Pulapa
+91-9949349894
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Seeking Advice on Table Alterations without Downtime in PostgreSQL
@ 2023-07-17 16:47 Laurenz Albe <laurenz.albe@cybertec.at>
parent: Veerendra Pulapa <veerendra.pulapa@ashnik.com>
0 siblings, 0 replies; 2+ messages in thread
From: Laurenz Albe @ 2023-07-17 16:47 UTC (permalink / raw)
To: Veerendra Pulapa <veerendra.pulapa@ashnik.com>; 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2023-07-17 16:47 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 16:31 Seeking Advice on Table Alterations without Downtime in PostgreSQL Veerendra Pulapa <veerendra.pulapa@ashnik.com>
2023-07-17 16:47 ` Laurenz Albe <laurenz.albe@cybertec.at>
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