ITPub博客

首页 > 数据库 > PostgreSQL > PostgreSQL DBA(132) - pgAdmin(unix_socket_directories)

PostgreSQL DBA(132) - pgAdmin(unix_socket_directories)

原创 PostgreSQL 作者:husthxd 时间:2019-11-18 18:35:05 0 删除 编辑

本节简单介绍了PostgreSQL数据库启动时socket存储的目录的配置,其对应的参数为unix_socket_directories。
unix_socket_directories参数默认为/tmp,由于该目录是临时目录,以免误操作,一般设置在其他目录中。
下面把unix_socket_directories设置为/data/pg12,重新启动

[pg12@localhost pg120db]$ grep 'unix' postgresql.conf 
unix_socket_directories = '/data/pg12' # comma-separated list of directories
#unix_socket_directories = '/tmp'   # comma-separated list of directories
#unix_socket_group = ''       # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
[pg12@localhost pg120db]$ 
[pg12@localhost pg120db]$ pg_ctl restart
pg_ctl: PID file "/data/pgsql/pg120db/postmaster.pid" does not exist
Is server running?
trying to start server anyway
waiting for server to start....2019-11-18 18:17:35.123 CST [15542] LOG:  starting PostgreSQL 12.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
2019-11-18 18:17:35.123 CST [15542] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-11-18 18:17:35.123 CST [15542] LOG:  listening on IPv6 address "::", port 5432
2019-11-18 18:17:35.155 CST [15542] LOG:  listening on Unix socket "/data/pg12/.s.PGSQL.5432"
2019-11-18 18:17:35.237 CST [15542] LOG:  redirecting log output to logging collector process
2019-11-18 18:17:35.237 CST [15542] HINT:  Future log output will appear in directory "pg_log".
 done
server started

尝试连接数据库

[pg12@localhost pg120db]$ psql -d testdb
psql: error: could not connect to server: could not connect to server: No such file or directory
   Is the server running locally and accepting
   connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

提示找不到socket(默认在/tmp下),可使用指定主机&端口连接


但这样的连接方式不是本地连接

[pg12@localhost ~]$ netstat -anpo|grep psql
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 ::1:52206               ::1:5432                ESTABLISHED 16200/psql           keepalive (7207.79/0/0)

设置参数PGHOST,使用本地连接(PGHOST behaves the same as the host connection parameter.)

[pg12@localhost pg120db]$ export PGHOST=/data/pg12
[pg12@localhost pg120db]$ psql -d testdb
Expanded display is used automatically.
psql (12.0)
Type "help" for help.
...
[pg12@localhost ~]$ netstat -anpo|grep psql
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
unix  3      [ ]         STREAM     CONNECTED     876042   15681/psql           
[pg12@localhost ~]$

或者使用-h指定为socket所在目录

[pg12@localhost ~]$ psql -h /data/pg12
Expanded display is used automatically.
psql (12.0)
Type "help" for help.
[local:/data/pg12]:5432 pg12@testdb=# 
...
[pg12@localhost ~]$ netstat -anpo|grep psql
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
unix  3      [ ]         STREAM     CONNECTED     880596   16309/psql           
[pg12@localhost ~]$

参考资料
Environment Variables

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6906/viewspace-2664693/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
ITPUB数据库版块资深版主,对Oracle、PostgreSQL有深入研究。

注册时间:2007-12-28

  • 博文量
    1442
  • 访问量
    3876585