unix_socket_directories参数

作者:瀚高PG实验室 (Highgo PG Lab)- 天蝎座

unix_socket_directories参数指定服务器侦听客户端应用程序连接的Unix域套接字的目录。默认值通常是/tmp,但可以更改。此参数只能在服务器启动时设置。

除了名为.s.PGSQL.nnnn的套接字文件本身之外,其中nnnn是服务器的端口号,将在每个unix_socket_directories目录中创建一个为.s.PGSQL.nnnn.lock的普通文件。 这两个文件都不应该手动删除。

但是假如被误删除了怎么办?

做个测试:

[postgres@hgdb tmp]$ rm -rf .s.PGSQL.5432.lock
[postgres@hgdb tmp]$ psql 
psql (10.0)
Type "help" for help.

postgres=# \q

[postgres@hgdb tmp]$ psql -h 127.0.0.1
psql (10.0)
Type "help" for help.

postgres=# \q
[postgres@hgdb tmp]$ rm -rf .s.PGSQL.5432
[postgres@hgdb tmp]$ psql
psql: 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"?

[postgres@hgdb tmp]$ psql -h 127.0.0.1
psql (10.0)
Type "help" for help.

postgres=#


[postgres@hgdb tmp]$ pg_ctl restart -m f

[postgres@hgdb tmp]$ ll -a
srwxrwxrwx   1 postgres postgres    0 Feb  7 15:09 .s.PGSQL.5432
-rw-------   1 postgres postgres   42 Feb  7 15:09 .s.PGSQL.5432.lock

从上面的实验可以看出,删除套接字文件后,重启数据库,又重新生成了套接字文件。在没有套接字文件的情况下,可以通过TCP/IP套接字连接数据库。

前面提到unix_socket_directories是可以修改的。假如将默认的/tmp 修改为/home/postgres 呢?

postgres=# show unix_socket_directories ;
 unix_socket_directories
-------------------------
 /tmp
(1 row)

postgres=# alter system set unix_socket_directories TO '/home/postgres';
ALTER SYSTEM

[postgres@hgdb tmp]$ pg_ctl restart -m f
[postgres@hgdb tmp]$ psql
psql: 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"?
[postgres@hgdb tmp]$ psql -h 127.0.0.1
psql (10.0)
Type "help" for help.

postgres=# show unix_socket_directories ;
 unix_socket_directories
-------------------------
 /home/postgres
(1 row)

postgres=# \q
[postgres@hgdb tmp]$ 

如上所示:unix_socket_directories只影响使用psql走Unix域套接字连接数据库的情况。

[postgres@hgdb tmp]$ psql
psql: 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"?
[postgres@hgdb tmp]$ psql -h /home/postgres/
psql (10.0)
Type "help" for help.

postgres=# \q
[postgres@hgdb tmp]$ ll -a /home/postgres/
srwxrwxrwx  1 postgres postgres    0 Feb  7 15:20 .s.PGSQL.5432
-rw-------  1 postgres postgres   52 Feb  7 15:20 .s.PGSQL.5432.lock
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值