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

Stop using template1 as default database for postgres drivers #2279

Merged
merged 1 commit into from
Jan 7, 2016

Conversation

kimhemsoe
Copy link
Member

The "postgresql" should be used as the default database and not "template1". Postgresql creates databases by copying an existing database and "template1" is the default if none is specified, if any connection to the template database exists when a "CREATE DATABASE" is issued postgresql is unable to create the new database.

http://www.postgresql.org/docs/9.4/static/manage-ag-templatedbs.html

@kimhemsoe
Copy link
Member Author

Ohh yeah.. and ... "fixes" #2278

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@kimhemsoe IIRC the reason we decided against using postgresql as temporary database was that it is not guaranteed that the database exists in every database setup as you could theoretically delete it.

See doctrine/DoctrineBundle#402 (comment)

@Ocramius
Copy link
Member

Ocramius commented Jan 7, 2016

Can we somehow query to check whether the schema is there?

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@Ocramius I doubt this helps a lot. If the schema isn't there we still can't establish a temp connection. Also relying on a "default" database that has no special purpose and can be dopped by anyone. It's basically like a demo database to start with.
I might have found another solution, will check this no and report back.

@kimhemsoe
Copy link
Member Author

You can drop template1 too, postgres schema is the "recommended" schema to use as default for applications (Read the bottom note in the link), using template1 is not an option for various reasons. There is numerous stackoverflow explaining this.

I do not think you can drop template0 but that is not a good idea either for the same as template1.

I do strongly believe that using he postgres schema is the lesser evil of the 3 options that we have.
If people have dropped postgres they can either recreate it or specify a schema.

"Unknown database "postgres" is alot better error message then random ""SQLSTATE[55006]: Object in use: 7 ERROR: source database "template1" is being accessed by other users"" which may not even get throwed from dbal but from other random applications using the pg instance because we are using template1 as the default schema.

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

Closing in favour of #2280

@deeky666 deeky666 closed this Jan 7, 2016
@deeky666 deeky666 self-assigned this Jan 7, 2016
@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@kimhemsoe in a default database setup you cannot drop template databases as they are protected via the datistemplate = true configuration directive.

SQLSTATE[42809]: Wrong object type: 7 ERROR:  cannot drop a template database

See #2280 for a complete explanation. Also postgresql database is the default database that is owned by the postgresql user and it is very unreliable that user and thus the database is present.

@deeky666 deeky666 reopened this Jan 7, 2016
@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

Reopening as the discussion in #2280 revealed this might be the better approach.

@deeky666 deeky666 removed the Invalid label Jan 7, 2016
@deeky666 deeky666 added this to the 2.5.5 milestone Jan 7, 2016
deeky666 added a commit that referenced this pull request Jan 7, 2016
Stop using template1 as default database for postgres drivers
@deeky666 deeky666 merged commit df7aeea into doctrine:master Jan 7, 2016
@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@kimhemsoe thanks :)

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

Backported to 2.5 branch in af38e30

@kimhemsoe
Copy link
Member Author

We better provide the driver param fast to catch the issue flooding from doctrine bundle.

@kimhemsoe kimhemsoe deleted the pg_default_database branch January 7, 2016 12:27
@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@kimhemsoe do you think that many people are not having the postgres database? Otherwise yeah go ahead do a PR :)

@kimhemsoe
Copy link
Member Author

The template1 change came from a few doctrine bundle issues, i will provide PR's for the parameter.

doctrine/DoctrineBundle#461
doctrine/DoctrineBundle#351

Btw i think we should merge #2280 too, not the template1 active connection reason, but to make sure we always have clean a database for tests, without any local changes.

@deeky666
Copy link
Member

deeky666 commented Jan 7, 2016

@kimhemsoe I don't see how your referenced PRs are related to this issue here. Those PRs deal with a completely different problem.
About merging #2280: I don't think we should do that. When running the tests it is not Doctrine's task to ensure that the environment is set up correctly. Travis always spawns a fresh default environment so we won't have any problems there. Is there any other reason why we should use template0? I think template1 might be better because then environments that want to have default objects in every database can still make use of a modified template1 database.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants