0

我在我的 Ubuntu 16.04 系统上安装了 PostgreSQL 9.6。它似乎已启动并正在运行,但是当我尝试建立连接时它就失败了。当我运行状态命令时,我看到它总是exited出于某种原因说。我在谷歌搜索中看到了很多东西,但似乎没有任何帮助。

我将 pg_hba.conf 中的第一个条目更改为local all postgres trust

% ps augxw | grep postg
postgres 769 0.0 0.3 303964 24384 ?S 22:13 0:00 /usr/lib/postgresql/9.6/bin/postgres -D /var/lib/postgresql/9.6/main -c config_file=/etc/postgresql/9.6/main/postgresql.conf
postgres 772 0.0 0.0 303964 3956 ? Ss 22:13 0:00 postgres: 9.6/main: checkpointer process
postgres 773 0.0 0.0 303964 3956 ? Ss 22:13 0:00 postgres: 9.6/main: writer process
postgres 774 0.0 0.0 303964 3956?Ss 22:13 0:00 postgres: 9.6/main: wal writer process
postgres 775 0.0 0.0 304408 6572?Ss 22:13 0:00 postgres: 9.6/main: autovacuum 启动器进程
postgres 776 0.0 0.0 158964 3204 ?Ss 22:13 0:00 postgres: 9.6/main: stats collector process
ubuntu 1492 0.0 0.0 12944 936 pts/0 S+ 22:14 0:00 grep postg
%
% sudo su - postgres
$ psql -h localhost
psql:无法连接到服务器:连接
被拒绝服务器是否在主机“localhost”(127.0 .0.1) 并接受
端口 5432 上的 TCP/IP 连接?
$ exit
logout
% systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
已加载:已加载(/lib/systemd/system/postgresql.service;已启用;供应商预设:已启用)
活动:自 2017 年 3 月 30 日星期四 22 日起活动(已退出) :13:57 PDT;1 分钟 19 秒前
进程:901 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
主 PID: 901 (code=exited, status=0/SUCCESS)
任务: 0
内存: 0B
CPU: 0
CGroup: /system.slice/postgresql.service

3 月 30 日 22:13:57 ip-172-31-9-223 systemd[1]:启动 PostgreSQL RDBMS...
3 月 30 日 22:13:57 ip-172-31-9-223 systemd[1]:启动 PostgreSQL关系数据库管理系统。

4

2 回答 2

0

您正在使用TCP/IP套接字进行连接,但local指的是 unix-domain 套接字。

第一个字段是连接类型:“local”是 Unix 域套接字,“host”是普通或 SSL 加密的 TCP/IP 套接字,“hostssl”是 SSL 加密的 TCP/IP 套接字,“hostnossl” " 是一个普通的 TCP/IP 套接字。

我确实从那个 repo 安装了 postgresql-9.6 并且:

  1. host all postgres 127.0.0.1/32 trust做你想做的事
  2. postgres@lkaminski-ubuntu-desk:~$ psql开箱即用,无需更改配置。它正在使用已经受信任的 unix 域套接字。因此,您可以直接删除-h localhost,无需编辑配置。

$ sudo grep -e "^[^#]" /etc/postgresql/9.6/main/pg_hba.conf

local   all             postgres                                peer
host   all             postgres         127.0.0.1/32            trust
local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
于 2017-04-03T06:42:13.357 回答
0

问题最终是版本 9.5 具有正常的 5432 端口,因此当 9.6 安装/启动时,它指向 5433。删除 9.5 安装并编辑配置文件以指向 5432 解决了该问题。

于 2017-04-09T00:54:17.053 回答