Can't connect to postgres on centos with psycopg

参考:https://stackoverflow.com/questions/42548285/cant-connect-to-postgres-on-centos-with-psycopg

 

 

I've downloaded postgres on centos, created a database, created a user with a password, restarted postgres, checked the user in pg_authid, done it again, and I still can't connect.

Why can't I connect?

postgres=# create database test;
CREATE DATABASE
postgres=# create user test with password 'test';
CREATE ROLE
postgres=# grant all privileges on database test to test;
GRANT
postgres=# select * from pg_authid where rolname = 'test';
 rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcatupdate | rolcanlogin | rolreplication | rolconnlimit |             rolpassword             | rolvaliduntil 
---------+----------+------------+---------------+-------------+--------------+-------------+----------------+--------------+-------------------------------------+---------------
 test    | f        | t          | f             | f           | f            | t           | f              |           -1 | md505a671c66aefea124cc08b76ea6d30bb | 
(1 row)
postgres=# alter user test with password 'test';
ALTER ROLE

In the midst of this, I've sudo service postgresql restart multiple times, but am still getting this:

>>> conn = psycopg2.connect(host="127.0.0.1", port="5432", dbname="test", user="test", password="test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  Ident authentication failed for user "test"

I'm out of ideas :(

EDIT:

I also tried changing

# "local" is for Unix domain socket connections only
local   all             all                                     peer

to

# "local" is for Unix domain socket connections only
local   all             all                                     trust


 

 

转载于:https://www.cnblogs.com/louissica/p/10824860.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值