当前位置: 首页 > news >正文

网站首页改版方案中国建设银行开放式网站

网站首页改版方案,中国建设银行开放式网站,郑州影视公司招聘,中国设计网站官网地址发文章是为了证明自己真的掌握了一个知识#xff0c;同时给他人带来帮助#xff0c;如有问题#xff0c;欢迎指正#xff0c;祝大家万事胜意#xff01; 目录 前言 openGauss数据库维护管理 1 操作系统参数检查 1.1 实验介绍 1.2 场景设置及操作步骤 2 openGauss 运…发文章是为了证明自己真的掌握了一个知识同时给他人带来帮助如有问题欢迎指正祝大家万事胜意 目录 前言 openGauss数据库维护管理 1 操作系统参数检查 1.1 实验介绍 1.2 场景设置及操作步骤 2 openGauss 运行健康状态检查 2.1 实验介绍 2.2 场景设置及操作步骤 3 数据库性能检查 3.1 实验介绍 3.2 通过 gs_checkperf 工具来检查数据库性能 3.3 通过 EXPLAIN 进行 SQL 语句优化 4 日志检查 4.1 实验介绍 4.2 通过 gs_collector 工具来收集日志信息 5 最大连接数设置 5.1 实验介绍 5.2 场景设置及操作步骤 6 例行表、索引的维护 6.1 实验介绍 6.2 场景设置及操作步骤 前言 本实验主要内容为操作系统参数检查、 openGauss 健康状态检查、数据库性能检查、日志检查 和清理、时间一致性检查、应用连接数检查、例行维护表等 我的环境 设备名称设备型号软件版本虚拟机VMwareVMware-workstation-full-17.5.1操作系统openEuler   openEuler 22.3LTS数据库openGauss  openGauss 5.0.0 需要的工具大家不用现在下后面用到了再下也可以如果需要相关文件可以评论其实大多数都是可以去官网下的哈因为我只能通过网盘给大家文件又有点大网盘的速度大家都是清楚的哈哈所以还是推荐大家去官网如果实在找不到可以找我 openGauss数据库维护管理 1 操作系统参数检查 1.1 实验介绍 gs_checkos 工具用来帮助检查操作系统、控制参数、磁盘配置等内容并对系统控制参数、 I/O 配置、网络配置和 THP 服务等信息进行配置。 本实验主要是通过 gs_checkos 工具来检查操作系统参数设置是否合理。先进行场景设置然后 根据检查结果进行参数调整。 1.2 场景设置及操作步骤 步骤 1 用 ROOT 用户登录装有 openGauss 数据库服务的操作系统登录后信息如下 Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 25日 星期一 19:09:30 CSTSystem load: 0.02 Processes: 195 Memory used: 39.3% Swap used: 13.3% Usage On: 25% IP address: 192.168.28.131 Users online: 1步骤 2 在 ROOT 用户下执行 gs_checkos 先对系统参数进行检查。 [rootnode0 ~]# gs_checkos -i A Checking items:A1. [ OS version status ] : NormalA2. [ Kernel version status ] : NormalA3. [ Unicode status ] : NormalA4. [ Time zone status ] : NormalA5. [ Swap memory status ] : WarningA6. [ System control parameters status ] : WarningA7. [ File system configuration status ] : NormalA8. [ Disk configuration status ] : NormalA9. [ Pre-read block size status ] : Normal BondMode NullA11.[ Network card configuration status ] : NormalA12.[ Time consistency status ] : WarningA13.[ Firewall service status ] : NormalA14.[ THP service status ] : Normal Total numbers:13. Abnormal numbers:0. Warning numbers:3.2 openGauss 运行健康状态检查 2.1 实验介绍 gs_check 能够帮助用户在 openGauss 运行过程中全量的检查 openGauss 运行环境操作系 统环境网络环境及数据库执行环境也有助于在 openGauss 重大操作之前对各类环境进行全 面检查有效保证操作执行成功。 本实验主要是通过 gs_check 工具来检查 openGauss 数据库运行状态。先进行场景设置然后 根据检查结果进行数据库调整。 2.2 场景设置及操作步骤 步骤 1 用 ROOT 用户登录装有 openGauss 数据库服务的操作系统然后用 su – omm 命令切换至 OMM 用户环境登录后信息如下。 [rootnode0 ~]# su - omm Last login: Mon Mar 25 18:47:31 CST 2024 on pts/0Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 25日 星期一 19:31:35 CSTSystem load: 0.30 Processes: 195 Memory used: 39.0% Swap used: 14.3% Usage On: 25% IP address: 192.168.28.131 Users online: 1 To run a command as administrator(user root),use sudo command.步骤 2 确认 openGauss 数据库服务是否启动。 [ommnode0 ~]$ gs_om -t status -----------------------------------------------------------------------cluster_name : dbCluster cluster_state : Normal redistributing : No-----------------------------------------------------------------------cluster_state : Normal 表示已启动可以正常使用。如果状态为非 Normal 表示不可用 为了实验场景设置如果数据库服务已经启动请执行步骤 3 先关闭服务。 步骤 3 关闭 openGauss 数据库服务。 [ommnode0 ~]$ gs_om -t stop Stopping cluster.Successfully stopped cluster.End stop cluster.步骤 4 检查 openGauss 实例连接。 [ommnode0 ~]$ gs_check -i CheckDBConnection -L2024-03-25 19:37:53 [NAM] CheckDBConnection 2024-03-25 19:37:53 [STD] 检查能否连接数据库如果连接成功则检查项通过否则检查项不通过 2024-03-25 19:37:53 [RST] NG The database can not be connected. 2024-03-25 19:37:53 [RAW]说明 CheckDBConnection...........................NG 表示连接检查项无用 The database can not be connected. 表示实例不能连接 Failed. All check items run completed. Total:1 NG:1 表示共检查 1 项并且检查结果未通过。 步骤 5 启动 openGauss 数据库服务。 [ommnode0 ~]$ gs_om -t start Starting cluster.[SUCCESS] node0 ......Successfully started.步骤 6 确认 openGauss 数据库服务已启动。 [ommnode0 ~]$ gs_om -t status; -----------------------------------------------------------------------cluster_name : dbCluster cluster_state : Normal redistributing : No-----------------------------------------------------------------------步骤 7 再次检查 openGauss 实例连接。 [ommnode0 ~]$ gs_check -i CheckDBConnection -L2024-03-25 19:46:27 [NAM] CheckDBConnection 2024-03-25 19:46:27 [STD] 检查能否连接数据库如果连接成功则检查项通过否则检查项不通过 2024-03-25 19:46:27 [RST] OK The database connection is normal. 2024-03-25 19:46:27 [RAW]source /home/omm/.bashrc gsql -m -d postgres -p 15400 -c select pg_sleep(1); 说明 CheckDBConnection...........................OK 表示连接检查项正常 Success. All check items run completed. Total:1 Success:1 表示共检查 1 项并且检查结 果成功。 openGauss 数据库运行健康状态检查实验结束 3 数据库性能检查 3.1 实验介绍 openGauss 提供了 gs_checkperf 工具来帮助用户了解 openGauss 的负载情况。 本实验主要是通过 gs_checkperf 工具来检查 openGauss 数据库性能以及通过 EXPLAIN 来进行 SQL 语句优化。 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 用户环境登录后信息如下。 [rootnode0 ~]# su - omm Last login: Mon Mar 25 18:47:31 CST 2024 on pts/0Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 25日 星期一 19:31:35 CSTSystem load: 0.30 Processes: 195 Memory used: 39.0% Swap used: 14.3% Usage On: 25% IP address: 192.168.28.131 Users online: 1 To run a command as administrator(user root),use sudo command.步骤 2 先启动数据库服务再用 gs_checkperf 检查下再使用 gsql 客户端以管理员用户身份连接 postgres 数据库假设端口号为 15400 。 先启动数据库服务。 [ommnode0 ~]$ gs_om -t start Starting cluster.[SUCCESS] node0: [2024-03-25 19:53:25.112][42128][][gs_ctl]: gs_ctl started,datadir is /opt/huawei/install/data/dn [2024-03-25 19:53:25.129][42128][][gs_ctl]: another server might be running; Please use the restart commandSuccessfully started.用 gs_checkperf 检查下。 [ommnode0 ~]$ gs_checkperf Cluster statistics information:Host CPU busy time ratio : 1.79 %MPPDB CPU time % in busy time : 8.68 %Shared Buffer Hit ratio : 99.56 %In-memory sort ratio : 0Physical Reads : 759Physical Writes : 124DB size : 50 MBTotal Physical writes : 124Active SQL count : 4Session count : 8然后连接 postgres 数据库。 [ommnode0 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type help for help. 步骤 3 对 PMK 模式下的表进行统计信息收集。 openGauss# analyze pmk.pmk_configuration; ANALYZE openGauss# analyze pmk.pmk_meta_data; ANALYZE openGauss# analyze pmk.pmk_snapshot; ANALYZE openGauss# analyze pmk.pmk_snapshot_datanode_stat; ANALYZEgs_checkperf 工具的监控信息依赖于 pmk 模式下的表的数据如果 pmk 模式下的表未执 行 analyze 操作则可能导致 gs_checkperf 工具执行失败。 步骤 4 执行简要性能检查。 用 \q 先退出 postgres 数据库然后在操作系统用户 omm 环境下去执行 gs_checkperf 检查 工具具体如下 openGauss# \q [ommnode0 ~]$ gs_checkperf Cluster statistics information:Host CPU busy time ratio : 2.02 %MPPDB CPU time % in busy time : 16.25 %Shared Buffer Hit ratio : 99.67 %In-memory sort ratio : 0Physical Reads : 777Physical Writes : 335DB size : 51 MBTotal Physical writes : 335Active SQL count : 4Session count : 8步骤 5 执行详细性能检查。 [ommnode0 ~]$ gs_checkperf --detail Cluster statistics information: Host CPU usage rate:Host total CPU time : 26998790.000 JiffiesHost CPU busy time : 594830.000 JiffiesHost CPU iowait time : 5920.000 JiffiesHost CPU busy time ratio : 2.20 %Host CPU iowait time ratio : .02 % MPPDB CPU usage rate:MPPDB CPU time % in busy time : 16.57 %MPPDB CPU time % in total time : .37 % Shared buffer hit rate:Shared Buffer Reads : 1232Shared Buffer Hits : 430218Shared Buffer Hit ratio : 99.71 % In memory sort rate:In-memory sort count : 0In-disk sort count : 0In-memory sort ratio : 0 I/O usage:Number of files : 121Physical Reads : 785Physical Writes : 492Read Time : 168726 msWrite Time : 5694 ms Disk usage:DB size : 51 MBTotal Physical writes : 492Average Physical write : 86406.74Maximum Physical write : 492 Activity statistics:Active SQL count : 4Session count : 8 Node statistics information: dn_6001:MPPDB CPU Time : 98590 JiffiesHost CPU Busy Time : 594830 JiffiesHost CPU Total Time : 26998790 JiffiesMPPDB CPU Time % in Busy Time : 16.57 %MPPDB CPU Time % in Total Time : .37 %Physical memory : 1497370624 BytesDB Memory usage : 5200146432 BytesShared buffer size : 284164096 BytesShared buffer hit ratio : 99.71 %Sorts in memory : 0Sorts in disk : 0In-memory sort ratio : 0Number of files : 121Physical Reads : 785Physical Writes : 492Read Time : 168726Write Time : 5694 Session statistics information(Top 10): Session CPU statistics: 1 dn_6001-postgres-omm:Session CPU time : 3Database CPU time : 98680Session CPU time % : 0.00 % 2 dn_6001-postgres-omm:Session CPU time : 0Database CPU time : 98680Session CPU time % : 0.00 % 3 dn_6001-postgres-omm:Session CPU time : 0Database CPU time : 98680Session CPU time % : 0.00 % 4 dn_6001-postgres-omm:Session CPU time : 0Database CPU time : 98680Session CPU time % : 0.00 %Session Memory statistics: 1 dn_6001-postgres-omm:Buffer Reads : 303Shared Buffer Hit ratio : 100.00In Memory sorts : 0In Disk sorts : 0In Memory sorts ratio : 0Total Memory Size : 7002360Used Memory Size : 5792184 2 dn_6001-postgres-omm:Buffer Reads : 300Shared Buffer Hit ratio : 99.01In Memory sorts : 0In Disk sorts : 0In Memory sorts ratio : 0Total Memory Size : 6994168Used Memory Size : 5790576 3 dn_6001-postgres-omm:Buffer Reads : 303Shared Buffer Hit ratio : 100.00In Memory sorts : 0In Disk sorts : 0In Memory sorts ratio : 0Total Memory Size : 6961400Used Memory Size : 5782816 4 dn_6001-postgres-omm:Buffer Reads : 1113Shared Buffer Hit ratio : 100.00In Memory sorts : 1In Disk sorts : 0In Memory sorts ratio : 100.00Total Memory Size : 12467920Used Memory Size : 10249640Session IO statistics: 1 dn_6001-postgres-omm:Physical Reads : 3Read Time : 11883 2 dn_6001-postgres-omm:Physical Reads : 0Read Time : 0 3 dn_6001-postgres-omm:Physical Reads : 0Read Time : 0 4 dn_6001-postgres-omm:Physical Reads : 0Read Time : 03.3 通过 EXPLAIN 进行 SQL 语句优化 说明   使用 explain 能显示 SQL 语句的执行计划 ;   执行计划将显示 SQL 语句所引用的表会采用什么样的扫描方式如简单的顺序扫描、索 引扫描等。如果引用了多个表执行计划还会显示用到的 JOIN 算法 ;   执行计划的最关键的部分是语句的预计执行开销这是计划生成器估算执行该语句将花费 多长的时间 ;   若指定了 ANALYZE 选项则该语句模拟执行并形成最优的执行计划并非真正执行然 后根据实际的运行结果显示统计数据包括每个计划节点内时间总开销毫秒为单位和 实际返回的总行数。这对于判断计划生成器的估计是否接近现实非常有用。 步骤 1 用 ROOT 用户登录装有 openGauss 数据库服务的操作系统然后用 su – omm 命令切换至 OMM 用户环境登录后信息如下。 [rootnode0 ~]# su - omm Last login: Mon Mar 25 19:31:35 CST 2024 on pts/0Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 25日 星期一 20:21:39 CSTSystem load: 0.02 Processes: 195 Memory used: 38.6% Swap used: 13.9% Usage On: 25% IP address: 192.168.28.131 Users online: 1 To run a command as administrator(user root),use sudo command.步骤 2 先启动数据库服务然后使用 gsql 客户端以管理员用户身份连接 postgres 数据库假设端 口号为 15400 。 启动数据库服务。 [ommnode0 ~]$ gs_om -t start Starting cluster.[SUCCESS] node0: ......Successfully started. 然后连接 postgres 数据库。 [ommnode0 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type help for help.步骤 3 创建 student 表。 openGauss# CREATE TABLE student openGauss-# ( std_id INT NOT NULL, openGauss(# std_name VARCHAR(20) NOT NULL, openGauss(# std_sex VARCHAR(6), openGauss(# std_birth DATE, openGauss(# std_in DATE NOT NULL, openGauss(# std_address VARCHAR(100) openGauss(# ); CREATE TABLE步骤 4 表数据插入。 下面是原数据直接复制粘贴就行从上的图也可以看出如果我把代码录制出来会有干扰比如openGauss#啥的就是让自己敲下面的插入代码很麻烦也没有很大的意义后面这种代码量比较多的我就直接给批量的语句方便大家复制在虚拟机直接粘贴就行如果不知道怎么粘贴可以直接问 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 数据查询统计。 openGauss# select count(*) from student;count -------50 (1 row)openGauss# 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 | 张六 | 男 | 1993-01-06 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 7 | 张七 | 男 | 1993-01-07 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 8 | 张八 | 男 | 1993-01-08 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 9 | 张九 | 男 | 1993-01-09 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 10 | 李一 | 男 | 1993-01-10 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 11 | 李二 | 男 | 1993-01-11 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 12 | 李三 | 男 | 1993-01-12 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 13 | 李四 | 男 | 1993-01-13 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 14 | 李五 | 男 | 1993-01-14 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区| | | | | 15 | 李六 | 男 | 1993-01-15 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区……部分粘贴有省略//注就是查询结果我就不完全粘贴了我尽量减少一些无用的代码不然影响观看 注就是查询结果我就不完全粘贴了我尽量减少一些无用的代码不然影响观看 步骤 6 查看表信息。 openGauss# \d studentTable public.studentColumn | Type | Modifiers --------------------------------------------------------std_id | integer | not nullstd_name | character varying(20) | not nullstd_sex | character varying(6) | std_birth | timestamp(0) without time zone | std_in | timestamp(0) without time zone | not nullstd_address | character varying(100) | 步骤 7 收集表的统计信息 openGauss# ANALYZE VERBOSE student; INFO: analyzing public.student(dn_6001 pid3982) 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 pid3982) ANALYZE使用 ANALYZE VERBOSE 语句更新统计信息会同时输出表的相关信息。 步骤 8 查看语句的执行计划。 openGauss# explain select * from student where std_id 30;QUERY PLAN --------------------------------------------------------Seq Scan on student (cost0.00..1.62 rows1 width63)Filter: (std_id 30) (2 rows) Seq Scan on student 表示使用的是全表扫描。 步骤 9 给表添加主键 openGauss# 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步骤 10 再次查看表信息。 确定主键是否建好。 openGauss# \d studentTable public.studentColumn | Type | Modifiers --------------------------------------------------------std_id | integer | not nullstd_name | character varying(20) | not nullstd_sex | character varying(6) | std_birth | timestamp(0) without time zone | std_in | timestamp(0) without time zone | not nullstd_address | character varying(100) | Indexes:student_pkey PRIMARY KEY, btree (std_id) TABLESPACE pg_defaultstudent_pkey 为主键名称。 步骤 11 通过 hint 来优化语句扫描方式。 通过加 hint 来使查询语句进行索引扫描最后退出数据库连接。 openGauss# explain select /*indexscan(student student_pkey)*/ * from student where std_id30;QUERY PLAN -----------------------------------------------------------------------------[Bypass]Index Scan using student_pkey on student (cost0.00..8.27 rows1 width63)Index Cond: (std_id 30) (3 rows)Index Scan using student_pkey on student 表示语句通过 student 表上的主键索引 student_pkey 进行了索引扫描。 EXPLAIN 进行 SQL 优化实验结束。 4 日志检查 4.1 实验介绍 数据库运行时某些操作在执行过程中可能会出现错误数据库依然能够运行。但是此时数据 库中的数据可能已经发生不一致的情况。建议检查 openGauss 运行日志及时发现隐患。 当 openGauss 发生故障时使用 gs_collector 此工具收集 OS 信息、日志信息以及配置文件 等信息来定位问题。 本实验主要是先手工设置收集配置信息然后通过 gs_collector 工具调整用配置来收集相关日 志信息。 4.2 通过 gs_collector 工具来收集日志信息 步骤 1 设置收集配置文件。 openGauss# \q [ommnode0 ~]$ pwd /home/omm [ommnode0 ~]$ 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 收集 OS 信息及日志信息。 begin-time、 end-time 的值根据自己实际想收集的时间来设置。 [ommnode0 ~]$ gs_collector --begin-time20240301 23:00 --end-time20240325 18:00 Successfully parsed the configuration file. create Dir. Successfully create dir. do system check interval 0 : count 1 Collecting OS information. The cmd is source /home/omm/.bashrc; python3 /opt/huawei/install/om/script/local/LocalCollect.py -t system_check -U omm -l /var/log/omm/omm/om/gs_local.log -C {#TypeName#: #System#, #Content#: #ps,ioStat,netFlow,spaceUsage,cpuInfo,memInfo,disk,#, #Interval#: #0#, #Count#: #1#} 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 /var/log/omm/omm/collector_20240328_213601.tar.gz.收集完后所有的结果存放在/var/log/omm/omm/collector_20240328_213601.tar.gz包中 步骤 3 查看日志信息。 先进入日志包所在的目录然后将日志包进行解压。 [ommnode0 ~]$ cd /var/log/omm/omm/ [ommnode0 omm]$ ll total 324 drwxr-x--- 3 omm dbgrp 4096 Mar 16 09:51 asp_data drwxr-x--- 7 omm dbgrp 4096 Mar 15 17:44 bin drwxr-x--- 3 omm dbgrp 4096 Mar 15 20:37 cm -rw------- 1 omm dbgrp 136455 Mar 25 19:02 collector_20240325_190144.tar.gz -rw------- 1 omm dbgrp 150982 Mar 28 21:36 collector_20240328_213601.tar.gz drwx------ 3 omm dbgrp 4096 Mar 16 09:51 gs_profile drwxr-x--- 3 omm dbgrp 4096 Mar 16 09:51 mem_log drwxr-x--- 2 omm dbgrp 4096 Mar 28 21:36 om drwxr-x--- 3 omm dbgrp 4096 Mar 15 17:44 pg_audit drwxr-x--- 3 omm dbgrp 4096 Mar 15 17:44 pg_log drwxr-x--- 3 omm dbgrp 4096 Mar 16 09:51 pg_perf drwxr-x--- 3 omm dbgrp 4096 Mar 16 09:51 sql_monitor [ommnode0 omm]$ tar -zxvf collector_20240328_213601.tar.gz collector_20240328_213601/ collector_20240328_213601/node0.tar.gz collector_20240328_213601/Summary.log collector_20240328_213601/Detail.log接下来进入解压后的文件夹 collector_20240328_213601这个每个人可能不一样不要完全复制观察一下和你的解压时间挂钩大家仔细看看并对 node0.tar.gz 这个也是和主机名挂钩包进一步解压。 [ommnode0 omm]$ cd collector_20240328_213601 [ommnode0 collector_20240328_213601]$ ll total 156 -rw------- 1 omm dbgrp 2870 Mar 28 21:36 Detail.log -rw------- 1 omm dbgrp 150043 Mar 28 21:36 node0.tar.gz -rw------- 1 omm dbgrp 1055 Mar 28 21:36 Summary.log [ommnode0 collector_20240328_213601]$ tar -zxvf node0.tar.gz node0/ node0/gstackfiles/ node0/configfiles/ node0/configfiles/config_20240328_213613624181/ node0/configfiles/config_20240328_213613624181/dn_6001/ node0/configfiles/config_20240328_213613624181/dn_6001/pg_ident.conf node0/configfiles/config_20240328_213613624181/dn_6001/gaussdb.state node0/configfiles/config_20240328_213613624181/dn_6001/pg_replslot/ node0/configfiles/config_20240328_213613624181/dn_6001/pg_hba.conf node0/configfiles/config_20240328_213613624181/dn_6001/postgresql.conf node0/systemfiles/ node0/systemfiles/OS_information_20240328_213603621784.txt node0/systemfiles/database_system_info_20240328_213603672555.txt node0/coreDumpfiles/ node0/planSimulatorfiles/ node0/catalogfiles/ node0/catalogfiles/dn_6001_pg_locks_20240328_213608752242.csv node0/catalogfiles/dn_6001_pg_stat_activity_20240328_213609154400.csv node0/catalogfiles/gs_clean_20240328_213610016028.txt node0/catalogfiles/dn_6001_pg_thread_wait_status_20240328_213609607570.csv node0/logfiles/ node0/logfiles/log_20240328_213611730074.tar.gz node0/xlogfiles/在解压的 node0指的是服务器名/主机名各自的不一样请注意观察下有各种定制收集的日志 [ommnode0 collector_20240328_213601]$ cd node0 [ommnode0 node0]$ ll total 32 drwx------ 2 omm dbgrp 4096 Mar 28 21:36 catalogfiles drwx------ 3 omm dbgrp 4096 Mar 28 21:36 configfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 coreDumpfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 gstackfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 logfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 planSimulatorfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 systemfiles drwx------ 2 omm dbgrp 4096 Mar 28 21:36 xlogfiles [ommnode0 node0]$ cd catalogfiles/ [ommnode0 catalogfiles]$ ll total 16 -rw------- 1 omm dbgrp 392 Mar 28 21:36 dn_6001_pg_locks_20240328_213608752242.csv -rw------- 1 omm dbgrp 1851 Mar 28 21:36 dn_6001_pg_stat_activity_20240328_213609154400.csv -rw------- 1 omm dbgrp 1945 Mar 28 21:36 dn_6001_pg_thread_wait_status_20240328_213609607570.csv -rw------- 1 omm dbgrp 286 Mar 28 21:36 gs_clean_20240328_213610016028.txt [ommnode0 catalogfiles]$ 步骤 4 下载收集后的日志文件。 根据自己需要比如可以通过 WinSCP 我用的这个这个工具主要是连接主机和虚拟机的 或者 XFTP 等 SSH 工具将日志文件下载至自己本地电脑 如 5 最大连接数设置 5.1 实验介绍 当应用程序与数据库的连接数超过最大值则新的连接无法建立。建议对连接数进行监控及 时释放空闲的连接或者增加最大连接数。 本实验主要是讲如何来设置数据库最大连接个数。 5.2 场景设置及操作步骤 步骤 1 用 ROOT 用户登录装有 openGauss 数据库服务的操作系统然后用 su – omm 命令切换至 OMM 用户环境登录后信息如下。 [rootnode0 ~]# su - omm Last login: Thu Mar 28 21:10:18 CST 2024 on pts/0Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 28日 星期四 22:03:30 CSTSystem load: 0.02 Processes: 199 Memory used: 39.1% Swap used: 21.8% Usage On: 25% IP address: 192.168.28.131 Users online: 2 To run a command as administrator(user root),use sudo command.步骤 2 确认 openGauss 数据库服务是否启动 [ommnode0 ~]$ gs_om -t status; -----------------------------------------------------------------------cluster_name : dbCluster cluster_state : Normal redistributing : No-----------------------------------------------------------------------cluster_state : Normal 表示已启动可以正常使用。如果状态为非 Normal 表示不可用 为了实验场景设置如果数据库服务没有启动请执行步 gs_om -t start 命令启动服务。 步骤 3 登录数据库 使用 gsql 客户端以管理员用户身份连接 postgres 数据库假设端口号为 15400 。 [ommnode0 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type help for help.步骤 4 查看当前数据库已使用的连接数 openGauss# select count(1) from pg_stat_activity;count -------8 (1 row) 8 表示当前有 8 个应用已连接到数据库 步骤 5 查看数据库设置的最大连接数 openGauss# SHOW max_connections;max_connections -----------------5000 (1 row)5000 表示数据库设置的最大连接个数为 5000 。如果当前数据库已使用的连接数快接近于最大 连接数时运维人员先要果断的增加最大连接数以防系统新的连接无法建立。 步骤 6 调整最大连接数参数 先 \q 退出数据库然后在 omm 用户环境下通过 gs_guc 工具来增大参数值如下 openGauss# \q [ommnode0 ~]$ gs_guc reload -I all -c max_connections 6000; The gs_guc run with the following arguments: [gs_guc -I all -c max_connections 6000 reload ]. expected instance path: [/opt/huawei/install/data/dn/postgresql.conf] gs_guc reload: max_connections6000: [/opt/huawei/install/data/dn/postgresql.conf] server signaledTotal instances: 1. Failed instances: 0. Success to perform gs_guc!步骤 7 重启数据库 gs_om -t stop 先关闭数据库 , 然后用 gs_om -t start 再启动数据库 [ommnode0 ~]$ gs_om -t stop; Stopping cluster.Successfully stopped cluster.End stop cluster. [ommnode0 ~]$ gs_om -t start; Starting cluster.[SUCCESS] node0 2024-03-28 22:26:31.558 66057e17.1 [unknown] 140368399876032 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2024-03-28 22:26:31.558 66057e17.1 [unknown] 140368399876032 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2024-03-28 22:26:31.561 66057e17.1 [unknown] 140368399876032 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (2314 Mbytes) is larger.Successfully started.步骤 8 验证参数设置是否成功 使用 gsql 客户端以管理员用户身份连接 postgres 数据库然后查看参数值最后退出数据库。 [ommnode0 ~]$ gsql -d postgres -p 15400 -r gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type help for help.openGauss# SHOW max_connections;max_connections -----------------6000 (1 row) 这里显示 max_connections 为 6000 说明前面参数的修改已经生效。 最大连接数设置实验结束。 6 例行表、索引的维护 6.1 实验介绍 为了保证数据库的有效运行数据库必须在插入 / 删除操作后基于客户场景定期做 VACUUM FULL 和 ANALYZE 更新统计信息以便获得更优的性能 VACUUM FULL 可回收已更新或已删除的数据所占据的磁盘空间同时将小数据文件合并 VACUUM 对每个表维护了一个可视化映射来跟踪包含对别的活动事务可见的数组的页。 一个普通的索引扫描首先通过可视化映射来获取对应的数组来检查是否对当前事务可见。 若无法获取再通过堆数组抓取的方式来检查。因此更新表的可视化映射可加速唯一索 引扫描 ANALYZE 可收集与数据库中表内容相关的统计信息。统计结果存储在系统表 PG_STATISTIC 中。查询优化器会使用这些统计数据生成最有效的执行计划。 数据库经过多次删除操作后索引页面上的索引键将被删除造成索引膨胀。例行重建索 引可有效的提高查询效率。 本实验主要是通过使用 VACUUM 、 VACUUM FULL FULL 来收缩表用 ANALYZE 来收集表的 统计信息以及对表上的索引进行重建。 6.2 场景设置及操作步骤 步骤 1 用 ROOT 用户登录装有 openGauss 数据库服务的操作系统然后用 su – omm 命令切换至 OMM 用户环境登录后信息如下。 [rootnode0 ~]# su - omm Last login: Thu Mar 28 22:03:30 CST 2024 on pts/0Welcome to 5.10.0-153.12.0.92.oe2203sp2.x86_64System information as of time: 2024年 03月 28日 星期四 22:33:00 CSTSystem load: 0.08 Processes: 198 Memory used: 37.1% Swap used: 9.4% Usage On: 25% IP address: 192.168.28.131 Users online: 2 To run a command as administrator(user root),use sudo command.步骤 2 启动服务器后然后使用 gsql 客户端以管理员用户身份连接 postgres 数据库假设端口号 为 15400 。 启动数据库服务。 [ommnode0 ~]$ gs_om -t start; Starting cluster.[SUCCESS] node0 2024-03-28 22:35:55.148 6605804b.1 [unknown] 140256478302144 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2024-03-28 22:35:55.148 6605804b.1 [unknown] 140256478302144 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2024-03-28 22:35:55.150 6605804b.1 [unknown] 140256478302144 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (2314 Mbytes) is larger.Successfully started.连接 postgres 数据库。 [ommnode0 ~]$ gsql -d postgres -p 15400 -r; gsql ((openGauss 5.0.0 build a07d57c3) compiled at 2023-03-29 03:37:13 commit 0 last mr ) Non-SSL connection (SSL connection is recommended when requiring high-security) Type help for help. 步骤 3 创建 student 表 openGauss# drop table student; DROP TABLE openGauss# CREATE TABLE student openGauss-# ( std_id INT NOT NULL, openGauss(# std_name VARCHAR(20) NOT NULL, openGauss(# std_sex VARCHAR(6), openGauss(# std_birth DATE, openGauss(# std_in DATE NOT NULL, openGauss(# std_address VARCHAR(100) openGauss(# ); 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 数据查询统计 openGauss# select count(*) from student;count -------50 (1 row)openGauss# 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 | 张六 | 男 | 1993-01-06 00:00:00 | 2011-09-01 00:00:00 | 江 省南京市雨花台区步骤 6 查看表信息 openGauss# \d studentTable public.studentColumn | Type | Modifiers --------------------------------------------------------std_id | integer | not nullstd_name | character varying(20) | not nullstd_sex | character varying(6) | std_birth | timestamp(0) without time zone | std_in | timestamp(0) without time zone | not nullstd_address | character varying(100) | 步骤 7 使用 VACUUM 命令进行磁盘空间回收 openGauss# vacuum student; VACUUM步骤 8 删除表中数据 openGauss# delete from student where std_id30; DELETE 20步骤 9 使用 VACUUM FULL 命令进行磁盘空间回收 openGauss# vacuum full student; VACUUM步骤 10 使用 ANALYZE 语句更新统计信息 openGauss# analyze student; ANALYZE步骤 11 使用 ANALYZE VERBOSE 语句更新统计信息并输出表的相关信息 openGauss# analyze verbose student; INFO: analyzing public.student(dn_6001 pid3999) 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 pid3999) ANALYZE步骤 12 执行 VACUUM ANALYZE 命令进行查询优化 openGauss# vacuum analyze student; VACUUM步骤 13 查看特定表的统计信息 openGauss# select relname,n_tup_ins,n_tup_upd,n_tup_del,last_analyze,vacuum_count from PG_STAT_ALL_TABLES where relnamestudent;relname | n_tup_ins | n_tup_upd | n_tup_del | last_analyze | vacuum_count ------------------------------------------------------------------------- -------------student | 0 | 0 | 0 | 2024-03-29 11:14:46.3843508 | 1 (1 row)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 列上创建一个索引如下 openGauss# create index inx_stu01 on student(std_name); CREATE INDEX方式 1 使用 REINDEX 语句重建索引具体如下 openGauss# reindex table student; REINDEX方式 2 先删除索引 DROP INDEX 再创建索引 CREATE INDEX 具体如下 openGauss# drop index inx_stu01; DROP INDEX openGauss# create index inx_stu01 on student(std_name); CREATE INDEX查看表结构信息具体如下 openGauss# \d student;Table public.studentColumn | Type | Modifiers --------------------------------------------------------std_id | integer | not nullstd_name | character varying(20) | not nullstd_sex | character varying(6) | std_birth | timestamp(0) without time zone | std_in | timestamp(0) without time zone | not nullstd_address | character varying(100) | Indexes:inx_stu01 btree (std_name) TABLESPACE pg_default 例行表、索引的维护实验结束。
http://www.zqtcl.cn/news/67276/

相关文章:

  • 网站地图制作怎么做?在线软件开发平台
  • 在网站中加入锚链接应该怎么做网站建设的主要工作
  • 如何做网站免费推广优秀网站模板下载
  • 旅游网站建设论文题目安阳市城乡建设规划局网站
  • 上海自建网站怎么查网站权重
  • 在线制作图片加字合成seo整站优化外包
  • DW做注册网站c语言自学免费网站
  • 北京网站建设一般多少钱长春建站优化
  • 政务信息网站建设工作方案动易内容管理系统
  • 海南省住房城乡建设厅网站做编程的网站有哪些内容
  • 做网站头片的高清图响应式网站和自适应网站的区别
  • 中学生网站源码广告设计专业大学排名
  • cms网站开发框架中英繁网站源码
  • html做的网站怎么弄个人网站 免费
  • 仙居做网站的浙江省的网站建设公司有哪些
  • 厦门邮件网站wordpress 底部悬浮
  • 微信网站怎么写宁波seo营销平台
  • 苏州网站制作设计u盘启动盘制作工具
  • 软件推广怎么做seo优化排名易下拉用法
  • 怎么样做网站爬虫淄博 建网站
  • 网站建设综合做网站吧
  • 网站建设销售职责公司名字大全免费查询
  • 维护网站都干什么wordpress安装详细教程
  • 备案 网站内容公司如何建设网站
  • 网站建设公司怎么推广网络建设费是什么费用
  • 黄岛网站建设公司首选phpcms仿站教程
  • 专业性行业网站有哪些网站空间做邮箱
  • 学校网站制作网站死链接
  • 什么是建站wordpress页头导航类目没有链接
  • 山西网站建设营销什么价格网站源码怎样弄成网站