Password Authentication Failed with Database PostgreSQL 9.3 in Ubuntu

时间:2015-11-12 11:35:51

标签: postgresql ubuntu ubuntu-14.04 postgresql-9.3

I've installed PostgreSQL 9.3 in Ubuntu and I've created a new user "myuser". In fact if I write psql -U postgres -c'\du+' I get

                                    List of roles
Role name |                   Attributes                   | Member of |  Description 
----------+------------------------------------------------+-----------+-------------
postgres  | Superuser, Create role, Create DB, Replication | {}        | 
myuser    |                                                | {}        | 

Now I want to modify the password for "myuser" and then create a new database. So I wrote

psql \password myuser
Password for user myuser: bla bla...

but I get the error

psql: FATAL:  password authentication failed for user "myuser"

but I don't remember to have created a previous password. Ok, no problem. I decide to delete this user and so I wrote:

dropuser myuser
Password: what? bla bla...
dropuser: could not connect to database postgres: FATAL: password authentication failed for user "strange_user"

strange_user is a fancy name... but I don't know who is... There's a way to fix this issue?

My pg_hba.conf is:

# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

1 个答案:

答案 0 :(得分:0)

I think your problem might be that portgres doesn't know what postgres role (user) you want to connect as when you try to set the password or drop the user.

Try something like `psql -U postgres -c "ALTER ROLE myuser ENCRYPTED PASSWORD 's3kr1t'.