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

Started by jiyeover 3 years ago4 messages
#1jiye
jiye_sw@126.com

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 :
https://dba.stackexchange.com/questions/293992/make-alter-table-wait-for-lock-without-blocking-anything-else.

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!

In reply to: jiye (#1)
Re: Is there any plan to support online schem change in postgresql?

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

#3jiye
jiye_sw@126.com
In reply to: hubert depesz lubaczewski (#2)
3 attachment(s)
Re:Re: Is there any plan to support online schem change in postgresql?

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:

Show quoted text

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

Attachments:

image.pngimage/png; name=image.pngDownload
image.pngimage/png; name=image.pngDownload
�PNG


IHDR��_���sRGB���gAMA���a	pHYs���o�d�IDATx^��}�������@@�w�F�UQQDD4�@D��M��HLi�/�/eCbH4bU��2���k���Z.Q+���1���ET^��H� "a���g����>s��{���S�wfz�v�>�}���{��;��v���������~�s�7;����u]:2�q��������3�1�����]�c�-��0g�k������o��������s�[�����?����������O�
���]~y:��?������n�����e���{4f�;�W�r+y����f���;�-���mHw��}��9��tLC��'����n���c�5��jL�0�=������.��wq���.�����[��/�y���zy��>}�����\�b����kl\��E�����K�{���i�z�)w�-��c��30�7�9��t�s7�|�;6�7���H��dy���-���r�����>�����t����_x�7}z���@���q�����<������/��>u�Q�������|�x�]w�;����n��4�t2���e��M�6���T�X��mh���g�����Y��������Mv���N�;9p��eA�[�p�2e��[�y��=���xo�/�v}�i���n�f�[V��WoMRpXF%��_|��}�,�@���������W��������h��#�1o�{���y��o��?��s���^�/v�m��:t��6��Z)���9:|����������g�B������y������w�
���[�����������|��'n���V�Q��|
N��np�f�p��A�J0��X�Z�n�;9��y���m~��:ur3g�L�m>��2|z������}�+Z����O`�0�����'�h��}�Y{EQ�x�%�/���ot/����c���4��7��'�l�� �x$��M�6��kqr\lM����q��������Y���:t����}�?N
���MP|�yV�oMv���^��y��Wf�r;���d���t}�;�
v�����v+�Z���I���������Ia�E��o��m�>�����;�����w+��u���,�y�N����o���;,�i���������t0���������(��o�e?��c~3���4��Zr5t�P+�W���Zj���w�^�y��{X��G&��@�6�-�g���&O�\*X2�g`�`>���)�$���������lO���>���#�8�
��n��mK�P���a���VH�~����<?����q����o�8.����x����B�������Z��AA���$=��}b���������'d�_K*)}������O~>���z!��?���k���a~�����TY(��l^���W:�9����|�MN,���c:��$9�IB�,m�5���[g!����%��W��������L����VKm����~:�u���iPM�I�����E-�=��ISi��c����/5	�ah�"�l������c�mm�4�<��C���Uo��b��0��EP���3�<��o����W/k�[���m���S�=����R+��)�u)��0�������H*alK�JZ�)LDD�]:c��XDD$*�j����}�\d����������w�pv����[�J?J����X������\��_�ni�����oj+V��������8�����f��[D��Z<�,]����5��x���s������{�s�+���_�B��[{�n��q���O~b�'��,�O���<6<��EBs�+��|��@^���C�������?zED�VJ���I0P��5vp�����������(�i���|�I���Z5|������~��������x-�3�|����'g>��*���{�#������/�����u��4��s�x>��H-58c����������y�!�(���S����k�{?�%�T�_����o.���7�������������j.XsfC����q�������$�0�<������!O����?���:�U�y8O����h>M��j���H-5,]�t�����6Oa�}���5���{?���Z=�2P R�2�������S~YGE�YD����3��3��~��������C���S��l�2$���F����^�|DD�U��B�6�3�����������f!j���<$��&�z��3�XgG<u����������~���z/w;3��7w�����j����g{��"}���&���bC�#"R���xO@��"��;����n��5���9(�����4g\�&3�
�O�k�8���h>�|s}��~)���+�OS��IRD�kX���E��;�(��a�&3����h�=�i)Ds�SU��r8#�������[��50��A�Uv�����0��^���J�����B���]�����$���o��$.�������o��9r�M�p������{[w�/������\#H����������YSR����<�L��z����TWm�}t�;j�(��.�T�q7�����)i��n��]�S wG��,�q�������"=�i%�^�p��f�_~�?|�p�z����,3{�3i%��g?����o�2���UW]e����{J�����B�����%8P��.
�|p��	gY����H�����i��f���y����n���GH��!]��t�fn�n/t>��+����{���-|W�""�RzV���������9+!���f�/*��r���n����^D����x_��&A@�>}��`�R�
�w<+������p��""-e�,g)��[��"�e\�'�*?D�%�kb�j�:c����"""Q)���HT
,""�>�>��s�a(]{��MNS�0P�v��m�m�-�;�/C>�H;c�`�>I7?�k��OZi��c���r�4��[�5�����m����,"��O����������������~��C�4s�Bw�)P�g �mQ�|��a���J�9S��q�����P��?�7��.�o�J]��v��w�sV6=�'#FzB�=�R�C0�7�x#����ze�8�L��s�����~�ry�^�YDZN��{�H!��o}+����v���.�}�
��ibv�K?1y���N�,��x�d�@����u�k,����}��o�����s6����� -�6mZ��|���������+F��B�s>�H�	,O��8��%f��EQ�1���yX�}>- =\�fY����W�LO��#$��L�<�.r��l��?t�l7�L6c�Om�MOTx�'�q��]�n����"�:��i�����3�^���=j�Y�.�	F�����]��pE��E^�]�z����LO��#$��P�����������+�~\��i�$}�;S�>��y��j�[>�H��*�P;��K�*��|3X(
1�1�Cs��m�zK��J�,���*����Hh�F\���Y�.�	D�t�[k���RW�E�����g�S�����ys:�e�V>W{�HD�����GAD�7����=��O�4��n��Y/��:��c�v��\����)S����e���C�=�r��Q��m��z���.�k>����f����'���(i�jJ������-���~��k���kY"�4U����N��Bc�`�ys1���������b:����]JL�u��i
��������3��W��-�k7\a[�����%�����}��l���k���W����^��Ba@D��/�<~_��<����2�{KR>����3��iVx��,�PC�����{��p������H��&����x/""R����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��""u��+�t&LH?I[�j��������D���E�J�u�]�~��z������;mhL5�K���!��RyU�)������o����:S=�-����������_�~�wp`�B�p�-]����5��"���-��j�'����������9s���W/���{�����O>�����Z��%j
���]������a�{���m���c�P��|��n��M�i�5�\��������E�8�������u���3�8��S{�����@��i�~���s��6��G�Z���O7u�Tw��'�{����w��{����g���m����r��r����w����!C��m���2.��B�����4�
�Z	5��^{��'].t3g����O3�!���9��r��k�w�	'������=��C���?��}��Ur�����+W��<j��|�B�����|�$4=!���W�?H[�<j,��}�H�z�?���[�����JB����s������iB�?L�4�
8�>�-~�a+?B��q������/O?�Q���������Z�n�����~:t�o&N��z���>��sw�}���[������0�%�\b��w�qK�,qt������W]u�m\>��������3�Xmm�����7�p����0`�m���������T�����lG��~����i������o�z�����-[����k�����r�!���s�|�������l���s������/[�{��7mYEi�����L;f�;������u��F�m���K{O��"o��oo���c�qs����YS�L������|.���|.���u��������m����O�����A��Q$t��+
����T$$���I'�d�ev�!�� �L�6�}��g����s~����te+�E|>�o�����������]���#\�v����-���;���<��%������4Dp��	5#_���s�]wY��G�A����7��W����=�X�\���|�I=�����#;��7�l����_��v���VC�I'��{vp���
�H#;�������U	�3P�z���ly���5�"�O�v�kV�r�+'$�Q�?��\$4=����Wq����*d�(�^��Oc�N6oB�	��
����+J���>����FVe�_��v:����j��2g���f_F
��������=��]kM5���F�h��|��
N!K������.���=i�,�|�|��4�����c���=b��#������i{�X6A��0P�Mm���OVc�K���k��q�}5D��^��'��i�����e��5��+�9&�?��PP����)�/��2�
�����f8�������sZ��~���ZM����i(��A��B�Z��&�������
fg>k��I�����i)�Y�N�:���S/��5��M�{�w5,�>��w�n�<j�{������7�c��6�]4UpA4/�S���v}d�E��)��pFE�$;�kh����}����(��w��
E������~������NE��3B�'�r�i����&[.��X��b���B�'���y|Q&���6�7��RY���\���\`���_~��T�:j�(7r�Hw��G��.���<|���i5��|�|�?�|��wo���EB������il�>������3��6I�;��#�9�����";
��?�x�X�Edvn�7��e���K �=�|sJQ�	,��L��Y���g�_|����?����
��������nZ8���l���e���'j��z����o�@�|�*�O5��RzB��}�v���6
g�|�Y���(���PE���/�`�Y,�Y���G|�8$�W���tE����8��Sm��X��������<��'�/��1�2���_����}4ysC�
(�A`aC~��v��Qs�VF�����o_�!�j��+��'���A���g�N"��>����9�����s��R!���-��n��v����K/�tR����;��w�pw�<X�Yg�e�1?�*��ch��0_�����gvz�S5;-i"������={Z�H����|b�(�H��U��E�\�?���RzB��}�����P��X��j��u�U���}#TQ>s�'�*.LC3Rh^��O�c�|Z�zui�	�&��C����:1�[�C��1�na��Y��:"4�m�y������K�w0�
7���oKDD��2���[�����nyO �T���%�
m�M�)���q���W����}~���V�������4��Xj��&""C�����H���"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D��"""Q)���HT
,""����D���/�����C�IEND�B`�
image.pngimage/png; name=image.pngDownload
In reply to: jiye (#3)
Re: Re: Is there any plan to support online schem change in postgresql?

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/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...

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