next up previous contents index
Next: Access Configuration Up: Administration Previous: Creating Users

   
Creating Databases

To create new databases, you run createdb from an operating system prompt. Initially, only the POSTGRESQL superuser can create new databases. Other users can be given permission to create new databases.

The createdb program creates a new database by making a copy of the template1  database. This database is created when POSTGRESQL is first initialized. Any modifications to template1  will appear in subsequently created databases.

Databases are removed with dropdb. The CREATE DATABASE and DROP DATABASE commands are also available in SQL.

Figure [*] shows one database created from the command line and another one created through psql.

 

        $ createdb demodb1
        CREATE DATABASE
        $ psql test
        Welcome to psql, the PostgreSQL interactive terminal.
         
        Type:  \copyright for distribution terms
               \h for help with SQL commands
               \? for help on internal slash commands
               \g or terminate with semicolon to execute query
               \q to quit
         
        test=> CREATE DATABASE demodb2;
        CREATE DATABASE
        test=> DROP DATABASE demodb1;
        DROP DATABASE
        test=> \connect demodb2
        You are now connected to database demodb2.
        demodb2=> \q
 

A database is then destroyed, and a connection made to a new database. Additional information about each command can be found in the manual pages.  


Bruce Momjian
2001-05-09