1.报错
虚假的报错,关键词:
┌──(xavier?xavier)-[~]
└─$ psql
psql: 错误: 无法连接到服务器:无法联接到服务器: 没有那个文件或目录
服务器是否在本地运行并且在 Unix 域套接字
"/var/run/postgresql/.s.PGSQL.5432"上准备接受联接?
真实的报错,关键词:Postgresql日志文件:
┌──(xavier?xavier)-[~]
└─$ sudo tail /var/log/postgresql/postgresql-13-main.log
2021-10-26 14:53:12.462 HKT [1750] FATAL: configuration file "/etc/postgresql/13/main/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_messages": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_monetary": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_numeric": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_time": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] FATAL: configuration file "/etc/postgresql/13/main/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
2.解决方法
写在前面:虽然很希望能帮助到大家,但本方法在本机测试有效,不一定在其他机器上也生效。 排查报错时,注意查看一下Postgresql的日志文件,如果您也是类似的编码引起的报错,您可以试下此方法,选择相应的编码支持。
┌──(xavier?xavier)-[~]
└─$ sudo dpkg-reconfigure locales
通过空格选中en_HK.UTF-8 该编码格式,并确定:  确定之后,系统环境默认的区域设置中会有该编码,不过不用修改默认的区域设置,选择你喜欢的就行,点击确定。   添加支持后,重启一下Postgresql服务即可。
3.排查过程
本机环境:Debian 5.9.1-1kali2 (2020-10-29) x86_64  最开始是msf数据库连接识别,使用sudo msfdb init 对msf数据库进行初始化时遇到报错:  网上找了很多帮助文档,虽然没能直接有效的解决问题,但是也提供了很多思路。这个报错让我定位到了psql命令,对应的Postgresql数据库,单独执行psql命令,同样也是这个报错。
┌──(xavier?xavier)-[~]
└─$ psql
psql: 错误: 无法连接到服务器:无法联接到服务器: 没有那个文件或目录
服务器是否在本地运行并且在 Unix 域套接字
"/var/run/postgresql/.s.PGSQL.5432"上准备接受联接?
根据这个报错,网上找了一大堆资料,效果不好,帮助不大,也因此打算记录分享一下。
查看Postgresql数据库日志文件:/var/log/postgresql/postgresql-13-main.log
┌──(xavier?xavier)-[~]
└─$ sudo tail /var/log/postgresql/postgresql-13-main.log
2021-10-26 14:53:12.462 HKT [1750] FATAL: configuration file "/etc/postgresql/13/main/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_messages": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_monetary": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_numeric": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] LOG: invalid value for parameter "lc_time": "en_HK.UTF-8"
2021-10-26 14:54:05.656 HKT [1996] FATAL: configuration file "/etc/postgresql/13/main/postgresql.conf" contains errors
pg_ctl: could not start server
Examine the log output.
可见是配置文件/etc/postgresql/13/main/postgresql.conf 中编码格式为en_HK.UTF-8 的问题  查看本机的所支持的所有编码,确实没有en_HK.UTF-8 :
┌──(xavier?xavier)-[~]
└─$ locale -a
C
C.UTF-8
en_US.utf8
POSIX
zh_CN
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

可见目前并不支持en_HK.UTF-8 ,所以先试着添加该支持,用命令:sudo dpkg-reconfigure locales    重启一下Postgresql服务,再查看一下日志,可以发现已经没有之前的报错了。  切换到postgres用户,再试着执行一下psql命令,可以看到,没有问题: 重新执行 msfdb reinit :
 问题解决!
希望也能帮助到大家。
|