目录
环境
文档用途
详细信息

环境
系统平台:N/A
版本:4.3.4.5,4.3.4.6,4.3.4.7,4.3.4.8,4.3.4.9,4.5
文档用途
本文档概述了单实例数据库、流复制环境和集群环境三种架构下启动和关闭的步骤。并非故障排除文档。 但是可以清楚地了解这三种方式数据库在Linux系统下启动和关闭方式。

详细信息
对于单实例数据库和流复制数据库启动和关闭的顺序无特别要求,对于集群数据库必须首先关闭所有备节点数据库后,才能关闭主节点数据库。

  1. 单实例数据库启动和关闭

1.1 systemctl方式

systemctl为使用操作系统服务的方式将数据库启动和关闭的方法,方便流复制和集群的管理。

(1)数据库启动

[root@hgv4 ~]# systemctl start hgdb-se4.5.service

查看运行数据库状态

[root@hgv4 ~]# systemctl status hgdb-se4.5.service
hgdb-se4.5.service - hgdb4.5-see
Loaded: loaded (/usr/lib/systemd/system/hgdb-se4.5.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2020-09-10 10:25:08 CST; 41s ago
Process: 79115 ExecStop=/highgo/database/4.5/etc/hgdb-se4.5 stop (code=exited, status=1/FAILURE)
Process: 79222 ExecStart=/highgo/database/4.5/etc/hgdb-se4.5 start (code=exited, status=0/SUCCESS)
Main PID: 79229 (postgres)
Tasks: 10
CGroup: /system.slice/hgdb-se4.5.service
├─79229 /highgo/database/4.5/bin/postgres -D /highgo/database/4.5/data
├─79230 postgres: logger
├─79231 postgres: auditwriter
├─79233 postgres: checkpointer
├─79234 postgres: background writer
├─79235 postgres: walwriter
├─79236 postgres: autovacuum launcher
├─79237 postgres: archiver
├─79238 postgres: stats collector
└─79239 postgres: logical replication launcher

9月 10 10:25:08 hgv4 systemd[1]: Starting hgdb4.5-see…
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: Starting HighGo Database Server:
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: waiting for server to start… done
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: server started
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: HighGo Database Server started successfully
9月 10 10:25:08 hgv4 systemd[1]: Started hgdb4.5-see.

查看数据库的操作系统进程

[root@hgv4 ~]# ps -ef|grep postg
root 79435 1 0 10:27 ? 00:00:00 /highgo/database/4.5/bin/postgres
root 79441 79435 0 10:27 ? 00:00:00 postgres: logger
root 79442 79435 0 10:27 ? 00:00:00 postgres: auditwriter
root 79444 79435 0 10:27 ? 00:00:00 postgres: checkpointer
root 79445 79435 0 10:27 ? 00:00:00 postgres: background writer
root 79446 79435 0 10:27 ? 00:00:00 postgres: walwriter
root 79449 79435 0 10:27 ? 00:00:00 postgres: autovacuum launchr
root 79450 79435 0 10:27 ? 00:00:00 postgres: archiver
root 79451 79435 0 10:27 ? 00:00:00 postgres: stats collector
root 79452 79435 0 10:27 ? 00:00:00 postgres: logical replication launcher
root 79511 76215 0 10:28 pts/1 00:00:00 grep --color=auto postg

(2)数据库关闭

[root@hgv4 ~]# systemctl stop hgdb-se4.5.service

查看数据库服务状态

[root@hgv4 ~]# systemctl status hgdb-se4.5.service
hgdb-se4.5.service - hgdb4.5-see
Loaded: loaded (/usr/lib/systemd/system/hgdb-se4.5.service; enabled; vendor preset: disabled)
Active: inactive (dead) since 四 2020-09-10 10:25:59 CST; 2s ago
Process: 79291 ExecStop=/highgo/database/4.5/etc/hgdb-se4.5 stop (code=exited, status=0/SUCCESS)
Process: 79222 ExecStart=/highgo/database/4.5/etc/hgdb-se4.5 start (code=exited, status=0/SUCCESS)
Main PID: 79229 (code=exited, status=0/SUCCESS)

9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: Starting HighGo Database Server:
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: waiting for server to start… done
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: server started
9月 10 10:25:08 hgv4 hgdb-se4.5[79222]: HighGo Database Server started successfully
9月 10 10:25:08 hgv4 systemd[1]: Started hgdb4.5-see.
9月 10 10:25:59 hgv4 systemd[1]: Stopping hgdb4.5-see…
9月 10 10:25:59 hgv4 hgdb-se4.5[79291]: Stopping HighGo Database
9月 10 10:25:59 hgv4 hgdb-se4.5[79291]: waiting for server to shut down… done
9月 10 10:25:59 hgv4 hgdb-se4.5[79291]: server stopped
9月 10 10:25:59 hgv4 systemd[1]: Stopped hgdb4.5-see.

查看数据库的操作系统进程

[root@hgv4 ~]# ps -ef|grep postg
root 79428 76215 0 10:27 pts/1 00:00:00 grep --color=auto postg
1.2 pg_ctl方式

(1)数据库启动

[root@hgv4 ~]# pg_ctl start

等待服务器进程启动 …2020-09-10 10:27:44.923 CST [79405] 日志: 正在启动 HighGo Security Enterprise Edition Database System 4.5 on CentOS7 x86_64,build on 20200426

2020-09-10 10:27:44.923 CST [79405] 日志: 正在监听IPv4地址"0.0.0.0",端口 5866

2020-09-10 10:27:44.923 CST [79405] 日志: 正在监听IPv6地址"::",端口 5866

2020-09-10 10:27:44.928 CST [79405] 日志: 在Unix套接字 "/tmp/.s.PGSQL.5866"上侦听

2020-09-10 10:27:44.939 CST [79405] 日志: 日志输出重定向到日志收集进程

2020-09-10 10:27:44.939 CST [79405] 提示: 后续的日志输出将出现在目录 "hgdb_log"中.

完成

服务器进程已经启动

(2)数据库关闭

如果当期环境允许,为了加快数据库关闭速度,数据库可以提前将应用、中间件提前关闭后并结束与数据库的连接残留进程。

检查数据库会话连接数

highgo=# select datname,usename,client_addr,count(*) from pg_stat_activity where pid <> pg_backend_pid()and state=‘idle’ group by 1,2,3 order by 1,2,4 desc;

datname | usename | client_addr | count

---------±--------±------------±------

highgo | sysdba | | 1

(1 行记录)

kill除自己会话连接之外的所有用户连接进程

highgo=# select pg_terminate_backend(pid) from pg_stat_activity where state=‘idle’;

pg_terminate_backend


t

(1 行记录)

关闭数据库

[root@hgv4 ~]# pg_ctl stop -m fast

等待服务器进程关闭 … 完成

服务器进程已经关闭

对于 pg_ctl 关闭数据库 -m 参数的说明

-m 选项:

关闭或重启的选项:

-m, --mode=MODE 可以是 “smart”, “fast”, 或者 “immediate”

关闭模式有如下几种:

smart 所有客户端断开连接后退出

fast 直接退出, 正确的关闭(默认)

immediate 不完全的关闭退出; 此方式会导致数据库再次启动时进行实例恢复

  1. 流复制数据库启动和关闭

流复制数据同样可以使用systemctl或者pg_ctl命令方式关闭和启动数据库,对于流复制环境一主多备或一主一备模式,并没有先后启动和关闭顺序上的要求。

如果你想要确定主备节点的角色可参考文档(HighGo Database判断流复制主备角色的方法(Document 017033702)。我们此处我们采用pg_ctl方式进行关闭和启动。

2.1 采用 pg_ctl方式启动和关闭流复制环境

与单实例数据库启动和关闭相同,为加速停止你也可以采用关闭应用和结束残余的用户进程的方法。

(1)启动数据库

启动主节点

[root@hgv4 highgo]# pg_ctl start

等待服务器进程启动 …2020-09-14 14:21:01.520 CST [102693] 日志: 正在启动 HighGo Security Enterprise Edition Database System 4.5 on CentOS7 x86_64,build on 20200426

2020-09-14 14:21:01.520 CST [102693] 日志: 正在监听IPv4地址"0.0.0.0",端口 5866

2020-09-14 14:21:01.520 CST [102693] 日志: 正在监听IPv6地址"::",端口 5866

2020-09-14 14:21:01.522 CST [102693] 日志: 在Unix套接字 "/tmp/.s.PGSQL.5866"上侦听

2020-09-14 14:21:01.539 CST [102693] 日志: 日志输出重定向到日志收集进程

2020-09-14 14:21:01.539 CST [102693] 提示: 后续的日志输出将出现在目录 "hgdb_log"中.

完成

服务器进程已经启

检查主节点操作系统后台进程

[root@hgv4 highgo]# ps -ef|grep postg

postgres 48939 48938 0 14:42 ? 00:00:00 postgres: logger

postgres 48941 48938 0 14:42 ? 00:00:00 postgres: checkpointer

postgres 48942 48938 0 14:42 ? 00:00:00 postgres: background writer

postgres 48943 48938 0 14:42 ? 00:00:00 postgres: walwriter

postgres 48944 48938 0 14:42 ? 00:00:00 postgres: autovacuum launcher

postgres 48945 48938 0 14:42 ? 00:00:00 postgres: archiver

postgres 48946 48938 0 14:42 ? 00:00:00 postgres: stats collector

postgres 48947 48938 0 14:42 ? 00:00:00 postgres: logical replication launcher

postgres 48949 48938 0 14:42 ? 00:00:00 postgres: walsender repuser hgv4dg(65096) streaming 4/200000D8 --流复制日志发送进程, hgv4dg为备节点的主机名。

启动备节点

[root@hgv4dg highgo]# pg_ctl start

等待服务器进程启动 …2020-09-14 14:21:01.520 CST [102693] 日志: 正在启动 HighGo Security Enterprise Edition Database System 4.5 on CentOS7 x86_64,build on 20200426

2020-09-14 14:21:01.520 CST [102693] 日志: 正在监听IPv4地址"0.0.0.0",端口 5866

2020-09-14 14:21:01.520 CST [102693] 日志: 正在监听IPv6地址"::",端口 5866

2020-09-14 14:21:01.522 CST [102693] 日志: 在Unix套接字 "/tmp/.s.PGSQL.5866"上侦听

2020-09-14 14:21:01.539 CST [102693] 日志: 日志输出重定向到日志收集进程

2020-09-14 14:21:01.539 CST [102693] 提示: 后续的日志输出将出现在目录 "hgdb_log"中.

完成

服务器进程已经启

检查备节点操作系统后台进程

[root@hgv4dg highgo]# ps -ef|grep postg

postgres 49906 49905 0 14:42 ? 00:00:00 postgres: logger

postgres 49907 49905 0 14:42 ? 00:00:00 postgres: startup recovering 000000060000000400000020

postgres 49908 49905 0 14:42 ? 00:00:00 postgres: checkpointer

postgres 49909 49905 0 14:42 ? 00:00:00 postgres: background writer

postgres 49910 49905 0 14:42 ? 00:00:00 postgres: stats collector

postgres 49922 49905 0 14:42 ? 00:00:00 postgres: walreceiver streaming 4/200000D8 --流复制日志接收进程

(2)关闭数据库

关闭主节点

[root@hgv4 highgo]# pg_ctl stop

等待服务器进程关闭 … 完成

服务器进程已经关闭

关闭备节点

[root@hgv4dg highgo]# pg_ctl stop

等待服务器进程关闭 … 完成

服务器进程已经关闭

  1. 集群数据库启动和关闭

需采用Linux启动和关闭服务(systemctl)的方式进行关闭和启动,不建议使用 pg_ctl 方式启动和关闭集群中的节点。

集群启动顺序:

主节点->备节点

说明:顺序不能颠倒,严格按照先启动主节点数据库服务,在启动所有备节点数据库服务的顺序进行。

集群关闭顺序:

备节点->主节点

说明:顺序不能颠倒,严格按照先关闭所有备节点数据库服务后,再关闭主节点数据库服务的的顺序进行。

3.1 启动集群数据库

(1)启动主节点

使用systemctl方式启动

[root@hs01 ] systemctl start hgdb-se4.5.service

[root@hs01 ] systemctl status hgdb-se4.5.service

查看主节点数据库的操作系统进程

[root@hs01 hgdb_log]# ps -ef|grep post

root 10251 1 0 15:23 ? 00:00:00 /usr/libexec/postfix/master -w

postfix 10261 10251 0 15:23 ? 00:00:00 qmgr -l -t unix -u

postfix 16252 10251 0 16:30 ? 00:00:00 pickup -l -t unix -u

root 24217 1 0 17:33 ? 00:00:00 /highgo/database/4.5/bin/postgres -D /highgo/database/4.5/data

root 24218 24217 0 17:33 ? 00:00:00 postgres: logger process

root 24220 24217 0 17:33 ? 00:00:00 postgres: checkpointer process

root 24221 24217 0 17:33 ? 00:00:00 postgres: writer process

root 24222 24217 0 17:33 ? 00:00:00 postgres: wal writer process

root 24223 24217 0 17:33 ? 00:00:00 postgres: autovacuum launcher process

root 24224 24217 0 17:33 ? 00:00:00 postgres: archiver process

root 24225 24217 0 17:33 ? 00:00:00 postgres: stats collector process

root 24226 24217 0 17:33 ? 00:00:00 postgres: bgworker: logical replication launcher

root 24238 24217 0 17:33 ? 00:00:00 postgres: sysdba highgo 192.168.0.121(39996) idle

查看主节点集群守护进程

[root@hs01 hgdb_log]# ps -ef|grep repmgrd

root 24240 1 0 17:33 ? 00:00:00 /highgo/database/4.5/bin/repmgrd -d

root 24719 16546 0 17:36 pts/2 00:00:00 grep --color=auto repmgrd

查看主节点集群状态

  • 可以通过查看数据库集群状态的命令;如果主备库显示一致且如下所示,说明集群状态正常

  • 在 status 一栏中出现 * 表示正常状态,如果出现了其他的符号(比如 !,?),表明集群状态出现故障

[root@hs01 arch]# repmgr cluster show

ID | Name | Role | Status | Upstream | Location | Priority | Replication lag | Last replayed LSN

----±--------------±--------±----------±--------------±---------±---------±----------------±------------------

1 | 192.168.0.121 | primary | * running | | default | 100 | n/a | none

2 | 192.168.0.122 | standby | running | 192.168.0.121 | default | 100 | 0 bytes | 0/70006F0

(2)启动备节点

使用systemctl方式启动

[root@hs02 ~]# systemctl start hgdb-se4.5.service

[root@hs02 ~]# systemctl status hgdb-se4.5.service

查看备节点数据库的操作系统进程

[root@hs02 ~]# ps -ef|grep postg

root 20568 1 0 17:37 ? 00:00:00 /highgo/database/4.5/bin/postgres -D /highgo/database/4.5/data

root 20569 20568 0 17:37 ? 00:00:00 postgres: logger process

root 20570 20568 0 17:37 ? 00:00:00 postgres: startup process recovering 000000010000000000000007

root 20571 20568 0 17:37 ? 00:00:00 postgres: checkpointer process

root 20572 20568 0 17:37 ? 00:00:00 postgres: writer process

root 20573 20568 0 17:37 ? 00:00:00 postgres: stats collector process

root 20574 20568 0 17:37 ? 00:00:00 postgres: wal receiver process streaming 0/70006F0

root 20585 20568 0 17:37 ? 00:00:00 postgres: sysdba highgo 192.168.0.122(13382) idle

查看备节点集群守护进程

[root@hs02 ~]# ps -ef|grep repmgrd

root 20587 1 0 17:37 ? 00:00:00 /highgo/database/4.5/bin/repmgrd -d

root 20638 15513 0 17:37 pts/2 00:00:00 grep --color=auto repmgrd

查看备节点集群状态

[root@hs01 arch]# repmgr cluster show

ID | Name | Role | Status | Upstream | Location | Priority | Replication lag | Last replayed LSN

----±--------------±--------±----------±--------------±---------±---------±----------------±------------------

1 | 192.168.0.121 | primary | * running | | default | 100 | n/a | none

3.2 关闭集群数据库

(1)确认数据库主备节点

[root@hs01 arch]# repmgr cluster show

ID | Name | Role | Status | Upstream | Location | Priority | Replication lag | Last replayed LSN

----±--------------±--------±----------±--------------±---------±---------±----------------±------------------

1 | 192.168.0.121 | primary | * running | | default | 100 | n/a | none

2 | 192.168.0.122 | standby | running | 192.168.0.121 | default | 100 | 0 bytes | 0/70007D0

(2)关闭备节点

使用systemctl方式关闭

[root@hs02 ~]# systemctl stop hgdb-se4.5.service

[root@hs02 ~]# systemctl status hgdb-se4.5.service

查看备节点数据库的操作系统进程

[root@hs02 ~]# ps -ef|grep postg

root 26121 15265 0 18:22 pts/1 00:00:00 grep --color=auto postg

– 显示已无数据库进程

查看备节点集群守护进程

[root@hs02 etc]# ps -ef|grep repmgrd

root 26453 15265 0 18:26 pts/1 00:00:00 grep --color=auto repmgrd

– 显示已无 repmgrd -d 守护进程
(3)关闭主节点

使用systemctl方式关闭

[root@hs01 ~]# systemctl stop hgdb-se4.5.service

[root@hs01 ~]# systemctl status hgdb-se4.5.service

查看主节点数据库的操作系统进程

[root@hs01 arch]# ps -ef|grep postg

root 35230 16270 0 18:35 pts/1 00:00:00 grep --color=auto postg

– 显示已无数据库进程

查看主节点集群守护进程

[root@hs01 arch]# ps -ef|grep repmgrd

root 35337 16270 0 18:37 pts/1 00:00:00 grep --color=auto repmgrd

– 显示已无 repmgrd -d 守护进程

查看备节点集群状态

[root@hs01 arch]# repmgr cluster show

WARNING: log_switch/true: unknown name/value pair provided; ignoring

ERROR: connection to database failed

DETAIL:

could not connect to server: Connection refused

    Is the server running on host "192.168.0.121" and acceptingTCP/IP connections on port 5866?

DETAIL: attempted to connect using:

user=sysdba password=hgdb1234 connect_timeout=2 dbname=highgo host=192.168.0.121 port=5866 fallback_application_name=repmgr

说明: 此时使用repmgr cluster show 在各个集群节点查看状态均显示无法连接数据库。此为集群关闭后的正常返回结果。

如何重启数据库服务(包含单实例/流复制/集群)相关推荐

  1. zookeeper的单实例和伪集群部署

    原文链接: http://gudaoyufu.com/?p=1395 zookeeper工作方式 ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现 ...

  2. 炫“库”行动-人大金仓有奖征文-KingbaseES V8R6 手工创建主备流复制集群案例

    [本文正在参与炫"库"行动-人大金仓有奖征文] CSDNhttps://marketing.csdn.net/p/98bd30353e7cb998b6070a89e8b91edb ...

  3. oracle同机单实例加入集群,将oracle同机单实例加入rac集群的操作步骤

    [导读] 最近做了一个迁移项目,将同机单实例数据库添加到集群中.当时由于建实例的时候,没有将数据库建成rac,而是建成了一个单实例 最近做了一个迁移项目,将同机单实例数据库添加到集群中.当时由于建实例 ...

  4. 用mongoshake实现mongo分片集群到单实例和分片集群的数据同步

    一 实验环境 这里演示只同步源端ccc库下的t1,t2表,ddd库下的所有表到两个目标端. 二 实验步骤 2.1 创建专用账号 2.1.1 在源端创建账号 2.1.1.1 登录其中一个mongos节点 ...

  5. 使用 Bitnami PostgreSQL Docker 镜像快速设置流复制集群

  6. Mysql8 group replication组复制集群单主多主模式切换

    Mysql8 MGR集群操作图解 声明与简介 本文的数据来自网络,部分代码也有所参照,这里做了注释和延伸,旨在技术交流,如有冒犯之处请联系博主及时处理.本文主要介绍mysql的MGR集群的操作. My ...

  7. Mysql 8配置MGR单主多从集群

    一.MGR介绍 1.官方文档 Chapter 18 Group Replication 2.MGR介绍 MySQL Group Replication(下简称:MGR)是MySQL官方推出的一种基于P ...

  8. redis 复制集群搭建

    前言 redis 复制集群是开发中一种比较常用的集群模式,本篇演示如何在centos7上快速搭建一个redis复制集群: 环境准备 1.基于centos7系统的服务器(或者云服务器): 2.redis ...

  9. 1000+Redis实例,100+集群,Redis 在海量数据和高并发下的优化实践

    墨墨导读:Redis 对于从事互联网技术工程师来说并不陌生,几乎所有的大中型企业都在使用 Redis 作为缓存数据库. 但是对于绝大多数企业来说只会用到它的最基础的 KV 缓存功能,还有很多 Redi ...

最新文章

  1. LabVIEW做一款科学计算器
  2. tomcat启动_tomcat学习|tomcat的启动过程
  3. oracle中导入dmp数据注意事项
  4. public lt;Tgt; void method,此地泛型的意思
  5. GCC,Clang,make,cmake,makefile,CMakeLists.txt的概念
  6. 【转】采购提前期概述
  7. 使用Java 8和Lambda简化ReadWriteLock
  8. mysql 登录默认实例_【MySQL案例】mysql本机登录-S失灵_mysql
  9. react 类暴露_react如何将组件内部的方法暴露给外部
  10. thinkphp中的__DIR__ __ROOT__ __APP__ __MODULE__ APP_PATH LIB_PATH MODULE_PATH 等是在哪里定义的?...
  11. css3 animate基本属性
  12. Universal Link 用企业证书build包,可以通过链接拉起绑定的App(客户端)
  13. 山东省特种设备作业考试系统_2019防爆电气作业在线免费模拟考试系统及模拟题库5...
  14. html文件用excel打开乱码,都是兼容惹的祸 用excel打开xls文件出现乱码的解决方法...
  15. WIN7运行命令大全
  16. matlab 无刷电机,无刷直流电机MATLAB仿真模型
  17. 数据结构与算法 经典题库练习
  18. Tushare社区验证Carhart四因子模型
  19. libxml2 安装使用
  20. 关于公网IP和私有IP的区别

热门文章

  1. 75.android 简单的获取当前可用运行内存,总运行内存,获取包含系统软件在内的所有内存,获取系统参数显示的内存大小。
  2. NPP/VIIRS DNB/SDR影像下载与预处理
  3. 网络慢?看看路由器设置对不对
  4. 西数 MyBook 西部数据硬盘盒 WD MyBook 盒子破解使用普通SATA硬盘
  5. 清除 search.babylon.com 病毒
  6. 基于python的豆瓣FM(终端命令行界面)
  7. 制作视频剪辑,自动剪辑视频的软件如何剪辑
  8. C++移动构造函数和移动赋值运算符
  9. 不懂程序看的明白《黑客帝国》吗?
  10. P2713(罗马游戏 可并堆模板)