PostgreSQL 9.6 无法在 Ubuntu 16 上连接
PostgreSQL 9.6 won't connect on Ubuntu 16
我在 Ubuntu 16.04 系统上安装了 PostgreSQL 9.6。它似乎已启动 运行ning,但是当我尝试建立连接时却失败了。当我 运行 status 命令时,我看到它出于某种原因总是说 exited
。我在 google 搜索中看到了很多东西,但 none 似乎有所帮助。
我将 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 launcher process
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: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
$ exit
logout
% systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2017-03-30 22:13:57 PDT; 1min 19s ago
Process: 901 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 901 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
Mar 30 22:13:57 ip-172-31-9-223 systemd[1]: Starting PostgreSQL RDBMS...
Mar 30 22:13:57 ip-172-31-9-223 systemd[1]: Started PostgreSQL RDBMS.
您正在使用 TCP/IP
套接字进行连接,但 local
指的是 unix 域套接字。
The first field is the connection type: "local" is a Unix-domain socket, "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.
我确实从那个 repo 安装了 postgresql-9.6 并且:
host all postgres 127.0.0.1/32 trust
做你想做的事
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
问题最终是版本 9.5 有正常的 5432 端口,所以当 9.6 得到 installed/started 时,它指向 5433。删除 9.5 安装并编辑配置文件以指向 5432 解决了这个问题.
我在 Ubuntu 16.04 系统上安装了 PostgreSQL 9.6。它似乎已启动 运行ning,但是当我尝试建立连接时却失败了。当我 运行 status 命令时,我看到它出于某种原因总是说 exited
。我在 google 搜索中看到了很多东西,但 none 似乎有所帮助。
我将 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 launcher process
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: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
$ exit
logout
% systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2017-03-30 22:13:57 PDT; 1min 19s ago
Process: 901 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 901 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.serviceMar 30 22:13:57 ip-172-31-9-223 systemd[1]: Starting PostgreSQL RDBMS...
Mar 30 22:13:57 ip-172-31-9-223 systemd[1]: Started PostgreSQL RDBMS.
您正在使用 TCP/IP
套接字进行连接,但 local
指的是 unix 域套接字。
The first field is the connection type: "local" is a Unix-domain socket, "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.
我确实从那个 repo 安装了 postgresql-9.6 并且:
host all postgres 127.0.0.1/32 trust
做你想做的事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
问题最终是版本 9.5 有正常的 5432 端口,所以当 9.6 得到 installed/started 时,它指向 5433。删除 9.5 安装并编辑配置文件以指向 5432 解决了这个问题.