pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Asaf Flescher <asaf@armis.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE
Date: Tue, 2 Mar 2021 19:28:56 -0300
Message-ID: <20210302222856.GA16038@alvherre.pgsql> (raw)
In-Reply-To: <CABNzHgnQ7q-EN_gc_GTKsGMksbxxD8=XT03rT2CRme=21KD_FQ@mail.gmail.com>

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.





view thread (3+ messages)  latest in thread

Message-ID: <20210302222856.GA16038@alvherre.pgsql>
Permalink:  ../20210302222856.GA16038@alvherre.pgsql/
Also on:    postgresql.org/message-id/20210302222856.GA16038@alvherre.pgsql

 · 

reply

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: alvherre@alvh.no-ip.org, asaf@armis.com
  Subject: Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE
  In-Reply-To: <20210302222856.GA16038@alvherre.pgsql>
  References: <CABNzHgnQ7q-EN_gc_GTKsGMksbxxD8=XT03rT2CRme=21KD_FQ@mail.gmail.com> <20210302222856.GA16038@alvherre.pgsql>

* 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