Create Database
Creates a new database in PostgreSQL.
Synopsis
CREATE DATABASE name [ WITH [ LOCATION = { 'dbpath' | DEFAULT } ] [ TEMPLATE = template | DEFAULT ] [ ENCODING = encoding_name | encoding_number | DEFAULT ] ]
Parameters
name
The name of the database you are creating.
dbpath
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 thePGDATA
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.template
The name of the template you wish to base the new database off of. Use the
DEFAULT
keyword to specify the default template (usuallytemplate1
).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).
Results
CREATE DATABASE
The message returned when a new database is created successfully.
ERROR: user ' ...
Get Practical PostgreSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.