学习目标:
opengauss数据库例行维护
1.使用操作系统命令和数据库工具检查实例状态
root@modb:~# su - omm
omm@modb:~$ ps -ef|grep gaussdb
omm 1 0 0 09:57 ? 00:00:01 gaussdb
omm 400 396 0 10:00 pts/0 00:00:00 grep gaussdb
omm@modb:~$ ps -Tp 1
PID SPID TTY TIME CMD
1 1 ? 00:00:00 gaussdb
1 293 ? 00:00:00 jemalloc_bg_thd
1 299 ? 00:00:00 gaussdb
1 300 ? 00:00:00 syslogger
1 301 ? 00:00:00 jemalloc_bg_thd
1 302 ? 00:00:00 alarm
1 303 ? 00:00:00 reaper
1 304 ? 00:00:00 jemalloc_bg_thd
1 350 ? 00:00:00 Spbgwriter
1 305 ? 00:00:00 jemalloc_bg_thd
1 349 ? 00:00:00 checkpointer
1 353 ? 00:00:00 pagewriter
1 354 ? 00:00:00 pagewriter
1 351 ? 00:00:00 pagewriter
1 352 ? 00:00:00 pagewriter
1 355 ? 00:00:00 pagewriter
1 356 ? 00:00:00 WALwriter
1 358 ? 00:00:00 AVClauncher
1 359 ? 00:00:00 Jobscheduler
1 357 ? 00:00:00 WALwriteraux
1 360 ? 00:00:00 asyncundolaunch
1 361 ? 00:00:00 globalstats
1 362 ? 00:00:00 applylauncher
1 363 ? 00:00:00 statscollector
1 364 ? 00:00:00 percentworker
1 365 ? 00:00:00 ashworker
1 366 ? 00:00:00 TrackStmtWorker
1 367 ? 00:00:00 auditor
1 368 ? 00:00:00 2pccleaner
1 369 ? 00:00:00 faultmonitor
1 370 ? 00:00:00 WLMworker
1 371 ? 00:00:00 WLMmonitor
1 372 ? 00:00:00 WLMarbiter
1 373 ? 00:00:00 undorecycler
omm@modb:~$ gs_ctl status
[2022-12-14 10:00:51.460][402][][gs_ctl]: gs_ctl status,datadir is /var/lib/opengauss/data
gs_ctl: server is running (PID: 1)
/usr/local/opengauss/bin/gaussdb
omm@modb:~$ gsql -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=#
omm=# show data_directory;
data_directory
-------------------------
/var/lib/opengauss/data
(1 row)2:检查锁信息
omm=# omm=# SELECT * FROM pg_locks;
ERROR: syntax error at or near "omm"
LINE 1: omm=# SELECT * FROM pg_locks;
^
omm=# locktype | database | relation | page | tuple | bucket | virtualxid | transactionid | classid
omm-# | objid | objsubid | virtualtransaction | pid | sessionid | mode | g
omm-# ranted | fastpath | locktag | global_sessionid
omm-# ------------+----------+----------+------+-------+--------+------------+---------------+---------
omm-# +-------+----------+--------------------+-----------------+-----------------+-----------------+--
omm-# | t | b:1e:0:0:0:7 | 0:0#0
omm-# virtualxid | | | | | | 9/59 | |
omm-# | | | 9/59 | 281471024856304 | 281471024856304 | ExclusiveLock | t
omm-# -------+----------+-------------------+------------------
omm-# relation | 16384 | 12010 | | | | | |
omm-# | | | 11/30 | 281470852431088 | 281470852431088 | AccessShareLock | t
omm-# | t | 4000:2eea:0:0:0:0 | 0:0#0
omm-# virtualxid | | | | | | 11/30 | |
omm-# | | | 11/30 | 281470852431088 | 281470852431088 | ExclusiveLock | t
omm-# | t | 9:3b:0:0:0:7 | 0:0#0
(3 rows)omm-#3查看数据库版本、日志信息
omm=# SELECT version();
version
-------------------------------------------------------------------------------------------------
------------------------------------------------------
(openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr on aarch64-u
nknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)omm=# \! ls /var/lib/opengauss/data/pg_log
postgresql-2022-12-14_095741.log postgresql-2022-12-14_095752.log4检查应用连接数、查看现有最大连接数
omm=# SHOW max_connections;
max_connections
-----------------
200
(1 row)omm=# SELECT count(*) FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;
count
-------
21
(1 row)5、对表进行VACUUM、VACUUM FULL和ANALYZE操作
omm=# CREATE TABLE customer_t
omm-# ( c_customer_sk integer,
omm(# omm(# c_customer_id char(5),
c_first_name char(6),
c_last_name char(8)
omm(# omm(# ) ;
ERROR: relation "customer_t" already exists in schema "public"
DETAIL: creating new table with existing name in the same schema
omm=# INSERT INTO customer_t (c_customer_sk, c_customer_id, c_first_name,c_last_name) VALUES
omm-# (6885, 1, 'Joes', 'Hunter'),
omm-# (4321, 2, 'Lily','Carter'),
omm-# (9527, 3, 'James', 'Cook'),
omm-# (9500, 4, 'Lucy', 'Baker');
INSERT 0 4
omm=# select count(*) from customer_t;
count
-------
8
(1 row)
omm=#
omm=#
omm=# VACUUM customer_t;
VACUUM
omm=#
omm=# VACUUM FULL customer_t;
CREATE TABLESPACE EXAMPLE RELATIVE LOCATION 'tablespace1/tablespace_1';
CREATE schema HR;
CREATE TABLE HR.areaS( area_ID NUMBER, area_NAME VARCHAR2(25) )tablespace EXAMPLE;
\d HR.areaS
CREATE INDEX areaS_idx ON HR.areaS (area_id);
REINDEX table HR.areaS;
VACUUM
omm=#
omm=# ANALYZE customer_t;
ANALYZE
omm=#
omm=# ANALYZE VERBOSE customer_t;
INFO: analyzing "public.customer_t"(gaussdb pid=1)
INFO: ANALYZE INFO : "customer_t": scanned 1 of 1 pages, containing 8 live rows and 0 dead rows; 8 rows in sample, 8 estimated total rows(gaussdb pid=1)
ANALYZE
omm=#
omm=# VACUUM ANALYZE customer_t;
VACUUM
omm=# 6、建表、索引,进行重建索引操作
omm=# CREATE TABLESPACE EXAMPLE RELATIVE LOCATION 'tablespace1/tablespace_1';
CREATE schema HR;
CREATE TABLESPACE
omm=# CREATE SCHEMA
omm=#
omm=# CREATE TABLE HR.areaS( area_ID NUMBER, area_NAME VARCHAR2(25) )tablespace EXAMPLE;
CREATE TABLE
omm=# \d HR.areaS
Table "hr.areas"
Column | Type | Modifiers
-----------+-----------------------+-----------
area_id | numeric |
area_name | character varying(25) |
Tablespace: "example"
omm=# CREATE INDEX areaS_idx ON HR.areaS (area_id);
CREATE INDEX
omm=#
omm=#
REINDEX table HR.areaS;
omm=# REINDEX「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




