PrevChapter 7. Managing a DatabaseNext

Database Creation

Databases are created by the create database issued from within Postgres. createdb is a command-line utility provided to give the same functionality from outside Postgres.

The Postgres backend must be running for either method to succeed, and the user issuing the command must be the Postgres superuser or have been assigned database creation privileges by the superuser.

To create a new database named “mydb” from the command line, type

% createdb mydb
and to do the same from within psql type

If you do not have the privileges required to create a database, you will see the following:

% createdb mydb
WARN:user "your username" is not allowed to create/destroy databases
createdb: database creation failed on mydb.

Postgres allows you to create any number of databases at a given site and you automatically become the database administrator of the database you just created. Database names must have an alphabetic first character and are limited to 32 characters in length.

Managing a DatabaseUpAlternate Database Locations