我已经在 Ubuntu 21.04 上安装了 postgresql。
当我想将它与 psql
一起使用时命令我收到此错误:
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
更新 1 我以前有过postgres。今天我尝试使用它并收到此错误,所以我使用
sudo apt remove postgresql-13 postgresql-client-13 postgresql-client-common postgresql-14 postgresql-client-14 postgresql-common
删除了有关 postgres 的所有内容并通过 sudo apt install postgresql
安装了 postgres .在教程中,他们安装 postgres 并在没有任何配置的情况下开始使用它,但我不能这样做。
更新 2
pg_lsclusters
的输出命令:Ver Cluster Port Status Owner Data directory Log file
13 main 5432 down,binaries_missing postgres /var/lib/postgresql/13/main /var/log/postgresql/postgresql-13-main.log
14 main 5433 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
最佳答案
编辑此文件以解决端口问题:/etc/postgresql/14/main/postgresql.conf
:port = 5433
-> port = 5432
/etc/postgresql/13/main/postgresql.conf
:port = 5432
-> port = 5433
打开/etc/postgresql/14/main/pg_hba.conf
使用您喜欢的编辑器并更改以下行:
local all postgres peer
对此:local all postgres trust
然后运行 sudo service postgresql restart
运行 psql -U postgres
并运行此命令:ALTER USER postgres WITH ENCRYPTED PASSWORD "#your-password" ;
CRETE USER smjt2000 WITH ENCRYPTED PASSWORD "#your-password" ;
CREATE DATABASE smjt2000 OWNER smjt2000 ;
输入 exit
退出 postgresql shell更改
/etc/postgresql/14/main/pg_hba.conf
对此:local all postgres md5
终于跑了sudo service postgresql restart
关于sql - postgresql 安装后出错 : connection to server failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69620787/