1、使用操作系统命令和数据库工具检查实例状态
操作系统命令
omm@modb:~$ ps -ef|grep gaussdb
omm 1 0 0 10:03 ? 00:00:00 gaussdb
omm 389 385 0 10:05 pts/0 00:00:00 grep gaussdb
omm@modb:~$ ps -Tp 1
PID SPID TTY TIME CMD
1 1 ? 00:00:00 gaussdb
1 287 ? 00:00:00 jemalloc_bg_thd
1 293 ? 00:00:00 gaussdb
1 294 ? 00:00:00 syslogger
1 295 ? 00:00:00 jemalloc_bg_thd
1 296 ? 00:00:00 alarm
1 297 ? 00:00:00 reaper
1 298 ? 00:00:00 jemalloc_bg_thd
1 299 ? 00:00:00 jemalloc_bg_thd
1 343 ? 00:00:00 checkpointer
1 346 ? 00:00:00 pagewriter
1 347 ? 00:00:00 pagewriter
1 348 ? 00:00:00 pagewriter
1 344 ? 00:00:00 Spbgwriter
1 345 ? 00:00:00 pagewriter
1 349 ? 00:00:00 pagewriter
1 350 ? 00:00:00 WALwriter
1 352 ? 00:00:00 AVClauncher
1 351 ? 00:00:00 WALwriteraux
1 353 ? 00:00:00 Jobscheduler
1 354 ? 00:00:00 asyncundolaunch
1 355 ? 00:00:00 globalstats
1 356 ? 00:00:00 applylauncher
1 357 ? 00:00:00 statscollector
1 359 ? 00:00:00 ashworker
1 360 ? 00:00:00 TrackStmtWorker
1 358 ? 00:00:00 percentworker
1 361 ? 00:00:00 auditor
1 362 ? 00:00:00 2pccleaner
1 363 ? 00:00:00 faultmonitor
1 364 ? 00:00:00 WLMworker
1 365 ? 00:00:00 WLMmonitor
1 366 ? 00:00:00 WLMarbiter
1 367 ? 00:00:00 undorecycler
数据库工具
[2022-12-14 10:33:22.625][19500][][gs_ctl]: gs_ctl status,datadir is /opt/huawei/install/data/db1
gs_ctl: server is running (PID: 29053)
/opt/huawei/install/app/bin/gaussdb "-D" "/opt/huawei/install/data/db1" "-M" "primary"
[omm@modb ~]$ gs_om -t status --detail
[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state
-----------------------------------------------------------------------------------------------
1 ogauss1 192.168.20.251 15400 6001 /opt/huawei/install/data/db1 P Primary Normal
2 ogauss2 192.168.20.252 15400 6002 /opt/huawei/install/data/db1 S Standby Normal
2、检查锁信息
Expanded display is on.
omm@modb:/opt/huawei/tmp [postgres]=# SELECT * FROM pg_locks;
-[ RECORD 1 ]------+------------------
locktype | relation
database | 15484
relation | 12010
page |
tuple |
bucket |
virtualxid |
transactionid |
classid |
objid |
objsubid |
virtualtransaction | 9/301193
pid | 140703053117184
sessionid | 140703053117184
mode | AccessShareLock
granted | t
fastpath | t
locktag | 3c7c:2eea:0:0:0:0
global_sessionid | 0:0#0
-[ RECORD 2 ]------+------------------
locktype | virtualxid
database |
relation |
page |
tuple |
bucket |
virtualxid | 9/301193
transactionid |
classid |
objid |
objsubid |
virtualtransaction | 9/301193
pid | 140703053117184
sessionid | 140703053117184
mode | ExclusiveLock
granted | t
fastpath | t
locktag | 9:49889:0:0:0:7
global_sessionid | 0:0#0
--查询等待锁的线程状态信息
omm@modb:/opt/huawei/tmp [postgres]=# SELECT * FROM pg_thread_wait_status WHERE wait_status = 'acquire lock';
(No rows)
omm@modb:/opt/huawei/tmp [postgres]=# SELECT * FROM pg_thread_wait_status WHERE wait_status = 'AccessShareLock';
(No rows)
omm@modb:/opt/huawei/tmp [postgres]=# SELECT * FROM pg_thread_wait_status WHERE wait_status = 'ExclusiveLock';
(No rows)
3、查看数据库版本、日志信息
-[ RECORD 1 ]-------------------------------------------------------------------------------------------------------------------------------------------------
version | (openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
--在gsql中
omm@modb:/opt/huawei/tmp [postgres]=#\! ls /opt/huawei/log/omm/pg_log/
dn_6001
----数据库日志位置
[omm@modb ~]$ ls /opt/huawei/log/omm/pg_log/
dn_6001
4、检查应用连接数、查看现有最大连接数
count
-------
20
(1 row)
omm@modb:/opt/huawei/tmp [postgres]=#SHOW max_connections;
max_connections
-----------------
5000
(1 row)
5、对表进行VACUUM、VACUUM FULL和ANALYZE操作
CREATE TABLESPACE
omm@modb:/opt/huawei/tmp [postgres]=#CREATE DATABASE musicdb21 WITH TABLESPACE = day21;
CREATE DATABASE
omm@modb:/opt/huawei/tmp [postgres]=#CREATE USER user21 IDENTIFIED BY 'zs@123456';
CREATE ROLE
omm@modb:/opt/huawei/tmp [postgres]=#ALTER USER user21 SYSADMIN;
ALTER ROLE
omm@modb:/opt/huawei/tmp [postgres]=#CREATE TABLE tab_day21
openGauss-# ( c_customer_sk integer,
openGauss(# c_customer_id char(5),
openGauss(# c_first_name char(6),
openGauss(# c_last_name char(8)
openGauss(# ) ;^C
omm@modb:/opt/huawei/tmp [postgres]=#
omm@modb:/opt/huawei/tmp [postgres]=#
omm@modb:/opt/huawei/tmp [postgres]=#\c musicdb21 user21
Password for user user21:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "musicdb21" as user "user21".
user21@local:/opt/huawei/tmp [musicdb21]=>CREATE TABLE tab_day21
musicdb21-> ( c_customer_sk integer,
musicdb21(> c_customer_id char(5),
musicdb21(> c_first_name char(6),
musicdb21(> c_last_name char(8)
musicdb21(> ) ;
CREATE TABLE
omm@modb:/opt/huawei/tmp [musicdb21]=>INSERT INTO tab_day21 (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES
musicdb21-> (6885, 1, 'Joes', 'Hunter'),
musicdb21-> (4321, 2, 'Lily','Carter'),
musicdb21-> (9527, 3, 'James', 'Cook'),
musicdb21-> (9500, 4, 'Lucy', 'Baker');
INSERT 0 4
omm@modb:/opt/huawei/tmp [musicdb21]=>select count(*) from tab_day21;
count
-------
4
(1 row)
omm@modb:/opt/huawei/tmp [musicdb21]=>
--使用VACUUM或VACUUM FULL命令,进行磁盘空间回收。
--使用VACUUM
omm@modb:/opt/huawei/tmp [musicdb21]=>VACUUM tab_day21;
VACUUM
--使用VACUUM full
--需要向正在执行的表增加排他锁,且需要停止其他所有数据库操作。
omm@modb:/opt/huawei/tmp [musicdb21]=>VACUUM FULL tab_day21;
VACUUM
--使用ANALYZE语句更新统计信息。
omm@modb:/opt/huawei/tmp [musicdb21]=>ANALYZE tab_day21;
ANALYZE
--使用ANALYZE VERBOSE语句更新统计信息,并输出表的相关信息。
omm@modb:/opt/huawei/tmp [musicdb21]=>ANALYZE VERBOSE tab_day21;
INFO: analyzing "public.tab_day21"(dn_6001_6002 pid=29053)
INFO: ANALYZE INFO : "tab_day21": scanned 1 of 1 pages, containing 4 live rows and 0 dead rows; 4 rows in sample, 4 estimated total rows(dn_6001_6002 pid=29053)
ANALYZE
--也可以同时执行VACUUM ANALYZE命令进行查询优化。
omm@modb:/opt/huawei/tmp [musicdb21]=>VACUUM ANALYZE tab_day21;
VACUUM
6、建表、索引,进行重建索引操作
CREATE INDEX
user21@local:/opt/huawei/tmp [musicdb21]=>\di+
List of relations
Schema | Name | Type | Owner | Table | Size | Storage | Description
--------+------------+-------+--------+-----------+-------+---------+-------------
public | idx_day21_ | index | user21 | tab_day21 | 16 kB | |
(1 row)
omm@modb:/opt/huawei/tmp [musicdb21]=>REINDEX table tab_day21;
REINDEX
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




