签到成功

知道了

CNDBA社区CNDBA社区

openGauss 数据库的启动和关闭

2023-03-09 21:20 4155 0 原创 openGauss
作者: dave

1 理论说明

在前文我们了解了单机版OpenGauss的安装,如下:

Linux 7.6 平台 openGauss 3.1.1 单机版 安装手册
https://www.cndba.cn/dave/article/116448http://www.cndba.cn/dave/article/116477

本文我们了解一下OpenGauss的启停操作。http://www.cndba.cn/dave/article/116477

OpenGauss的启停有个工具:gs_om 和 gs_ctl。

  1. gs_om 是服务端工具,该工具提供对openGauss进行维护,包括启动、停止、查询openGauss状态、查询静态配置、生成静态配置文件、查询openGauss状态详细信息、生成动态配置文件、SSL证书替换、显示帮助信息和显示版本号信息等功能。同时注意改命令需要使用omm用户来执行。
  2. gs_ctl 是系统内部使用的工具,通过gs_ctl是也可以用来启停数据库服务和查询数据库状态。主要供openGauss管理模块调用。gs_ctl工具也要由omm用户执行。
    该工具可以:
    启动、停止、重启openGauss节点。
    在不停止数据库的情况下,重新加载配置文件(postgresql.conf,pg_hba.conf)。
    主备切换、主备状态查询、重建和重建状态查询。

其他工具参考之前的博客:

http://www.cndba.cn/dave/article/116477
http://www.cndba.cn/dave/article/116477

openGauss 数据库 工具 清单
https://www.cndba.cn/dave/article/116476http://www.cndba.cn/dave/article/116477http://www.cndba.cn/dave/article/116477

2 操作示例

2.1 查看帮助

[dave@www.cndba.cn ~]# ps -ef|grep openGauss
root     19367 17786  0 20:40 pts/7    00:00:00 grep --color=auto openGauss
omm      43976     1  7 Feb19 ?        1-07:46:39 /data/openGauss/install/app/bin/gaussdb -D /data/openGauss/install/data/dn
[dave@www.cndba.cn ~]# su - omm
Last login: Sun Feb 19 16:36:54 CST 2023 on pts/9
[dave@www.cndba.cn ~]$ gs_om -V
gs_om (openGauss OM 3.0.3 build 43c77d67) compiled at 2023-01-10 22:52:03 commit 0 last mr
[dave@www.cndba.cn ~]$ gs_om -?

gs_om is a utility to manage a cluster.

Usage:
  gs_om -? | --help
  gs_om -V | --version
  OLAP scene:
    gs_om -t start [-h HOSTNAME] [-D dataDir] [--time-out=SECS]
                   [--security-mode=MODE] [--cluster-number=None] [-l LOGFILE]
    gs_om -t stop [-h HOSTNAME] [-D dataDir]  [--time-out=SECS] [-m MODE]
                  [-l LOGFILE]
    gs_om -t restart [-h HOSTNAME] [-D dataDir] [--time-out=SECS]
                   [--security-mode=MODE] [-l LOGFILE] [-m MODE]
    gs_om -t status [-h HOSTNAME] [-o OUTPUT] [--detail] [--all] [--az=AZ] [-l LOGFILE]
                    [--time-out=SECS]
    gs_om -t generateconf -X XMLFILE [--distribute] [-l LOGFILE]
    gs_om -t generateconf --old-values=old --new-values=new [--distribute] [-l LOGFILE]
    gs_om -t cert [--cert-file=CERTFILE | --rollback] [-L] [-l LOGFILE]
    gs_om -t kerberos -m [install|uninstall] -U USER [-l LOGFILE]
                         [--krb-server|--krb-client]
    gs_om -t view [-o OUTPUT]
    gs_om -t query [-o OUTPUT] [--time-out=SECS]
    gs_om -t refreshconf

General options:
  -t                              Type of the OM command.
  -l                              Path of log file.
  -?, --help                      Show help information for this utility,
  and exit the command line mode.
  -V, --version                   Show version information.

Options for start
  -h                              Name of the host to be started.
  -D                              Path of dn
      --time-out=SECS              Maximum waiting time when start the
                                   cluster or node.
      --security-mode=MODE        database start with security mode: on or off
                                        on: start with security mode
                                        off: start without security mode
      --cluster-number            database start with kernel version corresponding
                                  to version.cfg

Options for stop
  -h                              Name of the host to be shut down.
  -m, --mode=MODE                 Shutdown mode. It can be f (fast),
                                  or i (immediate).
  -D                              Path of dn
      --time-out=SECS             Maximum waiting time when start the cluster
                                 or node.

Options for restart
  -h                              Name of the host to be started.
  -m, --mode=MODE                 Shutdown mode. It can be f (fast),
                                  or i (immediate).
  -D                              Path of dn
      --time-out=SECS             Maximum waiting time when start the
                                  cluster or node.
      --security-mode=MODE        database start with security mode: on or off
                                        on: start with security mode
                                        off: start without security mode

Options for status
  -h                              Name of the host whose status is to be
                                  queried.
  --az=AZ                         Name of the single az whose status is to
                                  be queried.
  -o                              Save the result to the specified file.
      --detail                    Show detailed status information.
      --all                       Show all database node status information.
      --time-out=SECS             Maximum waiting time when query cluster status.

Options for generating configuration files
  -X                              Path of the XML configuration file.
  --old-values                    IP or hostname or port like "host1,ip1,port1"
  --new-values                    IP or hostname or port like "host1,ip1,port1"
      --distribute                Distribute the static configuration file
                                  to installation directory of cluster nodes.

Options for cert
      --cert-file                 Path of cert file.
      --rollback                  Perform rollback SSL cert files.
      -L                          local mode.

Options for kerberos
  -m                              Kerberos management mode. It can be
                                  install or uninstall.
  -U                              %s cluster user.
Install options:
  --krb-server                    Execute install for server. This parameter
  only work for install
  --krb-client                    Execute install for client. This parameter
  only work for install


[dave@www.cndba.cn ~]$ 

[dave@www.cndba.cn ~]$ gs_ctl --help
gs_ctl is a utility to initialize, start, stop, or control a openGauss server.

Usage:
  gs_ctl init[db]               [-D DATADIR] [-s] [-o "OPTIONS"]
  gs_ctl start   [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"] [-M SERVERMODE]
  gs_ctl restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
                 [-o "OPTIONS"]
  gs_ctl build   [-D DATADIR] [-b MODE] [-r SECS] [-C CONNECTOR] [-q] [-M SERVERMODE]
  gs_ctl stop    [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
  gs_ctl reload  [-D DATADIR] [-s]
  gs_ctl status  [-D DATADIR]
  gs_ctl finishredo [-D DATADIR] [-s]
  gs_ctl failover               [-W] [-t SECS] [-D DATADIR] [-U USERNAME] [-P PASSWORD] [-T TERM]
  gs_ctl switchover             [-W] [-D DATADIR] [-m SWITCHOVER-MODE] [-U USERNAME] [-P PASSWORD] [-f]
  gs_ctl query   [-D DATADIR] [-U USERNAME] [-P PASSWORD] [-L lsn]
  gs_ctl notify   -M SERVERMODE [-D DATADIR] [-U USERNAME] [-P PASSWORD]
  gs_ctl kill    SIGNALNAME PID
  gs_ctl querybuild   [-D DATADIR]
  gs_ctl copy   [-D DATADIR] [-Q COPYMODE]
  gs_ctl stack [-D DATADIR] [-I lwtid]
  gs_ctl member         [-O OPERATION] [-u DCF-NODE-ID] [-i DCF-NODE-IP] [-e DCF-NODE-PORT] [-D PRIMARY-DATADIR]
  gs_ctl changerole     [-R DCF-ROLE] [-D DATADIR] [-t SEC]
  gs_ctl setrunmode     [-x XMODE] [-v VOTE-NUM] [-D PRIMARY-DATADIR]

Common options:
  -b,  --mode=MODE       the mode of building the datanode or coordinator.MODE can be "full", "incremental", "auto", "standby_full", "copy_secure_files", "copy_upgrade_file", "cross_cluster_full", "cross_cluster_incremental", "cross_cluster_standby_full"
  -D, --pgdata=DATADIR   location of the database storage area
  -s, --silent           only print errors, no informational messages
  -t, --timeout=SECS     seconds to wait when using -w option
  -V, --version          output version information, then exit
  -w                     wait until operation completes
  -W                     do not wait until operation completes
  -M                     the database start as the appointed  mode
  -T                     Failover requires a term
  -q                     do not start automatically after build finishing, needed start by caller
  -d                     more debug info will be print
  -L                     query lsn:XX/XX validity and show the max_lsn
  -P PASSWORD            password of account to connect local server
  -U USERNAME            user name of account to connect local server
  -Z NODE-TYPE           can be "single_node"
  -?, -h, --help             show this help, then exit
(The default is to wait for shutdown, start and restart.)

If the -D option is omitted, the environment variable PGDATA is used.

Options for start or restart:
  -c, --core-files       allow openGauss to produce core files
  -l, --log=FILENAME     write (or append) server log to FILENAME
  -o OPTIONS             command line options to pass to openGauss
                         (openGauss server executable) or gs_initdb
  -p PATH-TO-POSTGRES    normally not necessary

Options for stop or restart:
  -m, --mode=MODE        MODE can be "fast" or "immediate"

Options for xlog copy:
  -Q, --mode=MODE        MODE can be "copy_from_local", "force_copy_from_local", "copy_from_share"

Options for DCF:
  -O, --operation=OPERATION          Operation of adding or removing or change a DN configuration.
  -u, --nodeid=DCF-NODE-ID           It is required for member command.
  -i, --ip=DCF-NODE-IP               It is required when OPERATION of member command is "add".
  -e, --port=DCF-NODE-PORT           It is required when OPERATION of member command is "add".
  -R, --role=DCF-NODE-ROLE           The option is "follower" or "passive".
  -v, --votenum=VOTE-NUM             It is required when XMODE is "minority".
  -x, --xmode=XMODE                  The option can be "minority" or "normal" mode in DCF.
  -G,                                The option is a int type to set group number in DCF.
  --priority,                        The option is a int type to set priority number in DCF.

OPERATION are:
  add            add a member to DCF configuration.
  remove         remove a member from DCF configuration.
  change         change DCF node configuration.

XMODE are:
  minority       the leader in DCF can reach consensus when getting less than half nodes' response.
  normal         the leader in DCF can reach consensus when getting more than half nodes' response.

DCF-NODE-ROLE are:
  follower       follower role in DCF
  passive        passive role in DCF

Options for stack:
  -I lwtid    light weight thread id. get stack of specific thread according to it's lwtid

Shutdown modes are:
  fast        quit directly, with proper shutdown
  immediate   quit without complete shutdown; will lead to recovery on restart

Switchover modes are:
  -f          quit directly, with proper shutdown and do not perform checkpoint
  fast        demote primary directly, with proper shutdown

SERVERMODE are:
  primary         database system run as a primary server, send xlog to standby server
  standby         database system run as a standby server, receive xlog from primary server
  cascade_standby database system run as a cascade standby server, receive xlog from standby server
  pending         database system run as a pending server, wait for promoting to primary or demoting to standby
                               Only used in start command

Allowed signal names for kill:
  ABRT HUP INT QUIT TERM USR1 USR2

Build connection option:
  -r, --recvtimeout=INTERVAL    time that receiver waits for communication from server (in seconds)
  -C, connector    CN/DN connect to specified CN/DN for build

Report bugs to openGauss community by raising an issue.
[dave@www.cndba.cn ~]$

2.2 查看状态

[dave@www.cndba.cn ~]$ gs_om -t status
Password: 
-----------------------------------------------------------------------

cluster_name    : dbCluster
cluster_state   : Normal
redistributing  : No

-----------------------------------------------------------------------
[dave@www.cndba.cn ~]$ gs_om -t view
NodeHeader:
version:301
time:1676795851
nodeCount:1
node:1
============================================================
azName:AZ1
azPriority:1
node :1
nodeName:hf-172-31-101-18
ssh channel :
sshChannel 1:172.31.101.18
datanodeCount :1
datanodeInstanceType :primary
datanode 1:
datanodeLocalDataPath :/data/openGauss/install/data/dn
datanodeXlogPath :
datanodeListenIP 1:172.31.101.18
datanodePort :15400
datanodeLocalHAIP 1:172.31.101.18
datanodeLocalHAPort :15401
dn_replication_num: 1
============================================================
[dave@www.cndba.cn ~]$ ps -ef|grep openGauss
omm      25729 19387  0 20:51 pts/7    00:00:00 grep --color=auto openGauss
omm      43976     1  7 Feb19 ?        1-07:47:31 /data/openGauss/install/app/bin/gaussdb -D /data/openGauss/install/data/dn
[dave@www.cndba.cn ~]$ gs_om -t query
Password: 
[   Cluster State   ]

cluster_state   : Normal
redistributing  : No
current_az      : AZ_ALL

[  Datanode State   ]

    node            node_ip         port      instance     state
--------------------------------------------------------------------------------
1  hf-172-31-101-18 172.31.101.18   15400      6001       P Primary Normal
[dave@www.cndba.cn ~]$

2.3 启停实例

2.3.1 gs_ctl 命令

[dave@www.cndba.cn ~]$ ps -ef|grep openGauss
omm      31231 19387  0 21:04 pts/7    00:00:00 grep --color=auto openGauss
omm      43976     1  7 Feb19 ?        1-07:48:25 /data/openGauss/install/app/bin/gaussdb -D /data/openGauss/install/data/dn

[dave@www.cndba.cn ~]$ gs_ctl stop -D /data/openGauss/install/data/dn

[dave@www.cndba.cn ~]$ gs_ctl start -D /data/openGauss/install/data/dn

[dave@www.cndba.cn ~]$ gs_ctl restart -D /data/openGauss/install/data/dn

[dave@www.cndba.cn ~]$ gs_ctl status -D /data/openGauss/install/data/dn
[2023-03-09 21:08:48.214][33319][][gs_ctl]: gs_ctl status,datadir is /data/openGauss/install/data/dn 
gs_ctl: server is running (PID: 31773)
/data/openGauss/install/app/bin/gaussdb "-D" "/data/openGauss/install/data/dn"
[dave@www.cndba.cn ~]$

2.3.2 gs_om 命令

[dave@www.cndba.cn ~]$ gs_om -t stop -D /data/openGauss/install/data/dn
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
[dave@www.cndba.cn ~]$ gs_om -t start -D /data/openGauss/install/data/dn
Starting cluster.
=========================================
[SUCCESS] hf-172-31-101-18
2023-03-09 21:10:01.833 6409daa9.1 [unknown] 140487301625536 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-03-09 21:10:01.833 6409daa9.1 [unknown] 140487301625536 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-03-09 21:10:01.834 6409daa9.1 [unknown] 140487301625536 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  No explicit IP is configured for listen_addresses GUC.
Password: 
=========================================
Successfully started.
[dave@www.cndba.cn ~]$ gs_om -t restart -D /data/openGauss/install/data/dn
Stopping cluster.
=========================================
Successfully stopped cluster.
=========================================
End stop cluster.
Starting cluster.
=========================================
[SUCCESS] hf-172-31-101-18
2023-03-09 21:10:24.197 6409dac0.1 [unknown] 139829065660096 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-03-09 21:10:24.197 6409dac0.1 [unknown] 139829065660096 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets
2023-03-09 21:10:24.198 6409dac0.1 [unknown] 139829065660096 [unknown] 0 dn_6001 01000  0 [BACKEND] WARNING:  No explicit IP is configured for listen_addresses GUC.
Password: 
=========================================
Successfully started.
[dave@www.cndba.cn ~]$ 


[dave@www.cndba.cn ~]$ gs_om -t status
Password: 
-----------------------------------------------------------------------

cluster_name    : dbCluster
cluster_state   : Normal
redistributing  : No

-----------------------------------------------------------------------
[dave@www.cndba.cn ~]$

两个工具的对比:

gs_om 作为服务端的工具,输出的日志更简洁一些,而gs_ctl 作为数据库内部工具,会显示数据库内部的实际的信息,所以内容更多,也更底层一些。

http://www.cndba.cn/dave/article/116477
http://www.cndba.cn/dave/article/116477http://www.cndba.cn/dave/article/116477http://www.cndba.cn/dave/article/116477

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2283
    原创
  • 3
    翻译
  • 579
    转载
  • 196
    评论
  • 访问:8164604次
  • 积分:4428
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ