PostgreSQL深入浅出 | 数据库的启动与停止

1、概述

上一章节我们已经讲述了基于CentOS7.9的操作系统环境安装PostgreSQL的过程,本章将介绍Postgres数据库的常用命令和基本操作。

2、Postgre数据库的启停

2.1、切换到postgres用户

[root@localhost ~]# su - postgres

2.2、查看PG数据库进程

[postgres@localhost ~]$ ps -aux|grep postgres

PostgreSQL深入浅出 | 数据库的启动与停止

2.3、启动数据库

[postgres@localhost ~]$ pg_ctl -D /usr/local/pgsql/pgdata -l /tmp/logfile start /usr/local/pgsql/pgdata:数据库的数据目录 /tmp/logfile:指定日志

PostgreSQL深入浅出 | 数据库的启动与停止

启动成功后检查进程 [postgres@localhost ~]$ ps -aux|grep postgres

PostgreSQL深入浅出 | 数据库的启动与停止

2.4、停止数据库

[postgres@localhost ~]$ pg_ctl stop -D /usr/local/pgsql/pgdata -m fast

PostgreSQL深入浅出 | 数据库的启动与停止

补充:

这里停止数据库使用的-m参数有三个常用选项: smart: 需要等到所有连接断开后才关闭数据库。 fast: 可以理解为Oracle数据库的immdiate模式。 immediate:可以理解为Oracle数据库的abort模式。

3、查看PostgreSQL数据库

[postgres@localhost ~]$ pg_ctl status

PostgreSQL深入浅出 | 数据库的启动与停止