mattes / migrate

Database migrations. CLI and Golang library.
Other
2.29k stars 326 forks source link

Password authentication failed (PostgreSQL 9.3) #41

Closed muminoff closed 8 years ago

muminoff commented 9 years ago

Hi.

I am facing with DB password authentication failure issue when I run this command:

sardor@geekbot:~/.gvm/pkgsets/go1.4/global/src/github.com/go-bootstrap/go-bootstrap$ migrate -url postgres://sardor:qwe123@localhost:5432/goweb?sslmode=disable -path /home/sardor/.gvm/pkgsets/go1.4/global/src/github.com/go-bootstrap/go-bootstrap/ up
pq: password authentication failed for user "sardor" 

0.0049 seconds

I was using migrate with go-bootstrap and it's author also points here in his comment

This is postgresql user sardor which was set as superuser:

sardor@geekbot:~/.gvm/pkgsets/go1.4/global/src/github.com/go-bootstrap/go-bootstrap$ sudo su postgres
postgres@geekbot:/home/sardor/.gvm/pkgsets/go1.4/global/src/github.com/go-bootstrap/go-bootstrap$ psql
psql (9.3.6)
Type "help" for help.

postgres=# \du
                              List of roles
  Role name  |                   Attributes                   | Member of 
-------------+------------------------------------------------+-----------
 digmaster   |                                                | {}
 drivers     |                                                | {}
 login       |                                                | {}
 newsdig     |                                                | {}
 postgres    | Superuser, Create role, Create DB, Replication | {}
 sardor      | Superuser, Create role, Create DB, Replication+| {}
             | Password valid until 2015-05-08 00:00:00+09    | 
 tarjimonlar |                                                | {}
 test        |                                                | {}

OS: Ubuntu 14.04.2 LTS PostgreSQL: 9.3.6 Go: 1.4

What might be the reason for it? Or postgresql configuration is not correct?

This is my pg_hba.conf:

root@geekbot:~# grep sardor /etc/postgresql/9.3/main/pg_hba.conf                                                                                          
local   all             sardor                                  trust

Tried with different methods:

root@geekbot:~# grep sardor /etc/postgresql/9.3/main/pg_hba.conf 
local   all             sardor                                  ident

No success.

Any suggestions?

cengiz-io commented 9 years ago

I'm having the same problem.

Version Information

vagrant@host:~$ migrate version
Driver '' not found.

Steps

Tried executing migrate by hand

migrate -url postgres://vagrant@localhost:5432/sandbox-go-bootstrap?sslmode=disable -path $GOPATH/src/github.com/cengizIO/sandbox-go-bootstrap/migrations up
pq: password authentication failed for user "vagrant"
0.0020 seconds

Nope.

And with an explicit password:

migrate -url postgres://vagrant:vagrant@localhost:5432/sandbox-go-bootstrap?sslmode=disable -path $GOPATH/src/github.com/cengizIO/sandbox-go-bootstrap/migrations up
pq: password authentication failed for user "vagrant"
0.0020 seconds

same.

Notes

vagrant@host:~$ psql -d sandbox-go-bootstrap
psql (9.1.15)
Type "help" for help.

sandbox-go-bootstrap=#

Regards.

mattes commented 9 years ago

I will check this weekend.

rnubel commented 9 years ago

@cengizIO: You should pass the password explicitly in the connection string, but not like you would for HTTP auth. Per the driver, it's a query argument to the connection string.

So, try:

migrate -url postgres://vagrant@localhost:5432/sandbox-go-bootstrap?sslmode=disable&password=vagrant

This approach worked for me.