- Mastering PostgreSQL 10
- Hans Jürgen Sch?nig
- 349字
- 2021-06-30 19:03:52
Optimizing storage and managing cleanup
Transactions are an integral part of the PostgreSQL system. However, transactions come with a small price tag attached. As already shown in this chapter, it can happen that concurrent users will be presented with different data. Not everybody will get the same data returned by a query. In addition to this, DELETE and UPDATE are not allowed to actually overwrite data as ROLLBACK would not work. If you happen to be in the middle of a large DELETE operation, you cannot be sure whether you will be able to COMMIT or not. In addition to this, data is still visible while you perform DELETE, and sometimes data is even visible once your modification has long since finished.
Consequently, this means that cleanup has to happen asynchronously. A transaction cannot clean up its own mess and COMMIT/ROLLBACK might be too early to take care of dead rows.
The solution to this problem is VACUUM:
test=# \h VACUUM
Command: VACUUM
Description: garbage-collect and optionally analyze a database
Syntax:
VACUUM [ ( { FULL | FREEZE | VERBOSE | ANALYZE } [, ...] ) ] [ table_name [ (column_name [, ...] ) ] ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table_name ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table_name [ (column_name [, ...] ) ] ]
VACUUM will visit all pages that potentially contain modifications and find all the dead space. The free space found is then tracked by Free Space Map (FSM) of the relation.
Note that VACUUM will, in most cases, not shrink the size of a table. Instead, it will track and find free space inside existing storage files.
What this means to the end users will be outlined in the Watching VACUUM at work section of this chapter.
- 大數據導論:思維、技術與應用
- Mastering Matplotlib 2.x
- TestStand工業自動化測試管理(典藏版)
- 極簡AI入門:一本書讀懂人工智能思維與應用
- Julia 1.0 Programming
- 樂高創意機器人教程(中級 下冊 10~16歲) (青少年iCAN+創新創意實踐指導叢書)
- AWS Administration Cookbook
- CompTIA Network+ Certification Guide
- Docker High Performance(Second Edition)
- 工業機器人操作與編程
- Storm應用實踐:實時事務處理之策略
- 工業機器人運動仿真編程實踐:基于Android和OpenGL
- 電氣控制與PLC技術應用
- 單片機C語言應用100例
- Dreamweaver CS6精彩網頁制作與網站建設