pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedLocks in creating a partition in CREATE TABLE vs ALTER TABLE
3+ messages / 2 participants
[nested] [flat]
* Locks in creating a partition in CREATE TABLE vs ALTER TABLE
@ 2021-03-02 20:18 Asaf Flescher <asaf@armis.com>
2021-03-02 22:28 ` Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE Alvaro Herrera <alvherre@alvh.no-ip.org>
0 siblings, 1 reply; 3+ messages in thread
From: Asaf Flescher @ 2021-03-02 20:18 UTC (permalink / raw)
To: pgsql-general
Hi,
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. Short recreation -
In one session:
CREATE TABLE stuff (stuff_id int) PARTITION BY LIST (stuff_id);
BEGIN;
SELECT * FROM stuff;
Then in a second session:
CREATE TABLE stuff_1 PARTITION OF stuff FOR VALUES IN (1); (Will get stuck,
and a query on pg_locks will show an ungranted AccessExclusive lock).
CREATE TABLE stuff_1 (LIKE stuff); (Will work)
ALTER TABLE stuff ATTACH PARTITION stuff_1 FOR VALUES IN (1); (Will work)
Logically, the two approaches are doing the same thing, are they not? Or am
I missing something?
Would appreciate any advice here,
Asaf
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE
2021-03-02 20:18 Locks in creating a partition in CREATE TABLE vs ALTER TABLE Asaf Flescher <asaf@armis.com>
@ 2021-03-02 22:28 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-03-02 23:15 ` Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE Asaf Flescher <asaf@armis.com>
0 siblings, 1 reply; 3+ messages in thread
From: Alvaro Herrera @ 2021-03-02 22:28 UTC (permalink / raw)
To: Asaf Flescher <asaf@armis.com>; +Cc: 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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE
2021-03-02 20:18 Locks in creating a partition in CREATE TABLE vs ALTER TABLE Asaf Flescher <asaf@armis.com>
2021-03-02 22:28 ` Re: Locks in creating a partition in CREATE TABLE vs ALTER TABLE Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2021-03-02 23:15 ` Asaf Flescher <asaf@armis.com>
0 siblings, 0 replies; 3+ messages in thread
From: Asaf Flescher @ 2021-03-02 23:15 UTC (permalink / raw)
To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-general
Right, I see I was unclear - I did know it was a new feature in Postgres
12, I just thought it applied to both cases, since the documentation makes
no such distinction. Wanted to make sure I wasn't missing something basic
before using the ALTER TABLE thing as a workaround.
Thanks!
On Tue, Mar 2, 2021 at 5:29 PM Alvaro Herrera <alvherre@alvh.no-ip.org>
wrote:
> 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.
>
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-03-02 23:15 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 20:18 Locks in creating a partition in CREATE TABLE vs ALTER TABLE Asaf Flescher <asaf@armis.com>
2021-03-02 22:28 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2021-03-02 23:15 ` Asaf Flescher <asaf@armis.com>
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