Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4Wk2-0000do-TL for pgsql-general@arkaria.postgresql.org; Fri, 06 Apr 2018 19:09:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f4Wk1-0001gz-PW for pgsql-general@arkaria.postgresql.org; Fri, 06 Apr 2018 19:09:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4Wk1-0001gq-BH for pgsql-general@lists.postgresql.org; Fri, 06 Apr 2018 19:09:41 +0000 Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f4Wjx-0004Ve-4M for pgsql-general@lists.postgresql.org; Fri, 06 Apr 2018 19:09:39 +0000 Received: by mail-io0-x232.google.com with SMTP id e79so2881404ioi.7 for ; Fri, 06 Apr 2018 12:09:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=0xKFwzISkuR94ywKWKx3+g6aWW6458Mz+R3G/Y2BBHQ=; b=ZgMTY4hIJxFQ6O9x72QO+/8EJz730ED70tS1OntUeenhDjnID9TPZaoN7im4bmEZIW vdBNVwvB0WcGMFoJ2693kXEM05NITsap/EOz9THxXyIXYQTxIqmi85+6LDwIKwaFqmOT VRNnRIaMuVrvsMJ0kZi4eV3UT438nbkeIv1bfTNH2o/MxyJDdN60DDtEYedgLvEeAyth 3GvwQ1/Mq9ZIDPiANj2pQWX0zhP1syWyZf53rv8dq6oztHmtzQiRAp8ld7JDHVhaiinn Y6TpeKz73MwqF5Id0bBvqqkAAOOiEwrcAsIqoNN7t0g5zGmZBz0egwbr+EuovgPirJZo oq5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=0xKFwzISkuR94ywKWKx3+g6aWW6458Mz+R3G/Y2BBHQ=; b=Ky7J7FSj/F9R5QpxtRaycgZGda4eh1pT/cgb7e993IhvIWZj7mxmWgb6Qjqeq2qVLs kvQIm3cBJaT0b3YxMqYb+I+sYMsSEnwwN7AyZ+K6npjop0c9kncBD6TeCPm57+XnAZV5 3lOjblTksjVOjN4kjzssseMJFlYdNTlx31sgTn/gAtJz6iX5iqPaqBb0M7ESOkFEP2Ms HowwZPjDadyGCP2G0eGFmejSeG4zW82o8MsOroyheQSYJGTG2on6b+7uoZIgoSaaU+N7 LmLxl86n3pP+iq19OeWtxv7iW3KT1CmTrOxj4X9ix4xxEoNujVgippK/WHMKvNOidcfG dK/g== X-Gm-Message-State: ALQs6tBvbrX229hKsu7qa8jeE7nGypc/jZcOYUCkE/1P1SNBkkwJ5jUp Yq/EVb9Wcb/paxQ4VLrqT4OvyZwk+jbg8Hiqjz5WIlXc X-Google-Smtp-Source: AIpwx4+2dCHRrNHsnLgbWvCh0k1XFHxbMdf6Isiiuub3Q5Iolj6z/rWPbHk9j+DoKj9OWrP439wT2NUeItmQIYdgUUs= X-Received: by 10.107.40.147 with SMTP id o141mr25538591ioo.72.1523041775930; Fri, 06 Apr 2018 12:09:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.192.170.55 with HTTP; Fri, 6 Apr 2018 12:09:35 -0700 (PDT) In-Reply-To: <1523027471.3170.10.camel@cybertec.at> References: <1523027471.3170.10.camel@cybertec.at> From: Thomas Poty Date: Fri, 6 Apr 2018 21:09:35 +0200 Message-ID: Subject: Re: dealing with lock To: Laurenz Albe Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="001a1141d81808500d056932ccdf" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --001a1141d81808500d056932ccdf Content-Type: text/plain; charset="UTF-8" Thank you Laurenz ! We will certainly have to change our release management. Is there a way to identify the list of statements that have to rewrite the table. If I am right, at least these statements need to do this : - create a unique index - add a column with a default value Regards, Thomas 2018-04-06 17:11 GMT+02:00 Laurenz Albe : > 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 > --001a1141d81808500d056932ccdf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you Laurenz !


We will certainly have to change our release mana= gement.

Is there a way to identify the list of statements that= have to rewrite the table.

If I am right, at least these stat= ements need to do this :
- create a unique index
- add a column= with a default value

Regards,

=C2=A0Thomas
=C2= =A0

2018-04-06 17:11 GMT+02:00 Laurenz Albe <laurenz.albe@cybertec.at= >:
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 a= nd we have about 1000 tables.
> Some tables are quite small but some others are very large. The servic= e 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 e= volution)
> 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 Transa= ction 1
> Transaction 3 : Transaction 1 retrieves data in Table A ( Retreiving d= ata 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 Transa= ction 1
> Transaction 3 : Transaction 3 cannot retrieve data because=C2=A0 Trans= action 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 havin= g 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

--001a1141d81808500d056932ccdf--