linux postgres服务重启,PostgreSQL服务器启动和关闭方法介绍

1. 启动数据库服务器(posgres用户):

[postgres@localhost bin]$ postgres -D /opt/postgresql/data/ > /opt/postgresql/log/pg_server.log 2>&1 &

[1] 4508

当然如果设置了环境变量

PGDATA=/opt/postgresql/data

export PGDATA

后,可使用pg_ctl工具进行启动:

[postgres@localhost log]$ pg_ctl start -l /opt/postgresql/log/pg_server.log

pg_ctl: another server might be running; trying to start server anyway

pg_ctl: could not start server

Examine the log output.

[postgres@localhost log]$

因为之前已经启动,所以打印“another server might be running”。此时,查看日志,有如下信息:

[postgres@localhost log]$ cat pg_server.log

FATAL:  lock file "postmaster.pid" already exists

HINT:  Is another postmaster (PID 4491) running in data directory "/opt/postgresql/data"?

[postgres@localhost log]$

当然,最简的启动方式是:

[postgres@localhost ~]$ pg_ctl start

server starting

[postgres@localhost ~]$ LOG:  database system was shut down at 2011-07-09 13:58:00 CST

LOG:  autovacuum launcher started

LOG:  database system is ready to accept connections

如果要在操作系统启动时就启动PG,可以在/etc/rc.d/rc.local 文件中加以下语句:

/opt/postgresql/bin/pg_ctl start -l /opt/postgresql/log/pg_server.log -D /opt/postgresql/data

2.关闭服务器

最简单方法:

[postgres@localhost ~]$ pg_ctl stop

waiting for server to shut down.... done

server stopped

与Oracle相同,在关闭时也可采用不同的模式,简介如下:

SIGTERM

不再允许新的连接,但是允许所有活跃的会话正常完成他们的工作,只有在所有会话都结束任务后才关闭。这是智能关闭。

SIGINT

不再允许新的连接,向所有活跃服务器发送 SIGTERM(让它们立刻退出),然后等待所有子进程退出并关闭数据库。这是快速关闭。

SIGQUIT

令 postgres 向所有子进程发送 SIGQUIT 并且立即退出(所有子进程也会立即退出),而不会妥善地关闭数据库系统。这是立即关闭。这样做会导致下次启动时的恢复(通过重放 WAL 日志)。我们推荐只在紧急的时候使用这个方法。

SIGKILL

此选项尽量不要使用,这样会阻止服务器清理共享内存和信号灯资源,那样的话你只能在启动服务器之前自己手工做这件事。另外,SIGKILL 直接把 postgres 杀掉,而不会等它把信号中继给它的子进程,因此我们还需要手工杀掉每个独立子进程。

使用方法举例:

[postgres@localhost ~]$ pg_ctl stop -o SIGTERM

LOG:  received smart shutdown request

LOG:  autovacuum launcher shutting down

waiting for server to shut down....LOG:  shutting down

LOG:  database system is shut down

done

server stopped

[postgres@localhost ~]$

最快速关闭方法:kill postgres 进程

[postgres@localhost ~]$ kill -INT `head -1 /opt/postgresql/data/postmaster.pid`

[postgres@localhost ~]$ LOG:  received fast shutdown request

LOG:  aborting any active transactions

LOG:  autovacuum launcher shutting down

LOG:  shutting down

LOG:  database system is shut down

附:postgre启动后的进程,如下:

[postgres@localhost ~]$  ps -ef|grep post

root      4609  4543  0 13:57 pts/2    00:00:00 su - postgres

postgres  4610  4609  0 13:57 pts/2    00:00:00 -bash

postgres  4724     1  0 14:08 pts/2    00:00:00 /opt/postgresql/bin/postgres

postgres  4726  4724  0 14:08 ?        00:00:00 postgres: writer process

postgres  4727  4724  0 14:08 ?        00:00:00 postgres: wal writer process

postgres  4728  4724  0 14:08 ?        00:00:00 postgres: autovacuum launcher process

postgres  4729  4724  0 14:08 ?        00:00:00 postgres: stats collector process

postgres  4752  4610  0 14:11 pts/2    00:00:00 ps -ef

postgres  4753  4610  0 14:11 pts/2    00:00:00 grep post

[postgres@localhost ~]$0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值