永发信息网

如何退出postgresq数据库

答案:3  悬赏:20  手机版
解决时间 2021-11-27 01:09
  • 提问者网友:雨不眠的下
  • 2021-11-26 19:40
如何退出postgresq数据库
最佳答案
  • 五星知识达人网友:愁杀梦里人
  • 2021-11-26 21:14
直接在命令行输入:quit或者是exist即可完成退出。
备注:其实最简单的方法就是关闭登录窗口,或者切换用户的形式完成退出当前用户的数据库操作。
全部回答
  • 1楼网友:woshuo
  • 2021-11-26 23:18
\q 退出postgresql数据库,建议使用\?查看帮助信息!
  • 2楼网友:梦中风几里
  • 2021-11-26 22:19
启动数据库服务器(posgres用户)
  

[postgres@localhost bin]$ postgres D /opt/postgresql/data/ > /opt/postgresql/log/pg_serverlog >& &
[]
  当然如果设置了环境变量
  

PGDATA=/opt/postgresql/data
export PGDATA
  后可使用pg_ctl工具进行启动:
  

[postgres@localhost log]$ pg_ctl start l /opt/postgresql/log/pg_serverlog
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_serverlog
FATAL: lock file postmasterpid already exists
HINT: Is another postmaster (PID ) 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 :: CST
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
  如果要在操作系统启动时就启动PG可以在/etc/rcd/rclocal 文件中加以下语句
  

/opt/postgresql/bin/pg_ctl start l /opt/postgresql/log/pg_serverlog D /opt/postgresql/data
  关闭服务器
  最简单方法
  

[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 downLOG: shutting down
LOG: database system is shut down
done
server stopped
[postgres@localhost ~]$
  最快速关闭方法kill postgres 进程
  

[postgres@localhost ~]$ kill INT `head /opt/postgresql/data/postmasterpid`
[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 : pts/ :: su postgres
postgres : pts/ :: bash
postgres : pts/ :: /opt/postgresql/bin/postgres
postgres : ? :: postgres: writer process
postgres : ? :: postgres: wal writer process
postgres : ? :: postgres: autovacuum launcher process
postgres : ? :: postgres: stats collector process
postgres : pts/ :: ps ef
postgres : pts/ :: grep post
[postgres@localhost ~]$
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯