From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Thomas Poty <thomas.poty@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: dealing with lock
Date: Fri, 06 Apr 2018 17:11:11 +0200
Message-ID: <1523027471.3170.10.camel@cybertec.at> (raw)
In-Reply-To: <CAN_ctniz+nQ5ABR8=VVnbpcKVGKjtivfF1AA_u9zbN-s8BrN-Q@mail.gmail.com>
References: <CAN_ctniz+nQ5ABR8=VVnbpcKVGKjtivfF1AA_u9zbN-s8BrN-Q@mail.gmail.com>
On Fri, 2018-04-06 at 16:58 +0200, Thomas Poty wrote:
> Here is a bit of context : we are migrating from MySQL to PostgreSQL and we have about 1000 tables.
> Some tables are quite small but some others are very large. The service provided to our clients
> relies on a high avaiability with a minimum down time due to any legal deadlines.
>
> So, lets imagine :
> in Transaction 1 : I am querying Table A (select)
> in Transaction 2 : I am trying to alter Table A ( due to our product evolution)
> in Transaction 3 : I am want to query Table1 (select)
>
> in MySQL : Transaction 1 retrieve data in Table A.
> Transaction 2 : is trying to alter Table A but it is blocked by Transaction 1
> Transaction 3 : Transaction 1 retrieves data in Table A ( Retreiving data is possible until Transaction 2 commit)
>
> In PostgreSQL, it is a bit different : Transaction 1 retrieve data in Table A.
> Transaction 2 : is trying to alter Table A but it is blocked by Transaction 1
> Transaction 3 : Transaction 3 cannot retrieve data because Transaction 2 did not terminate its transaction.
>
> So, with MySQL, the application is able to keep working with the table until the alter table completed.
>
> With PostgreSQL, the application will probably be blocked (until having the lock on this table).
> If I understand, if the alter table takes a long time (several hours) to execute, clients will be blocked during several hours.
>
> How do you deal with this problem? Maybe I missed something ?
The solution is to avoid ALTER TABLE statements that have to rewrite
the table outside of maintenance windows.
If your transactions are short, as they should be, it should not be
a big deal to add or drop a column, for example.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: laurenz.albe@cybertec.at, thomas.poty@gmail.com
Subject: Re: dealing with lock
In-Reply-To: <1523027471.3170.10.camel@cybertec.at>
References: <CAN_ctniz+nQ5ABR8=VVnbpcKVGKjtivfF1AA_u9zbN-s8BrN-Q@mail.gmail.com> <1523027471.3170.10.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