Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Asaf Flescher <asaf(at)armis(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE
Date: 2021-03-02 22:28:56
Message-ID: 20210302222856.GA16038@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2021-Mar-02, Asaf Flescher wrote:

> I'm not sure if this is a bug or I'm missing something regarding how
> partitioning is supposed to work but I've noticed (in Postgres 12.6) that
> if I have a partitioned table, and then try to add a partition to it via
> CREATE TABLE ... PARTITION OF, the statement will grab an AccessExclusive
> lock on the partitioned table. Meanwhile, if I create that same table
> normally, then attach it to the partitioned table via ALTER table - no
> AccessExclusive lock.

It's a new feature in Postgres 12 actually -- we went great lengths to
be able to do ALTER TABLE .. ATTACH PARTITION without a full
AccessExclusive lock. However, it's just not possible to do the same
for CREATE TABLE .. PARTITION AS.

If you try the same in Postgres 11, you'll notice that both use an
AccessExclusive lock.

--
Álvaro Herrera Valdivia, Chile
Syntax error: function hell() needs an argument.
Please choose what hell you want to involve.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2021-03-02 23:12:44 self-made certs not quite right
Previous Message Karsten Hilbert 2021-03-02 20:23:51 Aw: Re: Localizing stored functions by replacing placeholders in their body