简体   繁体   中英

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.

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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