Thread: Is there any plan to support online schem change in postgresql?

Is there any plan to support online schem change in postgresql?

From
jiye
Date:
Hi,

As we know postgres using high level lock when do alter table or other ddl commands,
It will block any dml operation, while it also will block by long term dml operation.

Like what discuss as follow :

I know that postgres try to avoid rewrite table when alter table happen , and so far, it support serveral ddl using concurrently feature,
Like create indexes. But like alter table add/drop colum, alter column type, it also will trigger rewrtie table . Long term block will make application offline in long times.

So is there any plan to support these ddl online and lock free?if not could you explain the  technological difficulty ?

Thanks and wating your respond!

Re: Is there any plan to support online schem change in postgresql?

From
hubert depesz lubaczewski
Date:
On Tue, Oct 11, 2022 at 05:43:03PM +0800, jiye wrote:
> As we know postgres using high level lock when do alter table or other ddl commands,
> It will block any dml operation, while it also will block by long term dml operation.

Most of the things can be already done in non-blocking (or almost
non-blocking way) if you just do it in a way that takes concurrency into
account.

Specifically - I have no problem adding/deleting columns.

Best regards,

depesz




But, as follow, if txn1 not commit (just like long term readonly txn), it will block txn2's ddl job,  why alt add/drop column can not concurrently with read only access?

txn1: long term txn not commit access t1.
txn2 waiting txn1 to commit or abort.

txn3 wait txn2...




At 2022-10-11 18:05:01, "hubert depesz lubaczewski" <depesz@depesz.com> wrote: >On Tue, Oct 11, 2022 at 05:43:03PM +0800, jiye wrote: >> As we know postgres using high level lock when do alter table or other ddl commands, >> It will block any dml operation, while it also will block by long term dml operation. > >Most of the things can be already done in non-blocking (or almost >non-blocking way) if you just do it in a way that takes concurrency into >account. > >Specifically - I have no problem adding/deleting columns. > >Best regards, > >depesz
Attachment

Re: Re: Is there any plan to support online schem change in postgresql?

From
hubert depesz lubaczewski
Date:
On Tue, Oct 11, 2022 at 08:31:53PM +0800, jiye wrote:
> But, as follow, if txn1 not commit (just like long term readonly txn), it will block txn2's ddl job,  why alt
add/dropcolumn can not concurrently with read only access?
 
> txn1: long term txn not commit access t1.
> txn2 waiting txn1 to commit or abort.
> txn3 wait txn2...

1. Please don't share code as screenshots.
2. If I understand your text above correctly, then the solution is
   trivial:
   https://www.depesz.com/2019/09/26/how-to-run-short-alter-table-without-long-locking-concurrent-queries/

depesz