1

What are the default databases in PostgreSQL at the time of installation?

2 Answers 2

5
  • template1: the "default" database, which is copied when you perform "create database foo"
  • template0: the "minimal default" database, which serves essentially the same purpose, but typically used to create databases when restoring dumps which might already have the extra objects that are in template1, or to create a database that uses a different character encoding to the server default (template0 should only contain ASCII characters in strings)
  • postgres: an "administrative" database, which clients can assume exists to connect to merely to list which databases are available etc. Also, for example, pgAdmin will install the pg_agent schema in this database.
Sign up to request clarification or add additional context in comments.

1 Comment

Here is the link to the official documentation: postgresql.org/docs/current/manage-ag-templatedbs.html
1

Apparently, there is a database "postgres" that is created by default on each PostgreSQL server installation. 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. When you later create a new database, everything in the template1 database is copied. (Therefore, anything installed in template1 is automatically copied into each database created later.) 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/static/app-initdb.html )

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.