sql - postgresql 安装后出错 : connection to server failed

标签 sql postgresql ubuntu

我已经在 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/

相关文章:

sql - 就像内联查询中的情况一样,出现错误

sql - 使用 postgreSQL 将字符串转换为 CLOB

Django 模型引用像循环?

postgresql - 在 GoLang 中将图像转换为 Base64

java - spring.jpa.properties.hibernate.jdbc.time_zone 适用于写入但不适用于读取?

reactjs - Nginx 404 静态文件( react 应用程序)

linux - ubuntu安装后USB的再利用

sql - 将字符串转换为具有非标准值的日期时间格式

mysql - 关系数据库 - 存储累积数据的最佳方式?

linux - 如何将文件名放在我要命令的目录中?