Reputation: 1333
I did search, but couldn't get clear clue. There is 'public' schema in postgres. But where is the schema defined? I only see it when I create a new db. More I want to know is where it is defined and how to change it.
Thanks in advance.
Yang
Upvotes: 3
Views: 1597
Reputation: 324901
The public
schema is created in the template0
and template1
databases by the initdb
command when the database cluster is initialised.
When you create a new database the template1
database is copied (cloned) to create the new database unless you specify a different template. All the contents of the template database are copied, so the new database starts out with a public
schema.
You can customise the template1
database - or make new databases to use as templates, specifying them with the TEMPLATE
option to the CREATE DATABASE
command.
See the documentation on template databases.
If you want custom templates I'd recommend making a new DB as a template and customising it how you want. It's perfectly reasonable to DROP
the public
schema.
Upvotes: 4
Reputation: 14185
As you guessed; It is created when you create the db.
There is nothing else special about it other than it is the default schema you get after createdb
and is the default search_path. You are free to DROP
it, create another one named 'public' or operate completely without one named 'public'.
Just make sure you have something useful in your search_path or you might end up having to type fully-qualified names all day.
Upvotes: 1