我刚刚在Ubuntu 15.10上安装了PostgreSQL 9.4。
- 我创建了一个用户
createuser -P myuser
- 我创建了一个数据库
createdb -O myuser mydatabase
- 我编辑
pg_hba.conf
并添加了local mydatabase myuser md5
- 我用重新启动了PostgreSQL
sudo service postgresql restart
用户myuser仅是PostgresSQL用户,在Ubuntu上没有用户帐户。
当我尝试使用连接数据库psql -W mydatabase myuser
时失败psql: FATAL: Peer authentication failed for user "myuser"
。
PostgreSQL正在运行…
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2016-03-03 09:53:00 CET; 9min ago
Process: 22219 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 22219 (code=exited, status=0/SUCCESS)
Mar 03 09:53:00 SERVER01 systemd[1]: Starting PostgreSQL RDBMS...
Mar 03 09:53:00 SERVER01 systemd[1]: Started PostgreSQL RDBMS.
...和聆听。
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:postgresql *:* LISTEN
tcp6 0 0 localhost:postgresql [::]:* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 151534 /var/run/postgresql/.s.PGSQL.5432
与用户myuser连接到数据库mydatabase,我该怎么做?