You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I call alter_table_set_access_method there is some period of time where there is an
AccessExclusiveLock set on the parent table.
This lock can be set for a while because I'm working on very large 0.3T bytes partitions.
# SELECTn.nspnameAS schema_name,
c.relnameAS table_name,
l.locktype,
l.mode,
l.grantedFROM
pg_locks l
JOIN
pg_class c ONl.relation=c.oidJOIN
pg_namespace n ONc.relnamespace=n.oidWHEREc.relname='calls';
schema_name | table_name | locktype | mode | granted
-------------+------------+----------+---------------------+---------
v1 | calls | relation | AccessShareLock | t
v1 | calls | relation | AccessExclusiveLock | t
v1 | calls | relation | AccessShareLock | f
Even table metadata are not accessible: \dt+ v1.calls will just wait for the lock release.
From PG documentation:
Only an ACCESS EXCLUSIVE lock blocks a SELECT (without FOR UPDATE/SHARE) statement.
This is problematic in my usecase because PG cannot serve data to end user.
I forgot to mention that I use citus on single node, I'm mainly interested on columnar storage.
Here is a few suggestions, not sure what they imply:
Add a parameter to choose less drastic lock mechanism that permits read. I may have read inconsistencies for a short period, but I would be fine with it I think.
Reduce the scope of the lock (maybe it's mandatory for the partition swapping ?). My application can guarantee it won't write in old partition. If so that's a bug on my side, I can take the blame.
PS: I found this bug, somehow related #7177 (I think the deadlock comes from the same lock I describe here)
Thanks
The text was updated successfully, but these errors were encountered:
jprudent
changed the title
alter_old_partitions_set_access_method AccessExclusiveLockalter_table_set_access_method AccessExclusiveLock
Jun 20, 2024
It looks like this is not Citus that explicitely set the lock.
This is pseudo SQL of the what does Citus when a table is converted
begin;
-- create the target partition with new storage without any index, constraints, ...createtablenew_partition;
-- copy the datainsert into new_partition select*from partition;
-- 🔒 the lock is set here altertable parent detach partition
droptable partition;
altertable new_partition rename to partition;
-- ⌚ this can be very long:altertable partition create index, constraints;
altertable parent attach partition;
-- 🔓 the lock is released herecommit;
The lock on the parent table is granted automatically by PG when we detach the partition (which is ok); and it's released once the tx ends.
If we could exclude the creation of index, constraints, ... from the time the lock is granted, that would greatly reduce the time my application freeze to a few seconds, just to do:
Is it possible to create the index and constraints just after the copy of the data, (and just before the detach that creates the lock) ? That would considerably decrease the locking time.
Hello,
When I call
alter_table_set_access_method
there is some period of time where there is anAccessExclusiveLock set on the parent table.
This lock can be set for a while because I'm working on very large 0.3T bytes partitions.
Even table metadata are not accessible:
\dt+ v1.calls
will just wait for the lock release.From PG documentation:
This is problematic in my usecase because PG cannot serve data to end user.
I forgot to mention that I use citus on single node, I'm mainly interested on columnar storage.
Here is a few suggestions, not sure what they imply:
PS: I found this bug, somehow related #7177 (I think the deadlock comes from the same lock I describe here)
Thanks
The text was updated successfully, but these errors were encountered: