PostgreSQL Tutorial for Absolute Beginners [Administration]
About Lesson

Every instance of a running PostgreSQL server manages one or more databases. Databases are therefore the topmost hierarchical level for organizing SQL objects (“database objects”).

Creating a Database

CREATE DATABASE name;

Template Databases

CREATE DATABASE actually works by copying an existing database. By default, it copies the standard system database named template1. Thus that database is the “template” from which new databases are made. If you add objects to template1, these objects will be copied into subsequently created user databases.

There is a second standard system database named template0. This database contains the same data as the initial contents of template1, that is, only the standard objects predefined by your version of PostgreSQL. template0 should never be changed after the database cluster has been initialized

Destroying a Database

Databases are destroyed with the command DROP DATABASE.

Drop database name;

Data dictionary view: pg_database

Viewing the List of Databases

SELECT oid, datname from pg_database;

Join the conversation