PostgreSQL 執行進度監控:VACUUM 、ANALYZE、CREATE INDEX 、CLUSTER、Base Backup


 

1、背景

在PG中,我們經常因為執行不知道多久結束而苦惱,主要集中在:

1)vacuum、vacuum full(阻塞讀寫)、analyze

2)pg_dump、pg_restore,缺少進度條,尤其對於大表的導出,只能通過數據量大致估算,但數據在DB中和磁盤上的量是有偏差的。

3)create index(不會阻塞讀取,會阻塞寫入,在創建時,你不知道花多少時間,無法評估業務的阻塞)、reindex(會阻塞讀寫)

 

pg_basebackup 這個可以通過查看復制了多少數據量,來大概估算。

 

2、現狀

PG9.6支持了pg_stat_progress_vacuum,PG13目前有如下5個進度視圖:

27.4.1. ANALYZE Progress Reporting
27.4.2. CREATE INDEX Progress Reporting
27.4.3. VACUUM Progress Reporting
27.4.4. CLUSTER Progress Reporting
27.4.5. Base Backup Progress Reporting

 

官方文檔有詳細說明: 

https://www.postgresql.org/docs/13/progress-reporting.html

 

pithe=# \d pg_stat_progress*
              View "pg_catalog.pg_stat_progress_analyze"
          Column           |  Type   | Collation | Nullable | Default
---------------------------+---------+-----------+----------+---------
 pid                       | integer |           |          |
 datid                     | oid     |           |          |
 datname                   | name    |           |          |
 relid                     | oid     |           |          |
 phase                     | text    |           |          |
 sample_blks_total         | bigint  |           |          |
 sample_blks_scanned       | bigint  |           |          |
 ext_stats_total           | bigint  |           |          |
 ext_stats_computed        | bigint  |           |          |
 child_tables_total        | bigint  |           |          |
 child_tables_done         | bigint  |           |          |
 current_child_table_relid | oid     |           |          |

          View "pg_catalog.pg_stat_progress_basebackup"
        Column        |  Type   | Collation | Nullable | Default
----------------------+---------+-----------+----------+---------
 pid                  | integer |           |          |
 phase                | text    |           |          |
 backup_total         | bigint  |           |          |
 backup_streamed      | bigint  |           |          |
 tablespaces_total    | bigint  |           |          |
 tablespaces_streamed | bigint  |           |          |

           View "pg_catalog.pg_stat_progress_cluster"
       Column        |  Type   | Collation | Nullable | Default
---------------------+---------+-----------+----------+---------
 pid                 | integer |           |          |
 datid               | oid     |           |          |
 datname             | name    |           |          |
 relid               | oid     |           |          |
 command             | text    |           |          |
 phase               | text    |           |          |
 cluster_index_relid | oid     |           |          |
 heap_tuples_scanned | bigint  |           |          |
 heap_tuples_written | bigint  |           |          |
 heap_blks_total     | bigint  |           |          |
 heap_blks_scanned   | bigint  |           |          |
 index_rebuild_count | bigint  |           |          |

        View "pg_catalog.pg_stat_progress_create_index"
       Column       |  Type   | Collation | Nullable | Default
--------------------+---------+-----------+----------+---------
 pid                | integer |           |          |
 datid              | oid     |           |          |
 datname            | name    |           |          |
 relid              | oid     |           |          |
 index_relid        | oid     |           |          |
 command            | text    |           |          |
 phase              | text    |           |          |
 lockers_total      | bigint  |           |          |
 lockers_done       | bigint  |           |          |
 current_locker_pid | bigint  |           |          |
 blocks_total       | bigint  |           |          |
 blocks_done        | bigint  |           |          |
 tuples_total       | bigint  |           |          |
 tuples_done        | bigint  |           |          |
 partitions_total   | bigint  |           |          |
 partitions_done    | bigint  |           |          |

           View "pg_catalog.pg_stat_progress_vacuum"
       Column       |  Type   | Collation | Nullable | Default
--------------------+---------+-----------+----------+---------
 pid                | integer |           |          |
 datid              | oid     |           |          |
 datname            | name    |           |          |
 relid              | oid     |           |          |
 phase              | text    |           |          |
 heap_blks_total    | bigint  |           |          |
 heap_blks_scanned  | bigint  |           |          |
 heap_blks_vacuumed | bigint  |           |          |
 index_vacuum_count | bigint  |           |          |
 max_dead_tuples    | bigint  |           |          |
 num_dead_tuples    | bigint  |           |          |

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM