views:

97

answers:

3

Apparently there is a database "postgres" that is created by default on each postgresql server installation. Can anyone tell me or point me to documentation what it is used for?

+3  A: 

It appears that it does not really have a well-defined purpose. According to the docs:

Creating a database cluster consists of creating the directories in which the database data will live, generating the shared catalog tables (tables that belong to the whole cluster rather than to any particular database), and creating the "template1" and "postgres" databases.

[...]

The postgres database is a default database meant for use by users, utilities and third party applications.

(Source: http://www.postgresql.org/docs/8.2/interactive/app-initdb.html )

sleske
OK, that works for me. ;) Thanks!
dareios
+2  A: 

There is also the database template0, your safety net when you screw up all others.

  1. postgres is your default database to connect with.
  2. template1 is your default for creating new databases, these are created just like template1
  3. template0 is usefull when template1 is corrupted (wrong settings etc.) and you don't want to spend a lot of time to fix this. Just drop template1 and create a new template1 using the database template0.
Frank Heikens
+3  A: 

When a client application connects to a Postgres server, it must specify which database that it wants to connect to. If you don't know the name of a database (within the cluster serviced by the postmaster to which you connect), you can find a list of database names with the command:

 psql -l

When you run that command, psql connects to the server and queries pg_database for a list of database names. However, since psql is a Postgres client application, it can't connect to the server without knowing the name of at least one database: Catch-22. So, psql is hard-coded to connect to a database named "postgres" when you run "psql -l".

-- Korry
korry
Interesting, thanks for the additional info!
dareios