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
nameThe name of the database you are creating.
dbpathThe directory in which to save the database. You may use the
DEFAULTkeyword to save the database in the default data directory, as specified by thePGDATAenvironment variable (or -D flag, passed to the postmaster).Note that the
dbpathvalue 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.templateThe name of the template you wish to base the new database off of. Use the
DEFAULTkeyword to specify the default template (usuallytemplate1).encoding_name|encoding_numThe 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
DEFAULTkeyword to explicitly specify the default encoding method (this is already the default).
Results
CREATE DATABASEThe message returned when a new database is created successfully.
ERROR: user 'username ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access