Search Postgresql Archives

Locks in creating a partition in CREATE TABLE vs ALTER TABLE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux