简体   繁体   English

如何使用python psycopg2改进大表中的添加列查询

[英]How to improve add column query from large table using python psycopg2

I am using following command to add the new column in existing large table in postgresql. 我正在使用以下命令在postgresql的现有大表中添加新列。

alter table table_name add column column_name bigserial

Is there any way to increase the performance of above query on large table? 有什么方法可以提高大型表的上述查询性能?

to reduce lock time, you can: 为了减少锁定时间,您可以:

alter table table_name add column column_name bigint;
create sequence seq_name;
with c as (select * from table_name) 
  update table_name set column_name = nextval('seq_name'::regclass);

alter table table_name alter column column_name set default nextval('seq_name');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM