Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PostgreSQL-- several small tip for performance optimization

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Reclaim disk space

In PostgreSQL, rows deleted or updated using delete and update statements are not actually deleted, but are simply set to be deleted or expired on the physical address of the old version of the row. Therefore, when the data in the data table changes very frequently, the space occupied by the table will become very large after a period of time, but the amount of data may not change much. To solve this problem, you need to perform regular VACUUM operations on data tables where the data changes frequently. Now the new version of PostgreSQL automatically executes VACUUM.

Use the VACUUM and VACUUM FULL commands to reclaim disk space

Postgres=# vacuum arr_test

Postgres=# vacuum full arr_test

Create test data: postgres=# create table arr (id serial, value int, age int) # create test table postgres=# insert into arr (value, age) select generate_series (1, 1000000) as value, (random () * (10 ^ 2)):: integer; # insert 100W test data postgres=# select pg_relation_size ('arr') # View table size pg_relation_size-44285952 (1 row) postgres=# delete from arr where id=300000 and id

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report