Re: Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure
Дата
Msg-id 202405142045.avyazkmi6kq2@alvherre.pgsql
обсуждение исходный текст
Ответ на Using ALTER TABLE DETACH PARTITION CONCURRENTLY inside a procedure  ("Dirschel, Steve" <steve.dirschel@thomsonreuters.com>)
Список pgsql-general
On 2024-May-14, Dirschel, Steve wrote:

> But when I try and run the command inside the procedure it throws this error:
> 
> STATE: 25001
> MESSAGE: ALTER TABLE ... DETACH CONCURRENTLY cannot run inside a transaction block
> CONTEXT: SQL statement "alter table t2.test1 detach partition t2.test1_gentime_20240511 concurrently"
> PL/pgSQL function part.partition_maintenance() line 323 at EXECUTE

Yeah, ouch.

> The documentation states:
> 
> CONCURRENTLY cannot be run in a transaction block and is not allowed if the partitioned table contains a default
partition.

Right.

> Is there an option to call that CONCURRENTLY inside a procedure as I describe?

Not at the moment.  The issue is that CONCURRENTLY needs to commit a
transaction internally and start a new one, and to ensure that works
correctly we check that it's being executed as a "top-level command",
which rules out procedures.  It may be possible to relax that
restriction when run inside procedures, given that procedures need
transaction control of their own anyway so we could arrange for the
right things to happen; but this is hypothetical and I don't know that
anybody has attempted to implement that.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/



В списке pgsql-general по дате отправления:

Предыдущее
От: Dimitrios Apostolou
Дата:
Сообщение: pg_stat_io clarifications: background worker, writes and reads
Следующее
От: sud
Дата:
Сообщение: Re: Adding constraints faster