# 简目与目录

LLMS 索引： [llms.txt](/llms.txt)

---

<span id="mon-chapter-star-1" class="pdf-anchor"></span><span id="pdf-page-4" class="pdf-anchor"></span>

## 简目 {#overview}

- [前言](/preface/#mon-chapter-star-3) — [7](/preface/#pdf-page-8)
- [关于本书](/about-this-book/#mon-chapter-star-4) — [9](/about-this-book/#pdf-page-10)
- [第 1 章 统计信息概览](/01-statistics-overview/#mon-chapter-1) — [15](/01-statistics-overview/#pdf-page-16)
- [第 2 章 活动统计信息](/02-activity-statistics/#mon-chapter-2) — [27](/02-activity-statistics/#pdf-page-28)
- [第 3 章 查询与函数的执行](/03-queries-and-functions/#mon-chapter-3) — [71](/03-queries-and-functions/#pdf-page-72)
- [第 4 章 数据库](/04-databases/#mon-chapter-4) — [99](/04-databases/#pdf-page-100)
- [第 5 章 共享内存与输入/输出](/05-shared-memory-and-io/#mon-chapter-5) — [129](/05-shared-memory-and-io/#pdf-page-130)
- [第 6 章 预写式日志](/06-write-ahead-log/#mon-chapter-6) — [157](/06-write-ahead-log/#pdf-page-158)
- [第 7 章 复制](/07-replication/#mon-chapter-7) — [173](/07-replication/#pdf-page-174)
- [第 8 章 清理](/08-vacuum/#mon-chapter-8) — [195](/08-vacuum/#pdf-page-196)
- [第 9 章 操作进度](/09-operation-progress/#mon-chapter-9) — [221](/09-operation-progress/#pdf-page-222)
- [附录：测试环境](/test-environment/#mon-appendix-a) — [235](/test-environment/#pdf-page-236)
- [主题索引](/index/#mon-chapter-star-168) — [239](/index/#pdf-page-240)

<span id="mon-chapter-star-2" class="pdf-anchor"></span><span id="pdf-page-5" class="pdf-anchor"></span>

## 目录 {#detailed-contents}

- [前言](/preface/#mon-chapter-star-3) — [7](/preface/#pdf-page-8)
- [关于本书](/about-this-book/#mon-chapter-star-4) — [9](/about-this-book/#pdf-page-10)
- [第 1 章 统计信息概览](/01-statistics-overview/#mon-chapter-1) — [15](/01-statistics-overview/#pdf-page-16)
  - [1.1 “Postgres 是一项服务”](/01-statistics-overview/#mon-section-1-1) — [15](/01-statistics-overview/#pdf-page-16)
  - [1.2 PostgreSQL 的内部结构](/01-statistics-overview/#mon-section-1-2) — [16](/01-statistics-overview/#pdf-page-17)
    - [建立连接与会话运行](/01-statistics-overview/#mon-section-star-15) — [17](/01-statistics-overview/#pdf-page-18)
    - [查询是工作负载的基本单位](/01-statistics-overview/#mon-section-star-16) — [17](/01-statistics-overview/#pdf-page-18)
    - [查询规划与执行](/01-statistics-overview/#mon-section-star-17) — [17](/01-statistics-overview/#pdf-page-18)
    - [查询执行期间的输入/输出](/01-statistics-overview/#mon-section-star-18) — [18](/01-statistics-overview/#pdf-page-19)
    - [预写式日志——Write-Ahead Log](/01-statistics-overview/#mon-section-star-19) — [20](/01-statistics-overview/#pdf-page-21)
    - [数据库管理系统的服务器日志](/01-statistics-overview/#mon-section-star-20) — [21](/01-statistics-overview/#pdf-page-22)
    - [变更复制](/01-statistics-overview/#mon-section-star-21) — [21](/01-statistics-overview/#pdf-page-22)
    - [预写式日志归档](/01-statistics-overview/#mon-section-star-22) — [21](/01-statistics-overview/#pdf-page-22)
    - [后台数据同步](/01-statistics-overview/#mon-section-star-23) — [22](/01-statistics-overview/#pdf-page-23)
    - [自动清理](/01-statistics-overview/#mon-section-star-24) — [22](/01-statistics-overview/#pdf-page-23)
  - [1.3 统计信息接口](/01-statistics-overview/#mon-section-1-3) — [23](/01-statistics-overview/#pdf-page-24)
  - [1.4 统计信息是监控工具的起点](/01-statistics-overview/#mon-section-1-4) — [24](/01-statistics-overview/#pdf-page-25)
  - [1.5 统计信息的特点](/01-statistics-overview/#mon-section-1-5) — [24](/01-statistics-overview/#pdf-page-25)
  - [1.6 测试环境](/01-statistics-overview/#mon-section-1-6) — [25](/01-statistics-overview/#pdf-page-26)
- [第 2 章 活动统计信息](/02-activity-statistics/#mon-chapter-2) — [27](/02-activity-statistics/#pdf-page-28)
  - [2.1 理解数据库管理系统中发生了什么的关键](/02-activity-statistics/#mon-section-2-1) — [27](/02-activity-statistics/#pdf-page-28)
  - [2.2 客户端与服务器的交互](/02-activity-statistics/#mon-section-2-2) — [28](/02-activity-statistics/#pdf-page-29)
  - [2.3 活动信息的来源](/02-activity-statistics/#mon-section-2-3) — [31](/02-activity-statistics/#pdf-page-32)
    - [pg\_stat\_activity 视图](/02-activity-statistics/#mon-section-star-26) — [31](/02-activity-statistics/#pdf-page-32)
    - [pg\_locks 视图](/02-activity-statistics/#mon-section-star-34) — [35](/02-activity-statistics/#pdf-page-36)
    - [pg\_stat\_activity 与 pg\_locks 的特点](/02-activity-statistics/#mon-section-star-37) — [37](/02-activity-statistics/#pdf-page-38)
    - [pg\_stat\_database 视图](/02-activity-statistics/#mon-section-star-38) — [37](/02-activity-statistics/#pdf-page-38)
  - [2.4 已连接的客户端](/02-activity-statistics/#mon-section-2-4) — [39](/02-activity-statistics/#pdf-page-40)
    - [跟踪客户端会话](/02-activity-statistics/#mon-section-star-39) — [41](/02-activity-statistics/#pdf-page-42)
    - [事务活动](/02-activity-statistics/#mon-section-star-44) — [44](/02-activity-statistics/#pdf-page-45)
    - [会话结束状态](/02-activity-statistics/#mon-section-star-46) — [46](/02-activity-statistics/#pdf-page-47)
  - [2.5 会话状态](/02-activity-statistics/#mon-section-2-5) — [49](/02-activity-statistics/#pdf-page-50)
    - [跟踪状态](/02-activity-statistics/#mon-section-star-50) — [50](/02-activity-statistics/#pdf-page-51)
    - [等待与阻塞](/02-activity-statistics/#mon-section-star-51) — [51](/02-activity-statistics/#pdf-page-52)
    - [结合等待跟踪状态](/02-activity-statistics/#mon-section-star-52) — [53](/02-activity-statistics/#pdf-page-54)
    - [死锁](/02-activity-statistics/#mon-section-star-54) — [55](/02-activity-statistics/#pdf-page-56)
    - [空闲事务](/02-activity-statistics/#mon-section-star-55) — [56](/02-activity-statistics/#pdf-page-57)

  - <span id="pdf-page-6" class="pdf-anchor"></span>[2.6 查询与事务的执行时间](/02-activity-statistics/#mon-section-2-6) — [58](/02-activity-statistics/#pdf-page-59)
  - [2.7 跟踪阻塞等待时间](/02-activity-statistics/#mon-section-2-7) — [61](/02-activity-statistics/#pdf-page-62)
    - [使用 pg\_locks.waitstart](/02-activity-statistics/#mon-section-star-57) — [61](/02-activity-statistics/#pdf-page-62)
    - [使用 pg\_stat\_activity.state\_change](/02-activity-statistics/#mon-section-star-59) — [63](/02-activity-statistics/#pdf-page-64)
  - [2.8 阻塞树](/02-activity-statistics/#mon-section-2-8) — [65](/02-activity-statistics/#pdf-page-66)
- [第 3 章 查询与函数的执行](/03-queries-and-functions/#mon-chapter-3) — [71](/03-queries-and-functions/#pdf-page-72)
  - [3.1 为什么需要监控查询](/03-queries-and-functions/#mon-section-3-1) — [71](/03-queries-and-functions/#pdf-page-72)
  - [3.2 pg\_stat\_statements 扩展](/03-queries-and-functions/#mon-section-3-2) — [73](/03-queries-and-functions/#pdf-page-74)
  - [3.3 查询元数据](/03-queries-and-functions/#mon-section-3-3) — [75](/03-queries-and-functions/#pdf-page-76)
  - [3.4 查询规划](/03-queries-and-functions/#mon-section-3-4) — [76](/03-queries-and-functions/#pdf-page-77)
  - [3.5 查询执行](/03-queries-and-functions/#mon-section-3-5) — [79](/03-queries-and-functions/#pdf-page-80)
  - [3.6 使用 queryid 进行跨来源查询识别](/03-queries-and-functions/#mon-section-3-6) — [91](/03-queries-and-functions/#pdf-page-92)
  - [3.7 基于 pg\_stat\_statements 生成报告](/03-queries-and-functions/#mon-section-3-7) — [91](/03-queries-and-functions/#pdf-page-92)
  - [3.8 pg\_stat\_statements\_info 视图](/03-queries-and-functions/#mon-section-3-8) — [94](/03-queries-and-functions/#pdf-page-95)
  - [3.9 过程与函数的执行](/03-queries-and-functions/#mon-section-3-9) — [95](/03-queries-and-functions/#pdf-page-96)
- [第 4 章 数据库](/04-databases/#mon-chapter-4) — [99](/04-databases/#pdf-page-100)
  - [4.1 数据库管理系统对象层级](/04-databases/#mon-section-4-1) — [99](/04-databases/#pdf-page-100)
    - [数据库集簇](/04-databases/#mon-section-star-75) — [100](/04-databases/#pdf-page-101)
    - [表空间](/04-databases/#mon-section-star-76) — [101](/04-databases/#pdf-page-102)
    - [数据库](/04-databases/#mon-section-star-77) — [103](/04-databases/#pdf-page-104)
    - [数据库模式](/04-databases/#mon-section-star-78) — [103](/04-databases/#pdf-page-104)
    - [表与索引](/04-databases/#mon-section-star-79) — [104](/04-databases/#pdf-page-105)
    - [TOAST](/04-databases/#mon-section-star-80) — [106](/04-databases/#pdf-page-107)
  - [4.2 数据库集簇中的事件](/04-databases/#mon-section-4-2) — [106](/04-databases/#pdf-page-107)
    - [表和索引层面的工作负载](/04-databases/#mon-section-star-81) — [107](/04-databases/#pdf-page-108)
    - [错误与不希望发生的事件](/04-databases/#mon-section-star-89) — [114](/04-databases/#pdf-page-115)
  - [4.3 操作数据库管理系统对象的函数](/04-databases/#mon-section-4-3) — [116](/04-databases/#pdf-page-117)
    - [确定数据库管理系统对象的大小](/04-databases/#mon-section-star-91) — [117](/04-databases/#pdf-page-118)
    - [在文件系统中定位对象](/04-databases/#mon-section-star-100) — [123](/04-databases/#pdf-page-124)
- [第 5 章 共享内存与输入/输出](/05-shared-memory-and-io/#mon-chapter-5) — [129](/05-shared-memory-and-io/#pdf-page-130)
  - [5.1 分析共享内存](/05-shared-memory-and-io/#mon-section-5-1) — [130](/05-shared-memory-and-io/#pdf-page-131)
    - [pg\_buffercache 视图](/05-shared-memory-and-io/#mon-section-star-106) — [130](/05-shared-memory-and-io/#pdf-page-131)
    - [pg\_shmem\_allocations 视图](/05-shared-memory-and-io/#mon-section-star-108) — [135](/05-shared-memory-and-io/#pdf-page-136)
  - [5.2 分析后端进程的内存](/05-shared-memory-and-io/#mon-section-5-2) — [136](/05-shared-memory-and-io/#pdf-page-137)
  - [5.3 评估 SLRU 缓存的使用情况](/05-shared-memory-and-io/#mon-section-5-3) — [137](/05-shared-memory-and-io/#pdf-page-138)
  - [5.4 数据库管理系统对象上下文中的输入/输出](/05-shared-memory-and-io/#mon-section-5-4) — [138](/05-shared-memory-and-io/#pdf-page-139)
    - [数据库](/05-shared-memory-and-io/#mon-section-star-109) — [139](/05-shared-memory-and-io/#pdf-page-140)
    - [表、索引与序列](/05-shared-memory-and-io/#mon-section-star-111) — [140](/05-shared-memory-and-io/#pdf-page-141)
  - [5.5 查询执行上下文中的输入/输出](/05-shared-memory-and-io/#mon-section-5-5) — [143](/05-shared-memory-and-io/#pdf-page-144)
  - [5.6 临时文件](/05-shared-memory-and-io/#mon-section-5-6) — [144](/05-shared-memory-and-io/#pdf-page-145)
    - [数据库层面](/05-shared-memory-and-io/#mon-section-star-115) — [145](/05-shared-memory-and-io/#pdf-page-146)

    - <span id="pdf-page-7" class="pdf-anchor"></span>[查询执行期间的输入/输出](/05-shared-memory-and-io/#mon-section-star-117) — [146](/05-shared-memory-and-io/#pdf-page-147)
    - [在服务器日志中跟踪](/05-shared-memory-and-io/#mon-section-star-118) — [147](/05-shared-memory-and-io/#pdf-page-148)
    - [跟踪活动临时文件](/05-shared-memory-and-io/#mon-section-star-119) — [148](/05-shared-memory-and-io/#pdf-page-149)
  - [5.7 后台进程的输入/输出](/05-shared-memory-and-io/#mon-section-5-7) — [149](/05-shared-memory-and-io/#pdf-page-150)
- [第 6 章 预写式日志](/06-write-ahead-log/#mon-chapter-6) — [157](/06-write-ahead-log/#pdf-page-158)
  - [6.1 Write-Ahead Log——预写式日志](/06-write-ahead-log/#mon-section-6-1) — [157](/06-write-ahead-log/#pdf-page-158)
  - [6.2 跟踪日志活动](/06-write-ahead-log/#mon-section-6-2) — [161](/06-write-ahead-log/#pdf-page-162)
    - [pg\_stat\_wal 视图](/06-write-ahead-log/#mon-section-star-128) — [162](/06-write-ahead-log/#pdf-page-163)
    - [pg\_stat\_statements 视图](/06-write-ahead-log/#mon-section-star-133) — [165](/06-write-ahead-log/#pdf-page-166)
  - [6.3 日志归档](/06-write-ahead-log/#mon-section-6-3) — [166](/06-write-ahead-log/#pdf-page-167)
    - [pg\_stat\_archiver 视图](/06-write-ahead-log/#mon-section-star-135) — [167](/06-write-ahead-log/#pdf-page-168)
    - [归档队列](/06-write-ahead-log/#mon-section-star-138) — [169](/06-write-ahead-log/#pdf-page-170)
- [第 7 章 复制](/07-replication/#mon-chapter-7) — [173](/07-replication/#pdf-page-174)
  - [7.1 复制概览](/07-replication/#mon-section-7-1) — [173](/07-replication/#pdf-page-174)
  - [7.2 复制跟踪工具](/07-replication/#mon-section-7-2) — [176](/07-replication/#pdf-page-177)
    - [pg\_stat\_replication 视图](/07-replication/#mon-section-star-141) — [177](/07-replication/#pdf-page-178)
    - [pg\_stat\_wal\_receiver 视图](/07-replication/#mon-section-star-144) — [181](/07-replication/#pdf-page-182)
    - [复制槽与 pg\_replication\_slots](/07-replication/#mon-section-star-145) — [183](/07-replication/#pdf-page-184)
    - [发布与订阅](/07-replication/#mon-section-star-147) — [187](/07-replication/#pdf-page-188)
  - [7.3 恢复冲突](/07-replication/#mon-section-7-3) — [190](/07-replication/#pdf-page-191)
- [第 8 章 清理](/08-vacuum/#mon-chapter-8) — [195](/08-vacuum/#pdf-page-196)
  - [8.1 清理简介](/08-vacuum/#mon-section-8-1) — [195](/08-vacuum/#pdf-page-196)
  - [8.2 清理的实际特点](/08-vacuum/#mon-section-8-2) — [197](/08-vacuum/#pdf-page-198)
    - [自动清理何时执行？](/08-vacuum/#mon-section-star-149) — [197](/08-vacuum/#pdf-page-198)
    - [清理执行统计](/08-vacuum/#mon-section-star-150) — [200](/08-vacuum/#pdf-page-201)
  - [8.3 事务计数器及防止其回卷导致的错误](/08-vacuum/#mon-section-8-3) — [202](/08-vacuum/#pdf-page-203)
  - [8.4 表和索引的膨胀](/08-vacuum/#mon-section-8-4) — [210](/08-vacuum/#pdf-page-211)
  - [8.5 跟踪正在运行的清理进程](/08-vacuum/#mon-section-8-5) — [213](/08-vacuum/#pdf-page-214)
    - [pg\_stat\_activity 视图](/08-vacuum/#mon-section-star-156) — [213](/08-vacuum/#pdf-page-214)
    - [pg\_stat\_progress\_vacuum 视图](/08-vacuum/#mon-section-star-159) — [217](/08-vacuum/#pdf-page-218)
- [第 9 章 操作进度](/09-operation-progress/#mon-chapter-9) — [221](/09-operation-progress/#pdf-page-222)
  - [9.1 pg_stat_progress_analyze 视图](/09-operation-progress/#mon-section-9-1) — [222](/09-operation-progress/#pdf-page-223)
  - [9.2 pg_stat_progress_basebackup 视图](/09-operation-progress/#mon-section-9-2) — [224](/09-operation-progress/#pdf-page-225)
  - [9.3 pg_stat_progress_cluster 视图](/09-operation-progress/#mon-section-9-3) — [226](/09-operation-progress/#pdf-page-227)
  - [9.4 pg_stat_progress_create_index 视图](/09-operation-progress/#mon-section-9-4) — [228](/09-operation-progress/#pdf-page-229)
  - [9.5 pg_stat_progress_copy 视图](/09-operation-progress/#mon-section-9-5) — [231](/09-operation-progress/#pdf-page-232)
- [附录：测试环境](/test-environment/#mon-appendix-a) — [235](/test-environment/#pdf-page-236)
- [主题索引](/index/#mon-chapter-star-168) — [239](/index/#pdf-page-240)
