ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

【参赛作品15】openGauss数据库维护管理

2021-07-07 12:59:20  阅读:192  来源: 互联网

标签:std 01 15 09 student address openGauss 雨花台区 参赛


openGauss数据库维护管理

openGauss数据库维护管理

1 操作系统参数检查

1.1 实验介绍

1.1.1 关于本实验

gs_checkos工具用来帮助检查操作系统、控制参数、磁盘配置等内容,并对系统控制参数、I/O配置、网络配置和THP服务等信息进行配置。

本实验主要是通过gs_checkos工具来检查操作系统参数设置是否合理。先进行场景设置,然后根据检查结果进行参数调整。

1.1.2 实验目的

掌握gs_checkos工具的基本使用;

1.2 场景设置及操作步骤

步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统,登录后信息如下:

Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Mon Jul 20 16:41:11 CST 2020
System load: 0.00
Processes: 113
Memory used: 7.0%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 2
[root@ecs-e1b3 ~]#

步骤 2在ROOT用户下执行gs_checkos先对系统参数进行检查。
[root@ecs-e1b3 ~]# gs_checkos -i A
Checking items:
A1. [ OS version status ] : Normal
A2. [ Kernel version status ] : Normal
A3. [ Unicode status ] : Normal
A4. [ Time zone status ] : Normal
A5. [ Swap memory status ] : Normal
A6. [ System control parameters status ] : Warning
A7. [ File system configuration status ] : Normal
A8. [ Disk configuration status ] : Normal
A9. [ Pre-read block size status ] : Normal
A10.[ IO scheduler status ] : Normal
BondMode Null
A11.[ Network card configuration status ] : Warning
A12.[ Time consistency status ] : Warning
A13.[ Firewall service status ] : Normal
A14.[ THP service status ] : Normal
Total numbers:14. Abnormal numbers:0. Warning numbers:3.
说明事项:
Normal 为正常项,Abnormal为必须处理项,Warning可以不处理。
Total numbers:14. Abnormal numbers:0. Warning numbers:3。
表示:总共检查14项,其中Abnormal必须处理项为0,Warning告警项为3。

步骤 3调整系统参数值。
在参数配置文件(/etc/sysctl.conf)中将参数 vm.min_free_kbytes(表示:内核内存分配保留的内存量) 的值调整为3488。输入“i”进入INSERT模式,进行修改。
[root@ecs-e1b3 ~]# vi /etc/sysctl.conf
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_responses=1
…………
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
vm.min_free_kbytes = 3488
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
参数值修改好后,按” ESC”键退出编辑模式,然后输入” :wq”后回车进行保存。接着通过执行sysctl -p 命令使刚才修改的参数生效,具体如下:
[root@ecs-e1b3 ~]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
……………
net.core.rmem_default = 21299200
net.sctp.sctp_mem = 94500000 915000000 927000000
net.sctp.sctp_rmem = 8192 250000 16777216
net.sctp.sctp_wmem = 8192 250000 16777216
kernel.sem = 250 6400000 1000 25600
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
vm.min_free_kbytes = 3488
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
kernel.shmall = 1152921504606846720
kernel.shmmax = 18446744073709551615

步骤 4再执行gs_checkos 对系统参数进行检查。
[root@ecs-e1b3 ~]# gs_checkos -i A
Checking items:
A1. [ OS version status ] : Normal
A2. [ Kernel version status ] : Normal
A3. [ Unicode status ] : Normal
A4. [ Time zone status ] : Normal
A5. [ Swap memory status ] : Normal
A6. [ System control parameters status ] : Abnormal
A7. [ File system configuration status ] : Normal
A8. [ Disk configuration status ] : Normal
A9. [ Pre-read block size status ] : Normal
A10.[ IO scheduler status ] : Normal
BondMode Null
A11.[ Network card configuration status ] : Warning
A12.[ Time consistency status ] : Warning
A13.[ Firewall service status ] : Normal
A14.[ THP service status ] : Normal
Total numbers:14. Abnormal numbers:1. Warning numbers:2.
Do checking operation finished. Result: Abnormal.
此时A6. [ System control parameters status ] 的状态为Abnormal为必须处理项;
Total numbers:14. Abnormal numbers:1. Warning numbers:2。
表示:总共检查14项,其中Abnormal必须处理项为1,Warning告警项为2。

步骤 5通过执行gs_checkos -i A --detail 查看更详细的信息。
[root@ecs-e1b3 ~]# gs_checkos -i A --detail
Checking items:
A1. [ OS version status ] : Normal
[ecs-e1b3]
openEuler_20.03_64bit
A2. [ Kernel version status ] : Normal
The names about all kernel versions are same. The value is “4.19.90-2003.4.0.0036.oe1.aarch64”.
A3. [ Unicode status ] : Normal
The values of all unicode are same. The value is “LANG=en_US.UTF-8”.
A4. [ Time zone status ] : Normal
The informations about all timezones are same. The value is “+0800”.
A5. [ Swap memory status ] : Normal
The value about swap memory is correct.
A6. [ System control parameters status ] : Abnormal
[ecs-e1b3]
Abnormal reason: variable ‘vm.min_free_kbytes’ RealValue ‘3488’ ExpectedValue ‘348844’.
Warning reason: variable ‘net.ipv4.tcp_retries1’ RealValue ‘3’ ExpectedValue ‘5’.
Warning reason: variable ‘net.ipv4.tcp_syn_retries’ RealValue ‘6’ ExpectedValue ‘5’.
Warning reason: variable ‘net.sctp.path_max_retrans’ RealValue ‘5’ ExpectedValue ‘10’.
Warning reason: variable ‘net.sctp.max_init_retransmits’ RealValue ‘8’ ExpectedValue ‘10’.
Check_SysCtl_Parameter failed.
A7. [ File system configuration status ] : Normal
Both soft nofile and hard nofile are correct.
A8. [ Disk configuration status ] : Normal
The value about XFS mount parameters is correct.
A9. [ Pre-read block size status ] : Normal
The value about Logical block size is correct.
A10.[ IO scheduler status ] : Normal
The value of IO scheduler is correct.
BondMode Null
A11.[ Network card configuration status ] : Warning
[ecs-e1b3]
BondMode Null
Warning reason: Failed to obtain the network card speed value. Maybe the network card “eth0” is not working.
A12.[ Time consistency status ] : Warning
[ecs-e1b3]
The NTPD not detected on machine and local time is “2020-07-20 17:16:41”.
A13.[ Firewall service status ] : Normal
The firewall service is stopped.
A14.[ THP service status ] : Normal
The THP service is stopped.
Total numbers:14. Abnormal numbers:1. Warning numbers:2.
Do checking operation finished. Result: Abnormal.
在详细信息中,可以明确看出那些参数设置有问题,并给出了问题参数要求修改的参考值,如下:
A6. [ System control parameters status ] : Abnormal
[ecs-e1b3]
Abnormal reason: variable ‘vm.min_free_kbytes’ RealValue ‘3488’ ExpectedValue ‘348844’.
Warning reason: variable ‘net.ipv4.tcp_retries1’ RealValue ‘3’ ExpectedValue ‘5’.
Warning reason: variable ‘net.ipv4.tcp_syn_retries’ RealValue ‘6’ ExpectedValue ‘5’.
Warning reason: variable ‘net.sctp.path_max_retrans’ RealValue ‘5’ ExpectedValue ‘10’.
Warning reason: variable ‘net.sctp.max_init_retransmits’ RealValue ‘8’ ExpectedValue ‘10’.
Check_SysCtl_Parameter failed.

步骤 6按详细信息中的修改说明对系统参数进行修改。
vm.min_free_kbytes的值由3488调整为348844
net.ipv4.tcp_retries1的值由3调整为5.
net.ipv4.tcp_syn_retries的值由6调整为5.
net.sctp.path_max_retrans的值由5调整为10
net.sctp.max_init_retransmits的值由8调整为10
具体设置如下:
vm.min_free_kbytes = 348844
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10
在系统参数文件中进行修改(输入“i”进入INSERT模式,进行修改。):
[root@ecs-e1b3 ~]# vi /etc/sysctl.conf

sysctl settings are defined through files in

/usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.

Vendors settings live in /usr/lib/sysctl.d/.

To override a whole file, create a new file with the same in

/etc/sysctl.d/ and put new settings there. To override

only specific settings, add a file with a lexically later

name in /etc/sysctl.d/ and put new settings there.

For more information, see sysctl.conf(5) and sysctl.d(5).

kernel.sysrq=0
net.ipv4.ip_forward=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0

/etc/sysctl.d/ and put new settings there. To override

only specific settings, add a file with a lexically later

name in /etc/sysctl.d/ and put new settings there.

For more information, see sysctl.conf(5) and sysctl.d(5).

kernel.sysrq=0
net.ipv4.ip_forward=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.accept_source_route=0

/etc/sysctl.d/ and put new settings there. To override

only specific settings, add a file with a lexically later

name in /etc/sysctl.d/ and put new settings there.

For more information, see sysctl.conf(5) and sysctl.d(5).

kernel.sysrq=0
net.ipv4.ip_forward=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
……………
net.sctp.sctp_rmem = 8192 250000 16777216
net.sctp.sctp_wmem = 8192 250000 16777216
kernel.sem = 250 6400000 1000 25600
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
vm.min_free_kbytes = 348844
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
kernel.shmall = 1152921504606846720
kernel.shmmax = 18446744073709551615
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10
参数值修改好后,按”ECS”键退出编辑模式,然后输入”:wq”后回车进行保存。接着通过执行sysctl -p 命令使刚才修改的参数生效,具体如下:
[root@ecs-e1b3 ~]# sysctl -p
kernel.sysrq = 0
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
vm.swappiness = 0
net.ipv4.tcp_max_tw_buckets = 10000
net.ipv4.tcp_tw_reuse = 1
…………….
net.ipv4.tcp_rmem = 8192 250000 16777216
net.ipv4.tcp_wmem = 8192 250000 16777216
vm.min_free_kbytes = 348844
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.core.somaxconn = 65535
kernel.shmall = 1152921504606846720
kernel.shmmax = 18446744073709551615
net.ipv4.tcp_retries1 = 5
net.ipv4.tcp_syn_retries = 5
net.sctp.path_max_retrans = 10
net.sctp.max_init_retransmits = 10

步骤 7再次通过执行gs_checkos -i A 查看系统参数检查是否能通过。
[root@ecs-e1b3 ~]# gs_checkos -i A
Checking items:
A1. [ OS version status ] : Normal
A2. [ Kernel version status ] : Normal
A3. [ Unicode status ] : Normal
A4. [ Time zone status ] : Normal
A5. [ Swap memory status ] : Normal
A6. [ System control parameters status ] : Normal
A7. [ File system configuration status ] : Normal
A8. [ Disk configuration status ] : Normal
A9. [ Pre-read block size status ] : Normal
A10.[ IO scheduler status ] : Normal
BondMode Null
A11.[ Network card configuration status ] : Warning
A12.[ Time consistency status ] : Warning
A13.[ Firewall service status ] : Normal
A14.[ THP service status ] : Normal
Total numbers:14. Abnormal numbers:0. Warning numbers:2.
从检查结果可以看出,系统参数检查已经通过。其中A6. [ System control parameters status ]的状态由原来的Abnormal变为了Normal。
操作系统参数检查实验结束。

2 openGauss运行健康状态检查
2.1 实验介绍
2.1.1 关于本实验
gs_check能够帮助用户在openGauss运行过程中,全量的检查openGauss运行环境,操作系统环境,网络环境及数据库执行环境,也有助于在openGauss重大操作之前对各类环境进行全面检查,有效保证操作执行成功。
本实验主要是通过gs_check工具来检查openGauss数据库运行状态。先进行场景设置,然后根据检查结果进行数据库调整。
语法如下:
单项检查:
gs_check -i ITEM […] [-U USER] [-L] [-l LOGFILE] [-o OUTPUTDIR] [–skip-root-items][–set][–routing]
场景检查:
gs_check -e SCENE_NAME [-U USER] [-L] [-l LOGFILE] [-o OUTPUTDIR] [–hosts] [–skip-root-items] [–time-out=SECS][–set][–routing][–skip-items]
场景检查项。默认的场景有inspect(例行巡检)、upgrade(升级前巡检)、binary_upgrade(就地升级前巡检)、health(健康检查巡检)、install(安装),等,用户可以根据需求自己编写场景。
显示帮助信息。
gs_check -? | --help
2.1.2 实验目的
掌握gs_check工具的基本使用;

2.2 场景设置及操作步骤
步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统然后用 su – omm命令切换至OMM用户环境,登录后信息如下。
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:11 CST 2020
System load: 0.01
Processes: 109
Memory used: 6.7%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[root@ecs-e1b3 ~]# su - omm
Last login: Fri Jul 10 19:05:39 CST 2020 on pts/0
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:25 CST 2020
System load: 0.01
Processes: 111
Memory used: 7.0%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[omm@ecs-e1b3 ~]$

步骤 2确认openGauss数据库服务是否启动。
[omm@ecs-e1b3 ~]$ gs_om -t status;

cluster_state : Normal
redistributing : No

cluster_state : Normal 表示已启动,可以正常使用。如果状态为非Normal表示不可用
为了实验场景设置,如果数据库服务已经启动,请执行步骤3先关闭服务。

步骤 3关闭openGauss数据库服务。
[omm@ecs-e1b3 ~]$ gs_om -t stop;
Stopping cluster.

Successfully stopped cluster.

End stop cluster.

步骤 4检查openGauss实例连接。
[omm@ecs-e1b3 ~]$ gs_check -i CheckDBConnection
Parsing the check items config file successfully
Distribute the context file to remote hosts successfully
Start to health check for the cluster. Total Items:1 Nodes:1

Checking… [=========================] 1/1
Start to analysis the check result
CheckDBConnection…NG
The item run on 1 nodes. ng: 1
The ng[ecs-e1b3] value:
The database can not be connected.

Analysis the check result successfully
Failed. All check items run completed. Total:1 NG:1
For more information please refer to /opt/huawei/wisequery/script/gspylib/inspection/output/CheckReport_2020072139449163171.tar.gz
说明:
CheckDBConnection…NG 表示连接检查项无用;
The database can not be connected. 表示实例不能连接;
Failed. All check items run completed. Total:1 NG:1 表示共检查1项并且检查结果未通过。

步骤 5启动openGauss数据库服务。
[omm@ecs-e1b3 ~]$ gs_om -t start;
Starting cluster.

=========================================
Successfully started.
[omm@ecs-e1b3 ~]$

步骤 6确认openGauss数据库服务已启动。
[omm@ecs-e1b3 ~]$ gs_om -t status;

cluster_state : Normal
redistributing : No

[omm@ecs-e1b3 ~]$

步骤 7再次检查openGauss实例连接。
[omm@ecs-e1b3 ~]$ gs_check -i CheckDBConnection
Parsing the check items config file successfully
Distribute the context file to remote hosts successfully
Start to health check for the cluster. Total Items:1 Nodes:1

Checking… [=========================] 1/1
Start to analysis the check result
CheckDBConnection…OK
The item run on 1 nodes. success: 1

Analysis the check result successfully
Success. All check items run completed. Total:1 Success:1
For more information please refer to /opt/huawei/wisequery/script/gspylib/inspection/output/CheckReport_2020072140672174672.tar.gz

说明:
CheckDBConnection…OK 表示连接检查项正常;
Success. All check items run completed. Total:1 Success:1 表示共检查1项并且检查结果成功。
openGauss数据库运行健康状态检查实验结束。

3 数据库性能检查
3.1 实验介绍
3.1.1 关于本实验
openGauss 不仅提供了gs_checkperf工具来帮助用户了解openGauss的负载情况。
本实验主要是通过gs_checkperf工具来检查openGauss数据库性能以及通过EXPLAIN来进行SQL语句优化。
3.1.2 实验目的
掌握gs_checkperf工具的基本使用;
3.2 通过gs_checkperf工具来检查数据库性能
说明:
gs_checkperf可以对以下级别进行检查:
openGauss级别(主机CPU占用率、Gauss CPU占用率、I/O使用情况等)、
节点级别(CPU使用情况、内存使用情况、I/O使用情况)、
会话/进程级别(CPU使用情况、内存使用情况、I/O使用情况)、
SSD性能(写入、读取性能)
其中检查SSD性能要用root用户执行,检查openGauss性能要用openGauss安装用户执行
本实验为检查openGauss性能。

步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统然后用 su – omm命令切换至OMM用户环境,登录后信息如下。
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:11 CST 2020
System load: 0.01
Processes: 109
Memory used: 6.7%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[root@ecs-e1b3 ~]# su - omm
Last login: Fri Jul 10 19:05:39 CST 2020 on pts/0
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:25 CST 2020
System load: 0.01
Processes: 111
Memory used: 7.0%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[omm@ecs-e1b3 ~]$

ommecse1b3__gs_om_t_start
Starting_cluster_445">步骤 2先启动数据库服务,再用gs_checkperf检查下,再使用gsql客户端以管理员用户身份连接postgres数据库,假设端口号为26000。

先启动数据库服务。

[omm@ecs-e1b3 ~]$ gs_om -t start;

Starting cluster.

=========================================
Successfully started.
用gs_checkperf检查下。
[omm@ecs-e1b3 ~]$ gs_checkperf
Cluster statistics information:
Host CPU busy time ratio : .72 %
MPPDB CPU time % in busy time : .33 %
Shared Buffer Hit ratio : 97.33 %
In-memory sort ratio : 0
Physical Reads : 466
Physical Writes : 175
DB size : 47 MB
Total Physical writes : 175
Active SQL count : 3
Session count : 4
确认openGauss数据库服务是否正常。
[omm@ecs-e1b3 ~]$ gs_om -t status;

cluster_state : Unavailable
redistributing : No

ommecse1b3__gs_om_t_start
Starting_cluster_471">cluster_state : Normal 表示已启动,可以正常使用。如果状态为Unavailable表示不可用

为了实验继续进行,请先启动数据库服务。

启动数据库服务(如果数据库服务是正常的,此步骤可以不执行)。

[omm@ecs-e1b3 ~]$ gs_om -t start;

Starting cluster.

=========================================
Successfully started.
然后连接postgres数据库。
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:57:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.
postgres=#

步骤 3对PMK模式下的表进行统计信息收集。
postgres=# analyze pmk.pmk_configuration;
ANALYZE
postgres=# analyze pmk.pmk_meta_data;
ANALYZE
postgres=# analyze pmk.pmk_snapshot;
ANALYZE
postgres=# analyze pmk.pmk_snapshot_datanode_stat;
ANALYZE
postgres=#
说明:
gs_checkperf工具的监控信息依赖于pmk模式下的表的数据,如果pmk模式下的表未执行analyze操作,则可能导致gs_checkperf工具执行失败。

步骤 4执行简要性能检查。
用 \q 先退出postgres数据库,然后在操作系统用户 omm 环境下去执行gs_checkperf检查工具,具体如下:
postgres=#
postgres=# \q
[omm@ecs-e1b3 ~]$ gs_checkperf
Cluster statistics information:
Host CPU busy time ratio : 1.66 % -----主机CPU占用率
MPPDB CPU time % in busy time : 2.51 % ----Gauss CPU占用率
Shared Buffer Hit ratio : 99.14 % ----共享内存命中率
In-memory sort ratio : 0 —内存中排序比率
Physical Reads : 504 —物理读次数
Physical Writes : 162 —物理写次数
DB size : 57 MB —DB大小
Total Physical writes : 162 —总物理写次数
Active SQL count : 4 —当前SQL执行数
Session count : 5 —Session数量

步骤 5执行详细性能检查。
[omm@ecs-e1b3 ~]$ gs_checkperf --detail
Cluster statistics information:
Host CPU usage rate:
Host total CPU time : 45719980.000 Jiffies
Host CPU busy time : 761060.000 Jiffies
Host CPU iowait time : 6640.000 Jiffies
Host CPU busy time ratio : 1.66 %
Host CPU iowait time ratio : .01 %
MPPDB CPU usage rate:
MPPDB CPU time % in busy time : 5.12 %
MPPDB CPU time % in total time : .09 %
Shared buffer hit rate:
Shared Buffer Reads : 1057
Shared Buffer Hits : 139798
Shared Buffer Hit ratio : 99.25 %
In memory sort rate:
In-memory sort count : 0
In-disk sort count : 0
In-memory sort ratio : 0
I/O usage:
Number of files : 106
Physical Reads : 584
Physical Writes : 362
Read Time : 5794 ms
Write Time : 4046 ms
Disk usage:
DB size : 57 MB
Total Physical writes : 362
Average Physical write : 89471.08
Maximum Physical write : 362
Activity statistics:
Active SQL count : 4
Session count : 5
Node statistics information:
dn_6001:
MPPDB CPU Time : 38960 Jiffies
Host CPU Busy Time : 761060 Jiffies
Host CPU Total Time : 45719980 Jiffies
MPPDB CPU Time % in Busy Time : 5.12 %
MPPDB CPU Time % in Total Time : .09 %
Physical memory : 7144341504 Bytes
DB Memory usage : 14922285056 Bytes
Shared buffer size : 1073741824 Bytes
Shared buffer hit ratio : 99.25 %
Sorts in memory : 0
Sorts in disk : 0
In-memory sort ratio : 0
Number of files : 106
Physical Reads : 584
Physical Writes : 362
Read Time : 5794
Write Time : 4046
Session statistics information(Top 10):
Session CPU statistics:
1 dn_6001-postgres-omm:
Session CPU time : 2
Database CPU time : 39020
Session CPU time % : .01 %
……………
Session Memory statistics:
1 dn_6001-postgres-omm:
Buffer Reads : 1309
Shared Buffer Hit ratio : 93.03
In Memory sorts : 0
In Disk sorts : 0
In Memory sorts ratio : 0
Total Memory Size : 7433136
Used Memory Size : 6443268
…………………
Session IO statistics:
1 dn_6001-postgres-omm:
Physical Reads : 98
Read Time : 1069
2 dn_6001-postgres-omm:
Physical Reads : 13
Read Time : 173
…………
[omm@ecs-e1b3 ~]$
gs_checkperf 检查实验结束。
3.3 通过EXPLAIN进行SQL语句优化
说明:
使用explain能显示SQL语句的执行计划;
执行计划将显示SQL语句所引用的表会采用什么样的扫描方式,如:简单的顺序扫描、索引扫描等。如果引用了多个表,执行计划还会显示用到的JOIN算法;
执行计划的最关键的部分是语句的预计执行开销,这是计划生成器估算执行该语句将花费多长的时间;
若指定了ANALYZE选项,则该语句模拟执行并形成最优的执行计划(并非真正执行),然后根据实际的运行结果显示统计数据,包括每个计划节点内时间总开销(毫秒为单位)和实际返回的总行数。这对于判断计划生成器的估计是否接近现实非常有用。

步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统然后用 su – omm命令切换至OMM用户环境,登录后信息如下。
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:11 CST 2020
System load: 0.01
Processes: 109
Memory used: 6.7%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[root@ecs-e1b3 ~]# su - omm
Last login: Fri Jul 10 19:05:39 CST 2020 on pts/0
Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64
System information as of time: Tue Jul 21 09:21:25 CST 2020
System load: 0.01
Processes: 111
Memory used: 7.0%
Swap used: 0.0%
Usage On: 15%
IP address: 192.168.0.96
Users online: 1
[omm@ecs-e1b3 ~]$

ommecse1b3__gs_om_t_start
Starting_cluster_626">步骤 2先启动数据库服务,然后使用gsql客户端以管理员用户身份连接postgres数据库,假设端口号为26000。

启动数据库服务。

[omm@ecs-e1b3 ~]$ gs_om -t start;

Starting cluster.

=========================================
Successfully started.
然后连接postgres数据库。
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:56:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

postgres=#

步骤 3创建student表。
postgres=# CREATE TABLE student
( std_id INT NOT NULL,
std_name VARCHAR(20) NOT NULL,
std_sex VARCHAR(6),
std_birth DATE,
std_in DATE NOT NULL,
std_address VARCHAR(100)
);

CREATE TABLE

步骤 4表数据插入。
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (1,‘张一’,‘男’,‘1993-01-01’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (2,‘张二’,‘男’,‘1993-01-02’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (3,‘张三’,‘男’,‘1993-01-03’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (4,‘张四’,‘男’,‘1993-01-04’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (5,‘张五’,‘男’,‘1993-01-05’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (6,‘张六’,‘男’,‘1993-01-06’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (7,‘张七’,‘男’,‘1993-01-07’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (8,‘张八’,‘男’,‘1993-01-08’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (9,‘张九’,‘男’,‘1993-01-09’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (10,‘李一’,‘男’,‘1993-01-10’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (11,‘李二’,‘男’,‘1993-01-11’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (12,‘李三’,‘男’,‘1993-01-12’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (13,‘李四’,‘男’,‘1993-01-13’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (14,‘李五’,‘男’,‘1993-01-14’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (15,‘李六’,‘男’,‘1993-01-15’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (16,‘李七’,‘男’,‘1993-01-16’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (17,‘李八’,‘男’,‘1993-01-17’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (18,‘李九’,‘男’,‘1993-01-18’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (19,‘王一’,‘男’,‘1993-01-19’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (20,‘王二’,‘男’,‘1993-01-20’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (21,‘王三’,‘男’,‘1993-01-21’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (22,‘王四’,‘男’,‘1993-01-22’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (23,‘王五’,‘男’,‘1993-01-23’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (24,‘王六’,‘男’,‘1993-01-24’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (25,‘王七’,‘男’,‘1993-01-25’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (26,‘王八’,‘男’,‘1993-01-26’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (27,‘王九’,‘男’,‘1993-01-27’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (28,‘钱一’,‘男’,‘1993-01-28’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (29,‘钱二’,‘男’,‘1993-01-29’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (30,‘钱三’,‘男’,‘1993-01-30’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (31,‘钱四’,‘男’,‘1993-02-01’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (32,‘钱五’,‘男’,‘1993-02-02’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (33,‘钱六’,‘男’,‘1993-02-03’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (34,‘钱七’,‘男’,‘1993-02-04’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (35,‘钱八’,‘男’,‘1993-02-05’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (36,‘钱九’,‘男’,‘1993-02-06’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (37,‘吴一’,‘男’,‘1993-02-07’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (38,‘吴二’,‘男’,‘1993-02-08’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (39,‘吴三’,‘男’,‘1993-02-09’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (40,‘吴四’,‘男’,‘1993-02-10’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (41,‘吴五’,‘男’,‘1993-02-11’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (42,‘吴六’,‘男’,‘1993-02-12’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (43,‘吴七’,‘男’,‘1993-02-13’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (44,‘吴八’,‘男’,‘1993-02-14’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (45,‘吴九’,‘男’,‘1993-02-15’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (46,‘柳一’,‘男’,‘1993-02-16’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (47,‘柳二’,‘男’,‘1993-02-17’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (48,‘柳三’,‘男’,‘1993-02-18’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (49,‘柳四’,‘男’,‘1993-02-19’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (50,‘柳五’,‘男’,‘1993-02-20’,‘2011-09-01’,‘江苏省南京市雨花台区’);

步骤 5数据查询统计。。
postgres=# select count(*) from student;
count

50

(1 row)

postgres=# select * from student order by std_id;
std_id | std_name | std_sex | std_birth | std_in | std_address
--------±---------±--------±--------------------±--------------------±---------------------
1 | 张一 | 男 | 1993-01-01 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
2 | 张二 | 男 | 1993-01-02 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
3 | 张三 | 男 | 1993-01-03 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
4 | 张四 | 男 | 1993-01-04 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
………………

步骤 6查看表信息。
postgres=# \d student
Table “public.student”
Column | Type | Modifiers
-------------±-------------------------------±----------
std_id | integer | not null
std_name | character varying(20) | not null
std_sex | character varying(6) |
std_birth | timestamp(0) without time zone |
std_in | timestamp(0) without time zone | not null
std_address | character varying(100) |

步骤 7收集表的统计信息。
postgres=# ANALYZE VERBOSE student;
INFO: analyzing “public.student”(dn_6001 pid=48036)
INFO: ANALYZE INFO : “student”: scanned 1 of 1 pages, containing 50 live rows and 0 dead rows; 50 rows in sample, 50 estimated total rows(dn_6001 pid=48036)
ANALYZE
使用ANALYZE VERBOSE语句更新统计信息,会同时输出表的相关信息。
步骤 8查看语句的执行计划。
postgres=# explain select * from student where std_id=30;
QUERY PLAN

Seq Scan on student (cost=0.00…1.62 rows=1 width=62)
Filter: (std_id = 30)
(2 rows)
Seq Scan on student 表示使用的是全表扫描。

步骤 9给表添加主键。
postgres=# alter table student add primary key (std_id);
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index “student_pkey” for table “student”
ALTER TABLE

postgres_d_student
__________________Table_publicstudent
__Column__________________Type_______________Modifiers

std_id_______integer_________________________not_null
std_name_____character_varying20___________not_null
std_sex______character_varying6
_________
std_birth____timestamp0_without_time_zone_
std_in_______timestamp0_without_time_zone__not_null
std_address__character_varying100
________
Indexes
___student_pkey_PRIMARY_KEY_btree_std_id_TABLESPACE_pg_default
student_pkey

_11hint
hint
postgres_explain_select_indexscanstudent_student_pkey__from_student_where_std_id30
_________________________________QUERY_PLAN_753">步骤 10再次查看表信息。

确定主键是否建好。

postgres=# \d student

Table “public.student”

Column | Type | Modifiers

-------------±-------------------------------±----------

std_id | integer | not null

std_name | character varying(20) | not null

std_sex | character varying(6) |

std_birth | timestamp(0) without time zone |

std_in | timestamp(0) without time zone | not null

std_address | character varying(100) |

Indexes:

“student_pkey” PRIMARY KEY, btree (std_id) TABLESPACE pg_default

student_pkey 为主键名称。

步骤 11通过hint来优化语句扫描方式。

通过加hint来使查询语句进行索引扫描。

postgres=# explain select /+indexscan(student student_pkey)/ * from student where std_id=30;

QUERY PLAN

[Bypass]
Index Scan using student_pkey on student (cost=0.00…8.27 rows=1 width=62)
Index Cond: (std_id = 30)
(3 rows)

postgres=#
Index Scan using student_pkey on student 表示语句通过student表上的主键索引student_pkey进行了索引扫描。
步骤 12退出数据库
postgres=# \q
EXPLAIN进行SQL优化实验结束。

4 日志检查
4.1 实验介绍
4.1.1 关于本实验
数据库运行时,某些操作在执行过程中可能会出现错误,数据库依然能够运行。但是此时数据库中的数据可能已经发生不一致的情况。建议检查openGauss运行日志,及时发现隐患。
当openGauss发生故障时,使用 gs_collector 此工具收集OS信息、日志信息以及配置文件等信息,来定位问题。
本实验主要是先手工设置收集配置信息,然后通过gs_collector工具调整用配置来收集相关日志信息。
4.1.2 实验目的
掌握gs_collector工具的基本使用;
4.2 通过gs_collector工具来收集日志信息
步骤 1设置收集配置文件。
[omm@ecs-e1b3 ~]$ pwd
/home/omm
[omm@ecs-e1b3 ~]$ vi collector.json
在用vi collector.json创建配置文件后,输入”i”进入INSERT模式,并将以下文本内容添加至配置文件中,具体如下:
{
“Collect”:
[
{“TypeName”: “System”, “Content”:“RunTimeInfo, HardWareInfo”,“Interval”:“0”, “Count”:“1”},
{“TypeName”: “Log”, “Content” : “Coordinator,DataNode,Gtm,ClusterManager”, “Interval”:“0”, “Count”:“1”},
{“TypeName”: “Database”, “Content”: “pg_locks,pg_stat_activity,pg_thread_wait_status”,“Interval”:“0”, “Count”:“1”},
{“TypeName”: “Config”, “Content”: “Coordinator,DataNode,Gtm”, “Interval”:“0”, “Count”:“1”}
]
}
内容添加好后,按下“Esc”键,然后输入“:wq”进行保存文件退出。
配置文件中
利用TypeName指定需要收集的信息类型;
利用Content指定每一类信息的具体内容;
利用Count指定此类信息收集的次数;
利用Interval指定收集间隔,单位为秒;
TypeName和Content不允许缺失或者内容为空;
Interval和Count可以不指定,如果没有指定Count,则默认收集一次;
如果没有指定Interval则表示间隔为0秒,Interval和Count的值不能小于0;
如果不指定则使用默认的配置文件;
可以根据gs_collector内容收集对照表进行个性化定制配置;
配置文件格式采用json格式。

步骤 2确定数据库服务是否启动。
[omm@ecs-e1b3 ~]$ gs_om -t status;

cluster_state : Unavailable
redistributing : No

ommecse1b3__gs_om_t_start
Starting_cluster_826">cluster_state : Normal 表示已启动,可以正常使用。如果状态为Unavailable表示不可用

为了实验继续进行,请先启动数据库服务。

启动数据库服务(如果数据库服务是正常状态,此步骤可以不执行)。

[omm@ecs-e1b3 ~]$ gs_om -t start;

Starting cluster.

=========================================
Successfully started.
步骤 3收集OS信息及日志信息。
begin-time、end-time的值根据自己实际想收集的时间来设置。
[omm@ecs-e1b3 ~]$ gs_collector --begin-time=“20200720 23:00” --end-time=“20200729 20:00” -C /home/omm/collector.json
Successfully parsed the configuration file.
create Dir.
Successfully create dir.
do system check interval 0 : count 1
Collecting OS information.
Failed to collect OS information.
do database check interval 0 : count 1
Collecting catalog statistics.
Successfully collected catalog statistics.
do log check interval 0 : count 1
Collecting Log files.
Successfully collected Log files.
do Config check 0:1
Collecting Config files.
Successfully collected Config files.
Collecting files.
Successfully collected files.
All results are stored in /opt/huawei/wisequery/omm_mppdb/collector_20200727_094932.tar.gz.
收集完后,所有的结果存放在/opt/huawei/wisequery/omm_mppdb/collector_20200727_094932.tar.gz包中,请注意自己生成的文件包名称,因为每次的文件包名不一样。
步骤 4查看日志信息。
先进入日志包所在的目录,然后将日志包进行解压。
[omm@ecs-e1b3 omm_mppdb]$ cd /opt/huawei/wisequery/omm_mppdb/
[omm@ecs-e1b3 omm_mppdb]$ ll
total 48K
-rw------- 1 omm dbgrp 46K Jul 27 09:49 collector_20200727_094932.tar.gz
[omm@ecs-e1b3 omm_mppdb]$ tar -zxvf collector_20200727_094932.tar.gz
collector_20200727_094932/
collector_20200727_094932/ecs-e1b3.tar.gz
collector_20200727_094932/Summary.log
collector_20200727_094932/Detail.log
接下来,进入解压后的文件夹collector_20200727_094932,并对ecs-e1b3.tar.gz包进一步解压。
[omm@ecs-e1b3 omm_mppdb]$ cd collector_20200727_094932
[omm@ecs-e1b3 collector_20200727_094932]$ ll
total 24K
-rw-------. 1 omm dbgrp 16K Feb 7 15:16 db1.tar.gz
-rw-------. 1 omm dbgrp 2.7K Feb 7 15:16 Detail.log
-rw-------. 1 omm dbgrp 1.1K Feb 7 15:16 Summary.log
[omm@ecs-e1b3 collector_20200727_094932]$ tar -zxvf db1.tar.gz
ecs-e1b3/
ecs-e1b3/logfiles/
ecs-e1b3/logfiles/log_20200727_094935975042.tar.gz
ecs-e1b3/planSimulatorfiles/
ecs-e1b3/catalogfiles/
ecs-e1b3/catalogfiles/dn_6001_pg_thread_wait_status_20200727_094935303146.csv
ecs-e1b3/catalogfiles/gs_clean_20200727_094935470508.txt
…………………………
ecs-e1b3/systemfiles/
ecs-e1b3/systemfiles/OS_information_20200727_094933424734.txt
ecs-e1b3/systemfiles/database_system_info_20200727_094933446671.txt
[omm@ecs-e1b3 collector_20200727_094932]$
在解压的db1(指的是服务器名,各自的不一样,请注意观察)下有各种定制收集的日志类型目录如下:
[omm@ecs-e1b3 collector_20200727_094932]$ cd db1
[omm@ecs-e1b3 ecs-e1b3]$ ll
total 32K
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 catalogfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 configfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 coreDumpfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 gstackfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 logfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 planSimulatorfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 systemfiles
drwx------ 2 omm dbgrp 4.0K Jul 27 09:49 xlogfiles
[omm@ecs-e1b3 ecs-e1b3]$ cd catalogfiles/
[omm@ecs-e1b3 catalogfiles]$ ll
total 16K
-rw------- 1 omm dbgrp 389 Jul 27 09:49 dn_6001_pg_locks_20200727_094934961507.csv
-rw------- 1 omm dbgrp 1.4K Jul 27 09:49 dn_6001_pg_stat_activity_20200727_094935134988.csv
-rw------- 1 omm dbgrp 878 Jul 27 09:49 dn_6001_pg_thread_wait_status_20200727_094935303146.csv
-rw------- 1 omm dbgrp 281 Jul 27 09:49 gs_clean_20200727_094935470508.txt
步骤 5下载收集后的日志文件。
根据自己需要比如可以通过WinSCP或者XFTP等SSH工具将日志文件下载至自己本地电脑。
使用root用户和密码登录数据库服务器(主机名为ecs的弹性公网IP):

点击“打开目录/书签”,输入目录路径“/opt/huawei/wisequery/omm_mppdb/”,点击确定后进入此目录:

逐层查找到“catalogfiles”文件夹,点击选中文件夹,然后点击“下载”,下载到Windows对应文件夹下:

查看下载后的文件夹内容:

图4-1日志文件下载

512_

52_
1ROOTopenGauss_su__ommOMM
Welcome_to_419902003400036oe1aarch64
System_information_as_of_time
Mon_Jul_27_112246_CST_2020
System_load_ 003
Processes_ 154
Memory_used_ 23
Swap_used_ 00
Usage_On_ 14
IP_address_ 192168012
Users_online_ 3
rootecse1b3__su__omm
Last_login_Mon_Jul_27_092344_CST_2020_on_pts0
Welcome_to_419902003400036oe1aarch64
System_information_as_of_time_ Mon_Jul_27_112337_CST_2020
System_load_ 001
Processes_ 156
Memory_used_ 24
Swap_used_ 00
Usage_On_ 14
IP_address_ 192168012
Users_online_ 3
_2openGauss
ommecse1b3__gs_om_t_status_920">5 最大连接数设置

5.1 实验介绍

5.1.1 关于本实验

当应用程序与数据库的连接数超过最大值,则新的连接无法建立。建议对连接数进行监控,及时释放空闲的连接或者增加最大连接数。

本实验主要是讲如何来设置数据库最大连接个数。

5.1.2 实验目的

掌握对数据库最大连接数的设置方法。

5.2 场景设置及操作步骤

步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统然后用 su – omm命令切换至OMM用户环境,登录后信息如下。

Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64

System information as of time: Mon Jul 27 11:22:46 CST 2020

System load: 0.03

Processes: 154

Memory used: 2.3%

Swap used: 0.0%

Usage On: 14%

IP address: 192.168.0.12

Users online: 3

[root@ecs-e1b3 ~]# su - omm

Last login: Mon Jul 27 09:23:44 CST 2020 on pts/0

Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64

System information as of time: Mon Jul 27 11:23:37 CST 2020

System load: 0.01

Processes: 156

Memory used: 2.4%

Swap used: 0.0%

Usage On: 14%

IP address: 192.168.0.12

Users online: 3

步骤 2确认openGauss数据库服务是否启动

[omm@ecs-e1b3 ~]$ gs_om -t status;

cluster_name : dbCluster
cluster_state : Normal
redistributing : No

cluster_state : Normal 表示已启动,可以正常使用。如果状态为非Normal表示不可用
为了实验场景设置,如果数据库服务没有启动,请执行步gs_om -t start 命令启动服务。
步骤 3登录数据库
使用gsql客户端以管理员用户身份连接postgres数据库,假设端口号为26000。
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:57:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

postgres=#
步骤 4查看当前数据库已使用的连接数
postgres=# select count(1) from pg_stat_activity;
count

10

(1 row)
10表示当前有10个应用已连接到数据库
步骤 5查看数据库设置的最大连接数
postgres=# SHOW max_connections;
max_connections

5000
(1 row)
5000 表示数据库设置的最大连接个数为5000。如果当前数据库已使用的连接数快接近于最大连接数时,运维人员先要果断的增加最大连接数以防系统新的连接无法建立。
步骤 6调整最大连接数参数
参数修改方式一:
先 \q 退出数据库,然后在omm 用户环境下通过gs_guc工具来增大参数值,如下:
[omm@ecs-e1b3 ~]$ gs_guc reload -I all -c “max_connections= 6000”;
expected instance path: [/gaussdb/data/db1/postgresql.conf]
gs_guc reload: max_connections=6000: [/gaussdb/data/db1/postgresql.conf]
server signaled
Total instances: 1. Failed instances: 0.
Success to perform gs_guc!
参数修改方式二:
也可以用alter system set 语句来设置此参数,如下:
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:57:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

postgres=# alter system set max_connections=6000;
NOTICE: please restart the database for the POSTMASTER level parameter to take effect.
ALTER SYSTEM SET
postgres=#\q
步骤 7重启数据库
gs_om -t stop先关闭数据库,然后用gs_om -t start再启动数据库
[omm@ecs-e1b3 ~]$ gs_om -t stop;
Stopping cluster.

Successfully stopped cluster.

End stop cluster.
[omm@ecs-e1b3 ~]$ gs_om -t start;
Starting cluster.

=========================================
Successfully started.
步骤 8验证参数设置是否成功
使用gsql客户端以管理员用户身份连接postgres数据库,然后查看参数值。
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:57:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

postgres=# SHOW max_connections;
max_connections

6000
(1 row)
这里显示max_connections 为 6000,说明前面参数的修改已经生效。
步骤 9退出数据库
postgres=#\q
最大连接数设置实验结束。

VACUUMVACUUM_FULL_FULLANALYZE
612_
VACUUMVACUUM_FULL_FULLANALYZE
62_
1ROOTopenGauss_su__ommOMM
Welcome_to_419902003400036oe1aarch64
System_information_as_of_time
Tue_Jul_27_162111_CST_2020
System_load_ 001
Processes_ 109
Memory_used_ 67
Swap_used_ 00
Usage_On_ 15
IP_address_ 192168096
Users_online_ 1
rootecse1b3__su__omm
Last_login_Fri_Jul__27_162211_CST_2020_on_pts0
Welcome_to_419902003400036oe1aarch64
System_information_as_of_time_ Tue_Jul_27_162111_CST_2020
System_load_ 001
Processes_ 111
Memory_used_ 70
Swap_used_ 00
Usage_On_ 15
IP_address_ 192168096
Users_online_ 1
ommecse1b3_
_2gsqlpostgres26000

ommecse1b3__gs_om_t_start
Starting_cluster_1030">6 例行表、索引的维护

6.1 实验介绍

6.1.1 关于本实验

为了保证数据库的有效运行,数据库必须在插入/删除操作后,基于客户场景,定期做VACUUM FULL和ANALYZE,更新统计信息,以便获得更优的性能;

VACUUM FULL可回收已更新或已删除的数据所占据的磁盘空间,同时将小数据文件合并;

VACUUM对每个表维护了一个可视化映射来跟踪包含对别的活动事务可见的数组的页。一个普通的索引扫描首先通过可视化映射来获取对应的数组,来检查是否对当前事务可见。若无法获取,再通过堆数组抓取的方式来检查。因此更新表的可视化映射,可加速唯一索引扫描;

ANALYZE可收集与数据库中表内容相关的统计信息。统计结果存储在系统表PG_STATISTIC中。查询优化器会使用这些统计数据,生成最有效的执行计划。

数据库经过多次删除操作后,索引页面上的索引键将被删除,造成索引膨胀。例行重建索引,可有效的提高查询效率。

本实验主要是通过使用VACUUM、VACUUM FULL FULL来收缩表,用ANALYZE来收集表的统计信息以及对表上的索引进行重建。

6.1.2 实验目的

掌握VACUUM、VACUUM FULL FULL、ANALYZE基本的使用及如何重建索引;

6.2 场景设置及操作步骤

步骤 1用ROOT用户登录装有openGauss数据库服务的操作系统然后用 su – omm命令切换至OMM用户环境,登录后信息如下。

Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64

System information as of time: Tue Jul 27 16:21:11 CST 2020

System load: 0.01

Processes: 109

Memory used: 6.7%

Swap used: 0.0%

Usage On: 15%

IP address: 192.168.0.96

Users online: 1

[root@ecs-e1b3 ~]# su - omm

Last login: Fri Jul 27 16:22:11 CST 2020 on pts/0

Welcome to 4.19.90-2003.4.0.0036.oe1.aarch64

System information as of time: Tue Jul 27 16:21:11 CST 2020

System load: 0.01

Processes: 111

Memory used: 7.0%

Swap used: 0.0%

Usage On: 15%

IP address: 192.168.0.96

Users online: 1

[omm@ecs-e1b3 ~] < b r / > 步 骤 2 启 动 服 务 器 后 , 然 后 使 用 g s q l 客 户 端 以 管 理 员 用 户 身 份 连 接 p o s t g r e s 数 据 库 , 假 设 端 口 号 为 26000 。 < b r / > 启 动 数 据 库 服 务 。 < b r / > [ o m m @ e c s − e 1 b 3   ] <br /> 步骤 2启动服务器后,然后使用gsql客户端以管理员用户身份连接postgres数据库,假设端口号为26000。<br /> 启动数据库服务。<br /> [omm@ecs-e1b3 ~] <br/>步骤2启动服务器后,然后使用gsql客户端以管理员用户身份连接postgres数据库,假设端口号为26000。<br/>启动数据库服务。<br/>[omm@ecs−e1b3 ] gs_om -t start;

Starting cluster.

=========================================
Successfully started.
连接postgres数据库。
[omm@ecs-e1b3 ~]$ gsql -d postgres -p 26000 -r
gsql ((openGauss 1.0.0 build 38a9312a) compiled at 2020-05-27 14:56:08 commit 472 last mr 549 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type “help” for help.

postgres=#
步骤 3创建student表
postgres=# drop table student;
postgres=# CREATE TABLE student
( std_id INT NOT NULL,
std_name VARCHAR(20) NOT NULL,
std_sex VARCHAR(6),
std_birth DATE,
std_in DATE NOT NULL,
std_address VARCHAR(100)
);

CREATE TABLE
步骤 4表数据插入
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (1,‘张一’,‘男’,‘1993-01-01’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (2,‘张二’,‘男’,‘1993-01-02’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (3,‘张三’,‘男’,‘1993-01-03’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (4,‘张四’,‘男’,‘1993-01-04’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (5,‘张五’,‘男’,‘1993-01-05’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (6,‘张六’,‘男’,‘1993-01-06’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (7,‘张七’,‘男’,‘1993-01-07’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (8,‘张八’,‘男’,‘1993-01-08’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (9,‘张九’,‘男’,‘1993-01-09’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (10,‘李一’,‘男’,‘1993-01-10’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (11,‘李二’,‘男’,‘1993-01-11’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (12,‘李三’,‘男’,‘1993-01-12’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (13,‘李四’,‘男’,‘1993-01-13’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (14,‘李五’,‘男’,‘1993-01-14’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (15,‘李六’,‘男’,‘1993-01-15’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (16,‘李七’,‘男’,‘1993-01-16’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (17,‘李八’,‘男’,‘1993-01-17’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (18,‘李九’,‘男’,‘1993-01-18’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (19,‘王一’,‘男’,‘1993-01-19’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (20,‘王二’,‘男’,‘1993-01-20’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (21,‘王三’,‘男’,‘1993-01-21’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (22,‘王四’,‘男’,‘1993-01-22’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (23,‘王五’,‘男’,‘1993-01-23’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (24,‘王六’,‘男’,‘1993-01-24’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (25,‘王七’,‘男’,‘1993-01-25’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (26,‘王八’,‘男’,‘1993-01-26’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (27,‘王九’,‘男’,‘1993-01-27’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (28,‘钱一’,‘男’,‘1993-01-28’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (29,‘钱二’,‘男’,‘1993-01-29’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (30,‘钱三’,‘男’,‘1993-01-30’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (31,‘钱四’,‘男’,‘1993-02-01’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (32,‘钱五’,‘男’,‘1993-02-02’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (33,‘钱六’,‘男’,‘1993-02-03’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (34,‘钱七’,‘男’,‘1993-02-04’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (35,‘钱八’,‘男’,‘1993-02-05’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (36,‘钱九’,‘男’,‘1993-02-06’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (37,‘吴一’,‘男’,‘1993-02-07’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (38,‘吴二’,‘男’,‘1993-02-08’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (39,‘吴三’,‘男’,‘1993-02-09’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (40,‘吴四’,‘男’,‘1993-02-10’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (41,‘吴五’,‘男’,‘1993-02-11’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (42,‘吴六’,‘男’,‘1993-02-12’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (43,‘吴七’,‘男’,‘1993-02-13’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (44,‘吴八’,‘男’,‘1993-02-14’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (45,‘吴九’,‘男’,‘1993-02-15’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (46,‘柳一’,‘男’,‘1993-02-16’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (47,‘柳二’,‘男’,‘1993-02-17’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (48,‘柳三’,‘男’,‘1993-02-18’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (49,‘柳四’,‘男’,‘1993-02-19’,‘2011-09-01’,‘江苏省南京市雨花台区’);
INSERT INTO student(std_id,std_name,std_sex,std_birth,std_in,std_address) VALUES (50,‘柳五’,‘男’,‘1993-02-20’,‘2011-09-01’,‘江苏省南京市雨花台区’);
步骤 5数据查询统计
postgres=# select count(*) from student;
count

50

(1 row)

postgres=# select * from student order by std_id;
std_id | std_name | std_sex | std_birth | std_in | std_address
--------±---------±--------±--------------------±--------------------±---------------------
1 | 张一 | 男 | 1993-01-01 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
2 | 张二 | 男 | 1993-01-02 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
3 | 张三 | 男 | 1993-01-03 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
4 | 张四 | 男 | 1993-01-04 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
5 | 张五 | 男 | 1993-01-05 00:00:00 | 2011-09-01 00:00:00 | 江苏省南京市雨花台区
………………
步骤 6查看表信息
postgres=# \d student
Table “public.student”
Column | Type | Modifiers
-------------±-------------------------------±----------
std_id | integer | not null
std_name | character varying(20) | not null
std_sex | character varying(6) |
std_birth | timestamp(0) without time zone |
std_in | timestamp(0) without time zone | not null
std_address | character varying(100) |
步骤 7使用VACUUM命令,进行磁盘空间回收
postgres=# vacuum student;
VACUUM
步骤 8删除表中数据
postgres=# delete from student where std_id>30;
DELETE 20
步骤 9使用VACUUM FULL命令,进行磁盘空间回收
postgres=# vacuum full student;
VACUUM
步骤 10使用ANALYZE语句更新统计信息
postgres=# analyze student;
ANALYZE
步骤 11使用ANALYZE VERBOSE语句更新统计信息,并输出表的相关信息
postgres=# analyze verbose student;
INFO: analyzing “public.student”(dn_6001 pid=37195)
INFO: ANALYZE INFO : “student”: scanned 1 of 1 pages, containing 30 live rows and 20 dead rows; 30 rows in sample, 30 estimated total rows(dn_6001 pid=37195)
ANALYZE
步骤 12执行VACUUM ANALYZE命令进行查询优化
postgres=# vacuum analyze student;
VACUUM
步骤 13查看特定表的统计信息
postgres=# select relname,n_tup_ins,n_tup_upd,n_tup_del,last_analyze,vacuum_count from PG_STAT_ALL_TABLES where relname=‘student’;
relname | n_tup_ins | n_tup_upd | n_tup_del | last_analyze | vacuum_count
---------±----------±----------±----------±-----------------------------±-------------
student | 50 | 0 | 20 | 2020-07-27 17:07:19.17167+08 | 3
(1 row)
postgres=#
PG_STAT_ALL_TABLES视图将包含当前数据库中每个表的一行统计信息,以上查询结果中各列分别表示:
Relname 表名
n_tup_ins 插入行数
n_tup_upd 更新行数
n_tup_del 删除行数
last_analyze 上次手动分析该表的时间
vacuum_count 这个表被手动清理的次数
步骤 14索引维护
说明:
如果数据发生大量删除后,索引页面上的索引键将被删除,导致索引页面数量的减少,造成索引膨胀。重建索引可回收浪费的空间。
新建的索引中逻辑结构相邻的页面,通常在物理结构中也是相邻的,所以一个新建的索引比更新了多次的索引访问速度要快。
重建索引有以下两种方式:
1、使用REINDEX语句重建索引;
2、先删除索引(DROP INDEX),再创建索引(CREATE INDEX)。
先在student表的std_name列上创建一个索引,如下:
postgres=# create index inx_stu01 on student(std_name);
CREATE INDEX
postgres=#
方式1:使用REINDEX语句重建索引,具体如下:
postgres=# reindex table student;
REINDEX
postgres=#
方式2:先删除索引(DROP INDEX),再创建索引(CREATE INDEX),具体如下:
postgres=# drop index inx_stu01;
DROP INDEX
postgres=# create index inx_stu01 on student(std_name);
CREATE INDEX
postgres=#
查看表结构信息,具体如下:
postgres=# \d student;
Table “public.student”
Column | Type | Modifiers
-------------±-------------------------------±----------
std_id | integer | not null
std_name | character varying(20) | not null
std_sex | character varying(6) |
std_birth | timestamp(0) without time zone |
std_in | timestamp(0) without time zone | not null
std_address | character varying(100) |
Indexes:
“inx_stu01” btree (std_name) TABLESPACE pg_default
步骤 15退出数据库
postgres=#\q
例行表、索引的维护实验结束。

实验结果:
截图一:操作系参数检查截图
图片1.png图片2.png
截图二:设置最大连接数
图片3.png图片4.png
截图三:
图片5.png
分析总结: 本次实验我掌握了系统参数检查、openGauss健康状态检查、数据库性能检查、日志检查和清理等操作。实验比较简单,没有遇到什么问题。

标签:std,01,15,09,student,address,openGauss,雨花台区,参赛
来源: https://blog.csdn.net/GaussDB/article/details/118544120

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有