Column widening without outage

From: Aniruddha Deshpande <daniruddha29(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Column widening without outage
Date: 2017-03-27 08:29:51
Message-ID: CAHU=hbhEDmhiPRmOKOi9=9K1MVxk9Xx0sRU4LmQG2NjbFVLSJw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi All,

We want to extend/widen the column without outage. But as column widening
takes ACCESS EXCLUSIVE LOCK, we have seen noticeable pause on
SELECT/INSERTS. This behavior was more noticeable in tables which has
composite Foreign keys. .We tried doing it like below which resulted in
minimizing the outage but still noticeable pause for INSERTS/UPDATE can be
seen.

Environment Details :
column_test=# select version();
version
---------------------------------------------------------------------------------------------------------------
EnterpriseDB 9.5.5.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7
20120313 (Red Hat 4.4.7-16), 64-bit
(1 row)

column_test=#

Steps Followed :

a. ALTER TABLE FINTRANS DROP CONSTRAINT FK_FINTRANS_SHOPTRANS;

b. ALTER TABLE FINTRANS ADD CONSTRAINT FK_FINTRANS_SHOPTRANS

FOREIGN KEY (MERCHANTID, SHOPTXNO)

REFERENCES SHOPTRANS (MERCHANTID, SHOPTXNO)

MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION NOT VALID;

c. ALTER TABLE fintrans ALTER COLUMN merchantid TYPE VARCHAR(255);

d. ALTER TABLE shoptrans ALTER COLUMN merchantid TYPE VARCHAR(255);

e. ALTER TABLE FINTRANS VALIDATE CONSTRAINT FK_FINTRANS_SHOPTRANS;

I have few queries on above problem, -

1. is there any way by which we can do the widening of column without
outage.

2. does ALTER TABLE ALTER COLUMN do re validation of all foreign keys again?

3.In this section of the Postgres documentation
https://www.postgresql.org/docs/9.2/static/release-9-2.html

it says -

E.21.3.4.2. ALTER

· Reduce need to rebuild tables and indexes for certain ALTER TABLE
<https://www.postgresql.org/docs/9.2/static/sql-altertable.html> ... ALTER
COLUMN TYPE operations (Noah Misch)

Increasing the length limit for a varchar or varbit column, or removing the
limit altogether, no longer requires a table rewrite. Similarly, increasing
the allowable precision of a numeric column, or changing a column from
constrained numeric to unconstrained numeric, no longer requires a table
rewrite. Table rewrites are also avoided in similar cases involving the
interval, timestamp, and timestamptz types.

· Avoid having ALTER TABLE
<https://www.postgresql.org/docs/9.2/static/sql-altertable.html> revalidate
foreign key constraints in some cases where it is not necessary (Noah Misch)

so, in what circumstances ALTER TABLE will avoid revalidating foreign keys
??

Your help will be much appreciated.

Regards,

Aniruddha

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2017-03-27 08:48:56 Re: New CORRESPONDING clause design
Previous Message Simon Riggs 2017-03-27 08:27:05 Re: Proposal for changes to recovery.conf API

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2017-03-27 09:58:35 daisychain rows to detect value
Previous Message Adrian Klaver 2017-03-20 13:54:44 Re: Equivalent data type for SQL_Variant not found