Create Database

Creates a new database in PostgreSQL.


  [ WITH [ LOCATION = { 'dbpath' | DEFAULT } ]
         [ TEMPLATE = template | DEFAULT ]
         [ ENCODING = encoding_name | encoding_number | DEFAULT ] ]



The name of the database you are creating.


The directory in which to save the database. You may use the DEFAULT keyword to save the database in the default data directory, as specified by the PGDATA environment variable (or -D flag, passed to the postmaster).

Note that the dbpath value must normally be the name of system-level environment variable, which is set within the PostgreSQL user’s environment to a value describing an initialized database directory. However, if PostgreSQL was compiled by the gmake command with the CPPFLAGS=-DALLOW_ABSOLUTE_DBPATHS argument passed to it, you can also specify a complete, absolute directory path.


The name of the template you wish to base the new database off of. Use the DEFAULT keyword to specify the default template (usually template1).

encoding_name | encoding_num

The multibyte encoding method to use for the database. This can be entered as a string literal, or an encoding type’s corresponding integer encoding number. See Appendix A, for a list of PostgreSQL’s multibyte encoding types.

You may use the DEFAULT keyword to explicitly specify the default encoding method (this is already the default).



The message returned when a new database is created successfully.

ERROR: user 'username ...

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.