E.19. lt_proctab

E.19.1. functions

lt_proctab 是一组存储函数,可以访问操作系统的进程表,从而通过数据库查询系统统计信息。

E.19.1. functions

E.19.1.1. pg_proctab

获取关于所有 LightDB 进程的信息。所有进程列表从 pg_stat_activity 中获取, 进程信息从系统文件 /proc 中获取。

lightdb@postgres=# select * from pg_proctab();
-[ RECORD 1 ]---------+-----------------------------------------
pid                   | 64994
comm                  | lightdb
fullcomm              | lightdb: autovacuum launcher 
state                 | S
ppid                  | 64986
pgrp                  | 64994
session               | 64994
tty_nr                | 0
tpgid                 | -1
flags                 | 4202560
minflt                | 529
cminflt               | 0
majflt                | 0
cmajflt               | 0
utime                 | 1
stime                 | 0
cutime                | 0
cstime                | 0
priority              | 20
nice                  | 0
num_threads           | 1
itrealvalue           | 0
starttime             | 3258371
vsize                 | 1902161920
rss                   | 3588
exit_signal           | 17
processor             | 3
rt_priority           | 0
policy                | 0
delayacct_blkio_ticks | 0
uid                   | 1001
username              | lightdb
rchar                 | 66914
wchar                 | 26
syscr                 | 72
syscw                 | 26
reads                 | 0
writes                | 0
cwrites               | 0

E.19.1.2. pg_cputime

/proc/stat 文件获取 CPU 信息。

lightdb@postgres=# select * from pg_cputime();
  user  | nice | system |   idle   | iowait 
--------+------+--------+----------+--------
 289580 |   61 |  29378 | 15540161 |   7253
(1 row)

E.19.1.3. pg_loadavg

/proc/loadavg 文件获取负载信息。

lightdb@postgres=# select * from pg_loadavg();
 load1 | load5 | load15 | last_pid 
-------+-------+--------+----------
  0.08 |  0.05 |   0.05 |    74363
(1 row)

E.19.1.4. pg_loadavg

/proc/meminfo 文件获取内存使用信息。

lightdb@postgres=# select * from pg_memusage();
 memused | memfree | memshared | membuffers | memcached | swapused | swapfree | swapcached 
---------+---------+-----------+------------+-----------+----------+----------+------------
 4441516 | 3552556 |         0 |       2084 |   3770828 |        0 |  4064252 |          0
(1 row)

E.19.1.5. pg_diskusage

/proc/diskstats 文件获取磁盘使用信息。

lightdb@postgres=# select * from pg_diskusage();
-[ RECORD 1 ]----+---------
major            | 8
minor            | 0
devname          | sda
reads_completed  | 36385
reads_merged     | 67
sectors_read     | 2060883
readtime         | 25260
writes_completed | 384347
writes_merged    | 3697
sectors_written  | 16852473
writetime        | 351385
current_io       | 0
iotime           | 326759
totaliotime      | 372183