CREATE DATABASE is a data definition language (DDL) statement that initializes a completely separate logical database, including its system catalog, default encoding, locale, and optional tablespace. Once executed, the server allocates the physical files or directories required to store the new database. Only superusers or roles with CREATEDB privileges can run it. The command does not switch the current session into the new database; clients must issue a separate CONNECT or \c command. Some options are dialect-specific, so verify support before use.
database_name
(identifier) - Name of the database to create; must be unique within the cluster.OWNER
(role name) - Role that will own the database; defaults to the issuing user.TEMPLATE
(identifier) - Existing database to clone. Use template0 for a pristine catalog.ENCODING
(string) - Character set such as 'UTF8', 'LATIN1'.LC_COLLATE
(string) - Locale rules for string comparison.LC_CTYPE
(string) - Locale rules for character classification.TABLESPACE
(identifier) - Where to store the database files.CONNECTION LIMIT
(integer) - Maximum concurrent connections; -1 means unlimited.DROP DATABASE, ALTER DATABASE, CREATE SCHEMA, CREATE TABLE, GRANT
PostgreSQL 6.0 (1997)
Only superusers or roles granted the CREATEDB privilege can create new databases. Regular users receive an error unless privileges are elevated.
No. The command finishes in the current database. Issue CONNECT database_name or \c database_name to start using the new database.
Yes, but only after no active sessions reference it. Dropping a template removes its ability to serve as the source for new databases.
Use ALTER DATABASE database_name OWNER TO new_owner; You must be a superuser or the current owner to run this command.