这篇文章主要讲解了“PostgreSQL数据库启动时socket存储目录的配置是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PostgreSQL数据库启动时socket存储目录的配置是什么”吧!

unix_socket_directories参数默认为/tmp,由于该目录是临时目录,以免误操作,一般设置在其他目录中。
下面把unix_socket_directories设置为/data/pg12,重新启动

[pg12@localhostpg120db]$grep'unix'postgresql.confunix_socket_directories='/data/pg12'#comma-separatedlistofdirectories#unix_socket_directories='/tmp'#comma-separatedlistofdirectories#unix_socket_group=''#(changerequiresrestart)#unix_socket_permissions=0777#beginwith0touseoctalnotation[pg12@localhostpg120db]$[pg12@localhostpg120db]$pg_ctlrestartpg_ctl:PIDfile"/data/pgsql/pg120db/postmaster.pid"doesnotexistIsserverrunning?tryingtostartserveranywaywaitingforservertostart....2019-11-1818:17:35.123CST[15542]LOG:startingPostgreSQL12.0onx86_64-pc-linux-gnu,compiledbygcc(GCC)4.8.520150623(RedHat4.8.5-16),64-bit2019-11-1818:17:35.123CST[15542]LOG:listeningonIPv4address"0.0.0.0",port54322019-11-1818:17:35.123CST[15542]LOG:listeningonIPv6address"::",port54322019-11-1818:17:35.155CST[15542]LOG:listeningonUnixsocket"/data/pg12/.s.PGSQL.5432"2019-11-1818:17:35.237CST[15542]LOG:redirectinglogoutputtologgingcollectorprocess2019-11-1818:17:35.237CST[15542]HINT:Futurelogoutputwillappearindirectory"pg_log".doneserverstarted

尝试连接数据库

[pg12@localhostpg120db]$psql-dtestdbpsql:error:couldnotconnecttoserver:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/tmp/.s.PGSQL.5432"?

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


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

[pg12@localhost~]$netstat-anpo|greppsql(Notallprocessescouldbeidentified,non-ownedprocessinfowillnotbeshown,youwouldhavetoberoottoseeitall.)tcp600::1:52206::1:5432ESTABLISHED16200/psqlkeepalive(7207.79/0/0)

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

[pg12@localhostpg120db]$exportPGHOST=/data/pg12[pg12@localhostpg120db]$psql-dtestdbExpandeddisplayisusedautomatically.psql(12.0)Type"help"forhelp....[pg12@localhost~]$netstat-anpo|greppsql(Notallprocessescouldbeidentified,non-ownedprocessinfowillnotbeshown,youwouldhavetoberoottoseeitall.)unix3[]STREAMCONNECTED87604215681/psql[pg12@localhost~]$

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

[pg12@localhost~]$psql-h/data/pg12Expandeddisplayisusedautomatically.psql(12.0)Type"help"forhelp.[local:/data/pg12]:5432pg12@testdb=#...[pg12@localhost~]$netstat-anpo|greppsql(Notallprocessescouldbeidentified,non-ownedprocessinfowillnotbeshown,youwouldhavetoberoottoseeitall.)unix3[]STREAMCONNECTED88059616309/psql[pg12@localhost~]$

感谢各位的阅读,以上就是“PostgreSQL数据库启动时socket存储目录的配置是什么”的内容了,经过本文的学习后,相信大家对PostgreSQL数据库启动时socket存储目录的配置是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!