PostgreSQL Cheat Sheet/Create database with owner

Create a database with explicit owner and template.

Section: Database and Role Lifecycle

Create database with owner

sql
sql
CREATE DATABASE appdb OWNER appuser TEMPLATE template0 ENCODING 'UTF8';
Explanation

See summary for usage details.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Database and Role Lifecycle
Create database
Create a new database in the cluster.
OpenIn sheetsqlsame section
Rename database
Rename an existing database.
OpenIn sheetsqlsame section
Drop database
Delete a database permanently.
OpenIn sheetsqlsame section
Create login role
Create a role that can log in.
OpenIn sheetsqlsame section
Create role with privileges
Create a role with explicit capability flags.
OpenIn sheetsqlsame section
Change role password
Update a role password.
OpenIn sheetsqlsame section