今天开始学习墨天轮每日一练:openGauss 3.0.0数据库在线实训课程,学习新的知识,让我们再次出发!
学习目标
学习从操作系统层面和使用 openGauss 工具查看数据库的状态、版本和数据文件目录。
课程学习
gs_ctl 是 openGauss 提供的数据库服务控制工具,可以用来启停数据库服务和查询数据库状态。主要供 openGauss 管理模块调用。 gs_ctl 工具由操作系统用户 omm 执行。可以执行:
启动、停止、重启 openGauss 节点。
在不停止数据库的情况下,重新加载配置文件(postgresql.conf,pg_hba.conf)。
主备切换、主备状态查询、重建和重建状态查询。
更加详细的参数可参考官方文档:工具参考–》系统内部使用的工具
1.操作系统层面查看数据库进程和线程。如果数据库启动,则有相应的进程和线程。
ps -ef|grep gauss
ps -Tp 1686
[omm@localhost ~]$ ps -ef|grep gauss
omm 1686 1 11 00:40 ? 00:00:15 /opt/openGauss/bin/gaussdb -D /opt/openGauss/data/single_node
omm 1947 1652 0 00:43 pts/0 00:00:00 grep --color=auto gauss
[omm@localhost ~]$ ps -Tp 1686
PID SPID TTY TIME CMD
1686 1686 ? 00:00:02 gaussdb
1686 1687 ? 00:00:00 jemalloc_bg_thd
1686 1692 ? 00:00:00 gaussdb
1686 1693 ? 00:00:00 syslogger
1686 1694 ? 00:00:00 alarm
1686 1695 ? 00:00:00 jemalloc_bg_thd
1686 1696 ? 00:00:00 reaper
1686 1697 ? 00:00:00 jemalloc_bg_thd
1686 1698 ? 00:00:00 jemalloc_bg_thd
1686 1722 ? 00:00:00 gaussdb
1686 1723 ? 00:00:00 gaussdb
1686 1724 ? 00:00:00 gaussdb
1686 1726 ? 00:00:00 checkpointer
1686 1727 ? 00:00:00 Spbgwriter
1686 1728 ? 00:00:00 pagewriter
1686 1729 ? 00:00:01 pagewriter
1686 1730 ? 00:00:00 pagewriter
1686 1731 ? 00:00:00 pagewriter
1686 1732 ? 00:00:00 pagewriter
1686 1733 ? 00:00:00 WALwriter
1686 1734 ? 00:00:00 WALwriteraux
1686 1735 ? 00:00:00 AVClauncher
1686 1736 ? 00:00:00 Jobscheduler
1686 1737 ? 00:00:00 asyncundolaunch
1686 1738 ? 00:00:00 globalstats
1686 1739 ? 00:00:00 applylauncher
1686 1740 ? 00:00:00 statscollector
1686 1741 ? 00:00:00 txnsnapcapturer
1686 1742 ? 00:00:00 CfsShrinker
1686 1743 ? 00:00:01 percentworker
1686 1744 ? 00:00:00 ashworker
1686 1745 ? 00:00:00 TrackStmtWorker
1686 1746 ? 00:00:00 auditor
1686 1747 ? 00:00:00 2pccleaner
1686 1748 ? 00:00:00 faultmonitor
1686 1749 ? 00:00:00 WLMworker
1686 1750 ? 00:00:00 WLMmonitor
1686 1751 ? 00:00:00 WLMarbiter
1686 1752 ? 00:00:00 undorecycler
2.使用 gs_ctl 工具查看数据库状态,如果数据库启动,显示 gs_ctl: server is running (PID: 1686)
[omm@localhost ~]$ gs_ctl status
[2024-10-04 01:03:30.490][3697][][gs_ctl]: gs_ctl status,datadir is /opt/openGauss/data/single_node
gs_ctl: server is running (PID: 1686)
/opt/openGauss/bin/gaussdb "-D" "/opt/openGauss/data/single_node"
3.使用 gs_ctl 查看数据文件的目录
官方文档参数释义 notify:启动后再指定主备机。
[omm@localhost ~]$ gs_ctl notify
[2024-10-04 01:05:11.285][3844][][gs_ctl]: gs_ctl notify ,datadir is /opt/openGauss/data/single_node
[2024-10-04 01:05:11.285][3844][][gs_ctl]: the parameter of notify must be specified
4.查看 omm 用户的环境变量
[omm@localhost ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export GAUSSHOME=/opt/openGauss
export PATH=$GAUSSHOME/bin:$PATH
export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
export PGDATA=/opt/openGauss/data/single_node
5.从环境变量查看数据文件的目录
[omm@localhost ~]$ grep -i PGDATA ~/.bash_profile
export PGDATA=/opt/openGauss/data/single_node
[omm@localhost ~]$
- 在 gsql 中查看数据文件的目录、数据库版本
gsql -d postgres -p 5432
CREATE DATABASE omm WITH ENCODING 'utf8';
gsql -r
show data_directory ;
select version();
课程作业
1.从操作系统层面查看数据库进程和线程,判断数据库是否启动。
使用 ps -ef | grep gauss 查看进程是否存在,使用 ps -Tp 1686 查看进程 PID 为 1686 时的线程有哪些。
2.使用 gs_ctl 工具查看数据库状态,判断数据库是否启动。
使用 gs_ctl --help 查看帮助命令,gs_ctl status 查看数据库状态是否为 running 。
[omm@localhost ~]$ gs_ctl status
[2024-10-04 02:23:33.524][10693][][gs_ctl]: gs_ctl status,datadir is /opt/openGauss/data/single_node
gs_ctl: server is running (PID: 1686)
/opt/openGauss/bin/gaussdb "-D" "/opt/openGauss/data/single_node"
3.使用 gs_ctl 查看数据文件的目录
使用 gs_ctl notify 查看数据文件存放目录。
[omm@localhost ~]$ gs_ctl notify
[2024-10-04 02:25:34.283][10907][][gs_ctl]: gs_ctl notify ,datadir is /opt/openGauss/data/single_node
[2024-10-04 02:25:34.283][10907][][gs_ctl]: the parameter of notify must be specified
4.从环境变量查看数据文件的目录
环境变量中参数 PGDATA 指定了数据文件存放路径。
[omm@localhost ~]$ grep -i PGDATA ~/.bash_profile
export PGDATA=/opt/openGauss/data/single_node
5.在 gsql 中查看数据文件目录、数据库版本
通过 gsql -r 连接到数据库,然后参数 data_directory 指定了数据文件的存放路径,通过 version() 函数来查看 openGauss 的数据库版本为 5.0.3。
[omm@localhost ~]$ gsql -r
gsql ((openGauss 5.0.3 build 89d144c2) compiled at 2024-07-31 20:59:31 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
omm=# show data_directory;
data_directory
---------------------------------
/opt/openGauss/data/single_node
(1 row)
omm=# select version();
version
------------------------------------------------------------------------------------------------------------------------------------
------------------
(openGauss 5.0.3 build 89d144c2) compiled at 2024-07-31 20:59:31 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (G
CC) 7.3.0, 64-bit
(1 row)
最后,\q 或者 Ctrl + d 退出数据库。