-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path3.2.html
More file actions
3964 lines (3954 loc) · 232 KB
/
3.2.html
File metadata and controls
3964 lines (3954 loc) · 232 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>日常监控 :: IvorySQL文档中心</title>
<link rel="canonical" href="https://docs.ivorysql.org/ivorysql-doc/master/3.2.html">
<link rel="prev" href="3.1.html">
<link rel="next" href="3.3.html">
<meta name="generator" content="Antora 3.1.7">
<link rel="stylesheet" href="../../_/css/site.css">
<script>var uiRootPath = '../../_'</script>
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://docs.ivorysql.org">IvorySQL文档中心</a>
<div class="navbar-item search hide-for-print">
<div id="search-field" class="field">
<input id="search-input" type="text" placeholder="Search the docs">
</div>
</div>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://www.ivorysql.org/">官方网站</a>
</div>
</div>
</nav>
</header>
<div class="body">
<div class="nav-container" data-component="ivorysql-doc" data-version="master">
<aside class="nav">
<div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="welcome.html">文档中心</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="welcome.html">欢迎</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="1.html">发行说明</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="2.html">关于IvorySQL</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL入门</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="3.1.html">快速开始</a>
</li>
<li class="nav-item is-current-page" data-depth="3">
<a class="nav-link" href="3.2.html">日常监控</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="3.3.html">日常维护</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL高级</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="4.1.html">安装指南</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="4.2.html">集群搭建</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="4.3.html">开发者指南</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="4.4.html">运维管理指南</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="4.5.html">迁移指南</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL生态</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="5.1.html">PostGIS</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="5.2.html">pgvector</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL架构设计</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">查询处理</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.1.1.html">双parser</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">兼容框架</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.2.1.html">initdb过程</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">兼容特性</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.3.1.html">like</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.3.3.html">RowID</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.3.2.html">OUT 参数</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="6.3.4.html">%TYPE、%ROWTYPE</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="6.4.html">国标GB18030</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">Oracle兼容功能列表</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.1.html">1、框架设计</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.2.html">2、GUC框架</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.3.html">3、大小写转换</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.4.html">4、双模式设计</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.5.html">5、兼容Oracle like</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.6.html">6、兼容Oracle匿名块</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.7.html">7、兼容Oracle函数与存储过程</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.8.html">8、内置数据类型与内置函数</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.9.html">9、新增Oracle兼容模式的端口与IP</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.10.html">10、XML函数</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.11.html">11、兼容Oracle sequence</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.12.html">12、包</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.13.html">13、不可见列</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.14.html">14、RowID</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.15.html">15、OUT 参数</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="7.16.html">16、%TYPE、%ROWTYPE</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">IvorySQL贡献指南</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="8.1.html">社区贡献指南</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="8.2.html">asciidoc语法快速参考</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="9.html">工具参考</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="10.html">FAQ</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">PostgreSQL</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="100.html">PG参数参考手册</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="110.html">PG函数参考手册</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">文档中心</span>
<span class="version">master</span>
</div>
<ul class="components">
<li class="component is-current">
<a class="title" href="welcome.html">文档中心</a>
<ul class="versions">
<li class="version is-current is-latest">
<a href="welcome.html">master</a>
</li>
<li class="version">
<a href="../v4.6/v4.6/welcome.html">v4.6</a>
</li>
<li class="version">
<a href="../v4.5/v4.5/welcome.html">v4.5</a>
</li>
<li class="version">
<a href="../v4.4/v4.4/welcome.html">v4.4</a>
</li>
<li class="version">
<a href="../v4.2/v4.2/welcome.html">v4.2</a>
</li>
<li class="version">
<a href="../v4.0/v4.0/welcome.html">v4.0</a>
</li>
<li class="version">
<a href="../v3.4/v3.4/welcome.html">v3.4</a>
</li>
<li class="version">
<a href="../v3.3/v3.3/welcome.html">v3.3</a>
</li>
<li class="version">
<a href="../v3.2/v3.2/welcome.html">v3.2</a>
</li>
<li class="version">
<a href="../v3.1/v3.1/welcome.html">v3.1</a>
</li>
<li class="version">
<a href="../v3.0/v3.0/welcome.html">v3.0</a>
</li>
<li class="version">
<a href="../v2.3/v2.3/welcome.html">v2.3</a>
</li>
<li class="version">
<a href="../v2.2/v2.2/welcome.html">v2.2</a>
</li>
<li class="version">
<a href="../v2.1/v2.1/welcome.html">v2.1</a>
</li>
<li class="version">
<a href="../v1.17/v1.17/welcome.html">v1.17</a>
</li>
<li class="version">
<a href="../v1.8/v1.8/welcome.html">v1.8</a>
</li>
<li class="version">
<a href="../v1.5/v1.5/welcome.html">v1.5</a>
</li>
<li class="version">
<a href="../v1.4/v1.4/welcome.html">v1.4</a>
</li>
<li class="version">
<a href="../v1.3/v1.3/welcome.html">v1.3</a>
</li>
<li class="version">
<a href="../v1.2/v1.2/welcome.html">v1.2</a>
</li>
<li class="version">
<a href="../v1.1/v1.1/welcome.html">v1.1</a>
</li>
<li class="version">
<a href="../v1.0/v1.0/welcome.html">v1.0</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="welcome.html">文档中心</a></li>
<li>IvorySQL</li>
<li>IvorySQL入门</li>
<li><a href="3.2.html">日常监控</a></li>
</ul>
</nav>
<div class="page-versions">
<button class="version-menu-toggle" title="switch to English">CN</button>
<div class="version-menu">
<a class="version is-current" href="">CN</a>
<a class="version" href="../../../../en/ivorysql-doc/master/3.2.html">EN</a>
</div>
</div>
<div class="edit-this-page"><a href="https://github.com/IvorySQL/ivorysql_docs/edit/master/CN/modules/ROOT/pages/master/3.2.adoc">编辑此页面</a></div>
</div>
<div class="content">
<aside class="toc sidebar" data-title="目录" data-levels="2">
<div class="toc-menu"></div>
</aside>
<article class="doc">
<h1 class="page"><strong>日常监控</strong></h1>
<div class="sect1">
<h2 id="监控数据活动"><a class="anchor" href="#监控数据活动"></a>1. 监控数据活动</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="标准unix工具"><a class="anchor" href="#标准unix工具"></a>1.1. 标准Unix工具</h3>
<div class="paragraph">
<p>在大部分 Unix 平台上,IvorySQL会修改由`ps`报告的命令标题,这样个体服务器进程可以被标识。一个显示样例</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-asciidoc hljs" data-lang="asciidoc">$ ps auxww | grep ^postgres
postgres 15551 0.0 0.1 57536 7132 pts/0 S 18:02 0:00 postgres -i
postgres 15554 0.0 0.0 57536 1184 ? Ss 18:02 0:00 postgres: background writer
postgres 15555 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: checkpointer
postgres 15556 0.0 0.0 57536 916 ? Ss 18:02 0:00 postgres: walwriter
postgres 15557 0.0 0.0 58504 2244 ? Ss 18:02 0:00 postgres: autovacuum launcher
postgres 15558 0.0 0.0 17512 1068 ? Ss 18:02 0:00 postgres: stats collector
postgres 15582 0.0 0.0 58772 3080 ? Ss 18:04 0:00 postgres: joe runbug 127.0.0.1 idle
postgres 15606 0.0 0.0 58772 3052 ? Ss 18:07 0:00 postgres: tgl regression [local] SELECT waiting
postgres 15610 0.0 0.0 58772 3056 ? Ss 18:07 0:00 postgres: tgl regression [local] idle in transaction</code></pre>
</div>
</div>
<div class="paragraph">
<p>(`ps`的调用方式随不同的平台而变,但是显示的细节都差不多。这个例子来自于一个最近的 Linux 系统)。列在这里的第一个进程是主服务器进程。为它显示的命令参数是当它被启动时使用的那些。接下来的五个进程是由主进程自动启动的后台工作者进程(如果你已经设置系统为不启动统计收集器,“统计收集器”进程将不会出现;同样“自动清理发动”进程也可以被禁用)。剩余的每一个进程都是一个处理一个客户端连接的服务器进程。每个这种进程都会把它的命令行显示设置为这种形式</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-asciidoc hljs" data-lang="asciidoc">postgres: user database host activity</code></pre>
</div>
</div>
<div class="paragraph">
<p>在该客户端连接的生命期中,用户、数据库以及(客户端)主机项保持不变,但是活动指示器会改变。活动可以是`闲置`(即等待一个客户端命令)、<code>在事务中闲置</code>(在一个`BEGIN`块里等待客户端)或者一个命令类型名,例如`SELECT`。还有,如果服务器进程正在等待一个其它会话持有的锁, `等待中`会被追加到上述信息中。在上面的例子中,我们可以推断:进程 15606 正在等待进程 15610 完成其事务并且因此释放一些锁(进程 15610 必定是阻塞者,因为没有其他活动会话。在更复杂的情况中,可能需要查看pg_locks系统视图来决定谁阻塞了谁)。</p>
</div>
<div class="paragraph">
<p>如果配置了cluster_name,则集簇的名字 也将会显示在`ps`的输出中:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-asciidoc hljs" data-lang="asciidoc">$ psql -c 'SHOW cluster_name'
cluster_name
--------------
server1
(1 row)
$ ps aux|grep server1
postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: server1: background writer
...</code></pre>
</div>
</div>
<div class="paragraph">
<p>如果你已经关闭了update_process_title,那么活动指示器将不会被更新,进程标题仅在新进程被启动的时候设置一次。 在某些平台上这样做可以为每个命令节省可观的开销,但在其它平台上却不明显。</p>
</div>
<div class="sidebarblock">
<div class="content">
<div class="title">提示</div>
<div class="paragraph">
<p>Solaris需要特别的处理。你必需使用`/usr/ucb/ps`而不是`/bin/ps`。 你还必需使用两个`w`标志,而不是一个。另外,你对`postgres`命令的最初调用必须用一个比服务器进程提供的短的`ps`状态显示。如果你没有满足全部三个要求,每个服务器进程的`ps`输出将是原始的`postgres`命令行。 command line。</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="统计收集器"><a class="anchor" href="#统计收集器"></a>1.2. 统计收集器</h3>
<div class="paragraph">
<p>IvorySQL的 <em>统计收集器</em> 是一个支持收集和报告服务器活动信息的子系统。 目前,这个收集器可以对表和索引的访问计数,计数可以按磁盘块和个体行来进行。它还跟踪每个表中的总行数、每个表的清理和分析动作的信息。它也统计调用用户定义函数的次数以及在每次调用中花费的总时间。</p>
</div>
<div class="paragraph">
<p>IvorySQL也支持报告有关系统正在干什么的 动态信息,例如当前正在被其他服务器进程执行的命令以及系统中存在哪些其他连接。 这个功能是独立于收集器进程存在的。</p>
</div>
<div class="sect3">
<h4 id="统计收集配置"><a class="anchor" href="#统计收集配置"></a>1.2.1. 统计收集配置</h4>
<div class="paragraph">
<p>因为统计收集给查询执行增加了一些负荷,系统可以被配置为收集或不收集信息。这由配置参数控制,它们通常在`postgresql.conf`中设置。</p>
</div>
<div class="paragraph">
<p>参数track_activities允许监控当前被任意服务器进程执行的命令。</p>
</div>
<div class="paragraph">
<p>参数track_counts控制是否收集关于表和索引访问的统计信息。</p>
</div>
<div class="paragraph">
<p>参数track_functions启用对用户定义函数使用的跟踪。</p>
</div>
<div class="paragraph">
<p>参数track_io_timing启用对块读写次数的监控。</p>
</div>
<div class="paragraph">
<p>通常这些参数被设置在`postgresql.conf`中,这样它们会应用于所有服务器进程,但是可以在单个会话中使用SET命令打开或关闭它们(为了阻止普通用户对管理员隐藏他们的活动,只有超级用户被允许使用`SET`来改变这些参数)。</p>
</div>
<div class="paragraph">
<p>统计收集器通过临时文件将收集到的信息传送给其他IvorySQL进程。这些文件被存储在名字由stats_temp_directory参数指定的目录中,默认是`pg_stat_tmp`。为了得到更好的性能,`stats_temp_directory`可以被指向一个基于 RAM 的文件系统来降低物理 I/O 需求。当服务器被干净地关闭时,一份统计数据的永久拷贝被存储在`pg_stat`子目录中,这样在服务器重启后统计信息能被保持。当在服务器启动时执行恢复时(例如立即关闭、服务器崩溃以及时间点恢复之后),所有统计计数器会被重置。</p>
</div>
</div>
<div class="sect3">
<h4 id="查看统计信息"><a class="anchor" href="#查看统计信息"></a>1.2.2. 查看统计信息</h4>
<div class="paragraph">
<p>表 1 中列出了一些预定义视图 可以用来显示系统的当前状态。 表 2 中列出了另一些视图可以 显示统计收集的结果。你也可以使用底层统计函数来建立自定义的视图。</p>
</div>
<div class="paragraph">
<p>在使用统计信息监控收集到的数据时,你必须了解这些信息并非是实时更新的。每个独立的服务器进程只在进入闲置状态之前才向收集器传送新的统计计数;因此正在进行的查询或事务并不影响显示出来的总数。同样,收集器本身也最多每`PGSTAT_STAT_INTERVAL`毫秒(缺省为 500ms,除非在编译服务器的时候修改过)发送一 次新的报告。因此显示的信息总是落后于实际活动。但是由`track_activities`收集的当前查询信息总是最新的。</p>
</div>
<div class="paragraph">
<p>另一个重点是当一个服务器进程被要求显示任何这些统计信息时,它首先取得收集器进程最近发出的报告并且接着为所有统计视图和函数使用这个快照,直到它的当前事务的结尾。因此只要你继续当前事务,统计数据将会一直显示静态信息。相似地,当任何关于所有会话的当前查询的信息在一个事务中第一次被请求时,这样的信息将被收集。并且在整个事务期间将显示相同的信息。这是一种特性而非缺陷,因为它允许你在该统计信息上执行多个查询并且关联结果而不用担心那些数字会在你不知情的情况下改变。但是如果你希望用每个查询都看到新结果,要确保在任何事务块之外做那些查询。或者,你可以调用`pg_stat_clear_snapshot`(),那将丢弃当前事务的统计快照(如果有)。下一次对统计性信息的使用将导致获取一个新的快照。</p>
</div>
<div class="paragraph">
<p>一个事务也可以在视图`pg_stat_xact_all_tables`、<code>pg_stat_xact_sys_tables</code>、`pg_stat_xact_user_tables`和`pg_stat_xact_user_functions`中看到它自己的统计信息(还没有被传送给收集器)。这些数字并不像上面所述的那样行动,相反它们在事务期间持续被更新。</p>
</div>
<div class="paragraph">
<p>表 1中显示的动态统计视图中的一些信息是有安全限制的。 普通用户只能看到关于他们自己的会话的所有信息(属于他们是成员的角色的会话)。 在关于其他会话的行中,许多列将为空。 但是,请注意,一个会话的存在和它的一般属性,例如会话用户和数据库,对所有用户都是可见的。 超级用户和内置角色`pg_read_all_stats`的成员可以看到所有会话的所有信息。</p>
</div>
<div class="paragraph">
<p><strong>表1.动态统计视图</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">视图名称</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_activity</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个服务器进程一行,显示与那个进程的当前活动相关的信息,例如状态和当前查询。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_replication</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每一个 WAL 发送进程一行,显示有关到该发送进程连接的后备服务器的复制的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_wal_receiver</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">只有一行,显示来自 WAL 接收器所连接服务器的有关该接收器的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_subscription</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个订阅至少一行,显示有关该订阅的工作者的信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_ssl</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个连接(常规的或者复制)一行,显示在这个连接上使用的SSL的信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_gssapi</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个连接(常规和复制)有一行,显示关于GSSAPI验证和加密的信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_progress_analyze</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个运行`ANALYZE`的后端(包括自动清理工作者进程)的行,显示当前进度。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_progress_create_index</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个后台运行`CREATE INDEX`或`REINDEX`的后端都有一行,显示当前的进度。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_progress_vacuum</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个运行着`VACUUM`的后端(包括autovacuum工作者进程)一行,显示当前的进度。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_progress_cluster</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个运行着`CLUSTER`或`VACUUM FULL`的后端一行,显示当前进度。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_progress_basebackup</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每一个WAL发送者进程的行显示一个基础备份,显示当前进度。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表2.已收集统计信息的视图</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">视图名称</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_archiver</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">只有一行,显示有关 WAL 归档进程活动的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_bgwriter</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">只有一行,显示有关后台写进程的活动的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_database</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个数据库一行,显示数据库范围的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_database_conflicts</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个数据库一行,显示数据库范围的统计信息, 这些信息的内容是关于由于与后备服务器的恢复过程 发生冲突而被取消的查询。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_all_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前数据库中每个表一行,显示有关访问指定表的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_sys_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_all_tables`一样,但只显示系统表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_user_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_all_tables`一样,但只显示用户表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_xact_all_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_all_tables`相似,但计数动作只在当前事务内发生,用于生存和死亡行数量的列以及清理和分析动作在此视图中不出现。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_xact_sys_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_xact_all_tables`一样,但只显示系统表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_xact_user_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_xact_all_tables`一样,但只显示用户表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_all_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前数据库中的每个索引一行,显示:表OID、索引OID、模式名、表名、索引名、 使用了该索引的索引扫描总数、索引扫描返回的索引记录数、使用该索引的简 单索引扫描抓取的活表(livetable)中数据行数。 当前数据库中的每个索引一行,显示与访问指定索引有关的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_sys_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_all_indexes`一样,但只显示系统表上的索引。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_user_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_all_indexes`一样,但只显示用户表上的索引。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_all_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前数据库中每个表一行(包括TOAST表),显示:表OID、模式名、表名、 从该表中读取的磁盘块总数、缓冲区命中次数、该表上所有索引的磁盘块读取总数、 该表上所有索引的缓冲区命中总数、在该表的辅助TOAST表(如果存在)上的磁盘块读取总数、 在该表的辅助TOAST表(如果存在)上的缓冲区命中总数、TOAST表的索引的磁盘块读 取总数、TOAST表的索引的缓冲区命中总数。 当前数据库中的每个表一行,显示有关在指定表上 I/O 的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_sys_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_tables`一样,但只显示系统表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_user_tables</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_tables`一样,但只显示用户表。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_all_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前数据库中每个索引一行,显示:表OID、索引OID、模式名、 表名、索引名、该索引的磁盘块读取总数、该索引的缓冲区命中总数。 当前数据库中的每个索引一行,显示与指定索引上的 I/O 有关的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_sys_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_indexes`一样,但只显示系统表上的索引。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_user_indexes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_indexes`一样,但只显示用户表上的索引。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_all_sequences</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前数据库中每个序列对象一行,显示:序列OID、模式名、序列名、序列的磁盘读取总数、序列的缓冲区命中总数。 当前数据库中的每个序列一行,显示与指定序列上的 I/O 有关的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_sys_sequences</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_sequences`一样,但只显示系统序列(目前没有定义系统序列,因此这个视图总是为空)。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_statio_user_sequences</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_statio_all_sequences`一样,但只显示用户序列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_user_functions</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">对于所有跟踪功能,函数的OID,模式,名称,数量 通话总时间,和自我的时间。自我时间是 在函数本身所花费的时间量,总时间包括 它调用函数所花费的时间。时间值以毫秒为单位。 每一个被跟踪的函数一行,显示与执行该函数有关的统计信息。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_xact_user_functions</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">和`pg_stat_user_functions`相似,但是只统计在当前事务期间的调用</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pg_stat_slru</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">每个SLRU一行, 显示操作的统计信息。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>针对每个索引的统计信息对于判断哪个索引正被使用以及它们的效果特别有用。</p>
</div>
<div class="paragraph">
<p>`pg_statio_`系列视图主要用于判断缓冲区的效果。当实际磁盘读取数远小于缓冲区命中时,这个缓冲能满足大部分读请求而无需进行内核调用。但是,这些统计信息并没有给出所有的事情:由于IvorySQL处理磁盘 I/O 的方式,不在IvorySQL缓冲区中的数据库仍然驻留在内核的 I/O 缓存中,并且因此可以被再次读取而不需要物理磁盘读取。我们建议希望了解IvorySQL I/O 行为更多细节的用户将IvorySQL统计收集器和操作系统中允许观察内核处理 I/O 的工具一起使用。</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="pg_stat_activity"><a class="anchor" href="#pg_stat_activity"></a>1.3. <code>pg_stat_activity</code></h3>
<div class="paragraph">
<p>`pg_stat_activity`视图每个服务器进程将有一行,显示与该进程当前活动相关的信息。</p>
</div>
<div class="paragraph">
<p><strong>表3.<code>pg_stat_activity</code> 视图</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">列</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">类型</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>datid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>oid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端连接到的数据库的OID</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>datname</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端连接到的数据库的名称</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>pid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端的进程 ID</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>leader_pid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">并行组组长的进程ID,如果该进程是并行查询工作者。如果该进程是一个并行组的组长或不参与并行查询,则为`NULL`。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>usesysid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>oid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">登录到这个后端的用户的 OID</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>usename</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">登录到这个后端的用户的 OID</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>application_name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">连接到这个后端的应用的名称</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>client_addr</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>inet</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">连接到这个后端的客户端的 IP 地址。如果这个字段为空,它表示客户端通过服务器机器上的一个 Unix 套接字连接或者这是一个内部进程,如自动清理。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>client_hostname</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">已连接的客户端的主机名,由 <code>client_addr</code> 的反向 DNS 查找报告。 这个字段将只对 IP 连接非空,并且只有log_hostname被启用时才会非空。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>client_port</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>integer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">客户端用于与此后端通信的TCP端口号,如果使用Unix套接字,则为`-1`。如果该字段为空,它表示这是一个内部服务器进程。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>backend_start</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>timestamp with time zone</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个进程被启动的时间。对客户端后端来说,这就是客户端连接到服务器的时间。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>xact_start</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>timestamp with time zone</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个进程的当前事务被启动的时间,如果没有活动事务则为空。 如果当前查询是它的第一个事务,这一列等于 <code>query_start</code> 列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>query_start</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>timestamp with time zone</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前活动查询被开始的时间,如果 <code>state</code> 不是 <code>active</code>,则为上一个查询开始的时间</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>state_change</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>timestamp with time zone</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>state</code> 上一次被改变的时间</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>wait_event_type</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">后端等待的事件类型,如果有的话;否则NULL。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>wait_event</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">如果后端当前正在等待,则等待事件名称,否则为NULL。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>state</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端的当前总体状态。可能的值为:<code>active</code>: 后端正在执行一个查询。<code>idle</code>: 后端正在等待一个新的客户端命令。<code>idle in transaction</code>: 后端在一个事务中,但是当前没有正在执行一个查询。<code>idle in transaction (aborted)</code>: 这个状态与 <code>idle in transaction</code> 相似,除了在该事务中的一个语句导致了一个错误。<code>fastpath function call</code>: 后端正在执行一个 fast-path 函数。<code>disabled</code>: 如果在这个后端中track_activities被禁用,则报告这个状态。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>backend_xid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>xid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端的顶层事务标识符,如果存在。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>backend_xmin</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>xid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前后端的 <code>xmin</code> 范围。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>query</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">这个后端最近查询的文本。如果 <code>state</code> 为 <code>active</code>,这个字段显示当前正在执行的查询。 在所有其他状态下,它显示上一个被执行的查询。默认情况下,查询文本会被截断至1024个字节,这个值可以通过参数track_activity_query_size更改。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>backend_type</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>text</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">当前后端的类型。可能的类型为 <code>autovacuum launcher</code>, <code>autovacuum worker</code>, <code>logical replication launcher</code>, <code>logical replication worker</code>, <code>parallel worker</code>, <code>background writer</code>, <code>client backend</code>, <code>checkpointer</code>, <code>startup</code>, <code>walreceiver</code>, <code>walsender</code> and <code>walwriter</code>. 除此以外,由扩展注册的后台Worker可能有额外的类型。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><code>wait_event`和`state`列是独立的。如果一个后端处于`active`状态,它可能是也可能不是某个事件上的`waiting</code>。如果状态是`active`并且`wait_event`为非空,它意味着一个查询正在被执行,但是它被阻塞在系统中某处。</p>
</div>
<div class="paragraph">
<p><strong>表4.等待事件类型</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待事件类型</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Activity</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程空闲。此事件类型表示在其主处理循环中等待活动的进程。 `wait_event`将识别特定的等待点。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BufferPin</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待对数据缓冲的独占访问。 如果另一个进程持有一个打开的游标,该游标最后一次从相关缓冲区读取数据,则缓冲区销等待可能是漫长的。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Client</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待连接到用户应用程序的套接字上的活动。 因此,服务器预计发生一些独立于其内部进程的事情。`wait_event`将识别特定的等待点。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Extension</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待扩展模块定义的某个条件。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IO</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待一个I/O操作完成。`wait_event`将识别特定的等待点。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IPC</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待与另一个服务器进程进行交互。`wait_event`将识别特定的等待点。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Lock</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待一个重量级锁。重量级锁,也称为锁管理器锁或简单锁,主要保护表等SQL可见对象。 然而,它们也用于确保某些内部操作的互斥,例如关系扩展。`wait_event`将识别等待的锁的类型。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LWLock</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待一个轻量级锁。大多数这样的锁保护共享内存中的特定数据结构。 `wait_event`将包含标识轻量级锁用途的名称。 (有些锁有特定的名称;其他锁是一组锁的一部分,每个锁具有类似的目的。)</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Timeout</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">服务器进程正在等待超时过期。`wait_event`将识别特定的等待点。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表5.`Activity`类型的等待事件</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Activity</code> 等待事件</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ArchiverMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在归档进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>AutoVacuumMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在自动清理启动过程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BgWriterHibernate</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在后台写进程中等待,休眠状态。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BgWriterMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在后台写进程主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CheckpointerMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在校验指针进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LogicalApplyMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在逻辑复制应用进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LogicalLauncherMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在逻辑复制启动器进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PgStatMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在统计收集器进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>RecoveryWalStream</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">流恢复期间,在启动进程主循环等待WAL到达。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>SysLoggerMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在syslogger进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalReceiverMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL接收器进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalSenderMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL发送者进程的主循环中等待。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalWriterMain</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL写入进程的主循环中等待。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表6.`BufferPin`类型的等待事件</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BufferPin</code> 等待事件</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BufferPin</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待获得缓冲区上的独占销。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表7.`Client`类型的等待事件</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Client</code> 等待事件</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ClientRead</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待从客户端读取数据。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ClientWrite</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待写入数据到客户端。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>GSSOpenServer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在建立GSSAPI会话时等待从客户端读取数据。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LibPQWalReceiverConnect</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL接收器等待与远程服务器建立连接。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LibPQWalReceiverReceive</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL接收器中等待从远程服务器接收数据。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>SSLOpenServer</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在尝试连接时等待SSL。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalReceiverWaitStart</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待启动进程发送用于流复制的初始数据。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalSenderWaitForWAL</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL发送器进程中等待WAL被刷新。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WalSenderWriteData</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在WAL发送器进程中处理WAL接收器的回复时,等待任何活动。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表8.`Extension`类型的等待事件</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Extension</code> 等待事件</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Extension</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">在扩展中等待。</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><strong>表9.`IO`类型的等待事件</strong></p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IO</code> 等待事件</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">描述</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BufFileRead</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待从缓冲文件中读取。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>BufFileWrite</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">等待对缓冲文件的写入。</p></td>