Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Create / drop database not working #836

Closed
Ibrahimous opened this issue Jan 8, 2018 · 18 comments
Closed

Create / drop database not working #836

Ibrahimous opened this issue Jan 8, 2018 · 18 comments
Assignees

Comments

@Ibrahimous
Copy link

Ibrahimous commented Jan 8, 2018

Hi there,

Thanks for your work, at first :)
I ran into problems just executing the following command:
$ buffalo create db -a
OR

$ buffalo db drop -a

I have the following database.yml:

development:
  dialect: postgres
  database: myAppdb
  user: user
  password: password
  host: 127.0.0.1
  pool: 5

test:
  url: {{envOr "TEST_DATABASE_URL" "postgres://user:password@127.0.0.1:5432/myApp_test?sslmode=disable"}}

production:
  url: {{envOr "DATABASE_URL" "postgres://user:password@127.0.0.1:5432/myApp_production?sslmode=disable"}}

I get:

$ buffalo db drop -a
v3.41.3

couldn't drop database myApp_test: error dropping PostgreSQL database myApp_test: pq: authentification par mot de passe échouée pour l'utilisateur  « user »
couldn't drop database myApp_production: error dropping PostgreSQL database myApp_production: pq: authentification par mot de passe échouée pour l'utilisateur  « user »
couldn't drop database myAppdb: error dropping PostgreSQL database myAppdb: pq: la base de données « user » n'existe pas

Meaning: buffalo seems to understand postgres://user:password as postgres://DATABASEr:password !

Any help, please ?

@markbates
Copy link
Member

I don’t understand the language of the error message, but I think it’s telling you that it can’t authenticate the user/password in Postgres. Make sure it exists and has the right permissions in Postgres.

@stanislas-m
Copy link
Member

@markbates It's french for "Bad password authentication for user 'user'", then "The "'user' database doesn't exist".

@Ibrahimous Check your credentials with a postgresql client.

@Ibrahimous
Copy link
Author

Hi, thanks for your fast as light answer: here is the translation:

couldn't drop database myApp_test: error dropping PostgreSQL database myApp_test: pq: failed authentication for user « user »
couldn't drop database myApp_production: error dropping PostgreSQL database myApp_production: pq: failed authentication for user « user »
couldn't drop database myAppdb: error dropping PostgreSQL database myAppdb: pq: database « user » does not exist

The problem isn't that the user doesn not exist, the problem is that, as mentionned above, the URL states:

url: {{envOr "DATABASE_URL" "postgres://user:password@127.0.0.1:5432/myApp_production?sslmode=disable"}}`

And that buffalo thinks that user is a database

@Ibrahimous
Copy link
Author

@stanislas-m I'm currently connected with "user": the problem doesn't lie in wrong credentials

@stanislas-m
Copy link
Member

@Ibrahimous buffalo db create -a handles all databases defined in the config.
Can you try buffalo db create -e development, to debug only one config first?

@Ibrahimous
Copy link
Author

Thanks @stanislas-m, but no, the particular doesn't work better that the general^^

Error: couldn't create database authrecipe_development: error creating PostgreSQL database authrecipe_development: pq: la base de données « red-teamer » n'existe pas

$ cat database.yml
development:
dialect: postgres
database: authrecipe_development
user: red-teamer
password:
host: 127.0.0.1
pool: 5

...

P.S. : I'm trying to use: https://github.com/gobuffalo/authrecipe

@stanislas-m
Copy link
Member

@Ibrahimous It works well on my Linux machine:

$ buffalo db create -a
v3.41.9

created database authrecipe_development
created database authrecipe_test
created database authrecipe_production

can you get the output of buffalo info?

@Ibrahimous
Copy link
Author

Ibrahimous commented Jan 8, 2018

$ buffalo info

Buffalo Version

v0.10.2

App Information

Pwd=<user_home>/DEV/Go/src/github.com/authrecipe
Root=<user_home>/DEV/Go/src/github.com/authrecipe
GoPath=<user_home>/DEV/Go
Name=authrecipe
Bin=bin/authrecipe
PackagePkg=github.com/authrecipe
ActionsPkg=github.com/authrecipe/actions
ModelsPkg=github.com/authrecipe/models
GriftsPkg=github.com/authrecipe/grifts
WithPop=true
WithDep=true
WithWebpack=true
WithYarn=true
WithDocker=true
WithGrifts=true

Go Version

go version go1.9.2 linux/amd64

Go Env

GOARCH="amd64"
GOBIN="<user_home>/DEV/Go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="<user_home>/DEV/Go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build908012092=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Node Version

v8.9.4

NPM Version

5.6.0

Yarn Version

1.3.2

Dep Version

dep Not Found

Dep Status

dep Not Found

PostgreSQL Version

PostgreSQL Not Found

MySQL Version

mysql Ver 14.14 Distrib 5.5.58, for debian-linux-gnu (x86_64) using readline 6.3

SQLite Version

3.8.7.1 2014-10-29 13:59:56 3b7b72c4685aa5cf5e675c2c47ebec10d9704221

@robvdl
Copy link

robvdl commented Jan 14, 2018

Not sure if this is related but it's not working for me either, only the error doesn't make sense:

ERRO[0000] Error: couldn't create database vuerecipe: error creating PostgreSQL database vuerecipe: pq: database "robvdl" does not exist

What doesn't make sense in the error is that "robvdl" is not my db name, it's my username, so why it is saying "database robvdl does not exist" is beyond me, the db name is "vuerecipe" and username "robvdl".

I am getting the same error when doing a buffalo db drop.

buffalo db drop -a

I have made sure the robvdl user can log in with password and has createdb privileges, so not sure, this should be working.

If i manually create the databases and run buffalo db migrate it's fine and creates tables, it just seems to have issues creating databases and dropping them.

@Ibrahimous
Copy link
Author

I have made the logging capabilities & createdb privileges checks as well.

@stanislas-m
Copy link
Member

@robvdl @Ibrahimous Can you upgrade buffalo (and pop) to the latest version?

buffalo db create -a
v3.51.0

created database vuerecipe_production
created database vuerecipe_development
created database vuerecipe_test
buffalo db drop -a
v3.51.0

dropped database vuerecipe_test
dropped database vuerecipe_production
dropped database vuerecipe_development

I can't reproduce your problem on my setup, so either it was fixed, or your database has a different config.

@robvdl
Copy link

robvdl commented Jan 15, 2018

I did ugrade both pop and buffalo, but unfortunately I still get the same problem, the error message still doesn't make sense when it says database "robvdl" does not exist when that is the user, NOT the database:

buffalo db drop -a
v3.51.0

couldn't drop database vuerecipe_production: error dropping PostgreSQL database vuerecipe_production: pq: database "robvdl" does not exist
couldn't drop database vuerecipe_development: error dropping PostgreSQL database vuerecipe_development: pq: database "robvdl" does not exist
couldn't drop database vuerecipe_test: error dropping PostgreSQL database vuerecipe_test: pq: database "robvdl" does not exist

@stanislas-m
Copy link
Member

stanislas-m commented Jan 15, 2018

@robvdl @Ibrahimous Can you try to patch the postgresql.go file in your pop sources (in github.com/markbates/pop)? Replace urlWithoutDb definition with the following:

func (p *postgresql) urlWithoutDb() string {
	c := p.ConnectionDetails
	ssl := defaults.String(c.Options["sslmode"], "disable")

	var s string
	if c.Password == "" {
		s = "postgres://%s@%s:%s?sslmode=%s"
		return fmt.Sprintf(s, c.User, c.Host, c.Port, ssl)
	}
	s = "postgres://%s:%s@%s:%s?sslmode=%s"
	return fmt.Sprintf(s, c.User, c.Password, c.Host, c.Port, ssl)
}

Then go install -v github.com/gobuffalo/buffalo/buffalo & retry to create / drop the databases.

@stanislas-m
Copy link
Member

@robvdl @Ibrahimous Any news on this problem? :)

@StupidCodeFactory
Copy link

I have found work around:

  1. Create the database called what ever your postgres username is:
createdb my_postgres_username
  1. run the buffalo command to create the database:
buffalo db create -a

And on my machine it completed, hopefully it will on yours

@emurmotol
Copy link

emurmotol commented Mar 9, 2018

@StupidCodeFactory work around works. Thanks.

stanislas-m added a commit to gobuffalo/pop that referenced this issue Mar 15, 2018
See: gobuffalo/buffalo#836
If the db is not precised, postgresql takes the username as the database to connect on.
To avoid a connection problem if the user db is not here, we use the default "postgres"
db, just like the other client tools do.
@stanislas-m
Copy link
Member

I've reproduced the problem on another computer, with a brand new postgresql install.

It seems postgresql assumes the db name to be the same as the username, if not provided: that's why you see "pq: database "username" does not exist". By hardcoding the db to postgres (just like other postgresql clients), it works.

See gobuffalo/pop#31

@stanislas-m stanislas-m added the s: in progress Someone is working on this label Mar 15, 2018
@stanislas-m stanislas-m self-assigned this Mar 15, 2018
@stanislas-m stanislas-m removed the s: in progress Someone is working on this label Mar 15, 2018
@stanislas-m
Copy link
Member

@Ibrahimous Please update to Pop v4.2.2, it should work fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants