Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't drop PostgreSQL database #402

Closed
davialexandre opened this issue Mar 7, 2015 · 16 comments
Closed

Can't drop PostgreSQL database #402

davialexandre opened this issue Mar 7, 2015 · 16 comments

Comments

@davialexandre
Copy link

It started after commit 1ed0fec. When you try to connect to PostgreSQL without a dbname, the username is used instead. If you don't have a database with same name as the username the connection will fail (and if both, the username and the database that you're trying to drop, have the same name the drop will also fail).

After a few tests, I don't think this can be fixed in DropDatabaseDoctrineCommand. I think that maybe the solution would change Doctrine\DBAL\Driver\PDOPgSql\Driver::_constructPdoDsn to use some default database name (maybe postgres) if dbname isn't set, but I have no idea if this would impact somewhere else.

@phansys
Copy link
Contributor

phansys commented Apr 9, 2015

I opened a issue in PHP some time ago because I didn't know that this was the expected behavior.

@deeky666
Copy link
Member

@davialexandre can we rely on postgres DB being always present? Is it possible to not have that DB in a server setup? I agree that we might need to add some abstraction around this issue to DBAL if it cannot be fixed this way...

@davialexandre
Copy link
Author

@deeky666 The postgres database is always created by the initdb command, but it can be dropped. This command also creates the template1 database, that is a template for other databases. Templates cannot be dropped, so I believe it is a good candidate as a default database name

@steve-todorov
Copy link

@deeky666, @davialexandre is right. I've commented on your pull request a while ago with observations and a possible solution to this issue. The same approach is used in PhpPGAdmin and I haven't had any issues in the past 3-4 years or so.

Also, the documentation of PostgreSQL points out that you'll always have a template0 and template1 database (more here) so this approach should be safe to use.

@pdesgarets
Copy link

Same problem here. I agree to say that template1 is a good default database, and thus used it in my PR.

@steve-todorov
Copy link

Neat solution! @stof @deeky666 - whenever you have some time, could you please have a look at this and merge it if everything's ok? :)

@pdesgarets
Copy link

@steve-todorov I actually think that steve-todorov@113ebec is a better solution, as it deals with the unfortunate "feature" of PostgreSQL instead of hiding it through DBAL. Could you please rebase, create a specific branch and pull-request ? I will close my PR for dbal as soon as yours is opened for DoctrineBundle.

deeky666 pushed a commit to doctrine/dbal that referenced this issue Apr 30, 2015
Fixes #402 (doctrine/DoctrineBundle#402) by connecting by default to 'template1' instead of the database with the same name as the user (Postgre default in case of no dbname).
deeky666 pushed a commit to doctrine/dbal that referenced this issue Apr 30, 2015
Fixes #402 (doctrine/DoctrineBundle#402) by connecting by default to 'template1' instead of the database with the same name as the user (Postgre default in case of no dbname).
@deeky666
Copy link
Member

@davialexandre @kiwidg @steve-todorov I merged the DBAL patch. Should be working with DBAL master now. Can someone confirm, please?
Also backported the fix to 2.5 and 2.4 branches.

@pdesgarets
Copy link

@deeky666 It works, for creating and dropping a database (with dev-master). Do you have an ETA for a v2.5.2 tag with the fix ?

@acasademont
Copy link

Yep, a 2.5.2 tag would come handy :D @deeky666

@trylika
Copy link

trylika commented Sep 4, 2015

Ping again, release would really help

@deeky666
Copy link
Member

deeky666 commented Sep 4, 2015

Sorry guys didn't see the comments. Will tag a new version next week. Sorry for the delay

@Ph3nol
Copy link

Ph3nol commented Sep 10, 2015

Waiting for a 2.5.2 tag too. 👍
Thank you!

@deeky666
Copy link
Member

New tag is available: https://github.com/doctrine/dbal/releases/tag/v2.5.2

@pdesgarets
Copy link

Thanks @deeky666 !

@kimhemsoe
Copy link
Member

Reading from comments this issue should be solved with the tagging of a new dbal release, therefor i am closing this.

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

No branches or pull requests

9 participants