How to Create a Database in PostgreSQL

Last updated July 25, 2026 · By the SaturnSQL team

Use CREATE DATABASE name, optionally setting OWNER and ENCODING. It cannot run inside a transaction block, so execute it as a standalone statement. New databases are cloned from template1 unless you specify another TEMPLATE.

CREATE DATABASE analytics;

With owner and template

CREATE DATABASE analytics_staging
  OWNER analytics_admin
  TEMPLATE analytics
  ENCODING 'UTF8';

Cloning from a TEMPLATE copies all its objects and data, but fails if anyone else is connected to the template database. Because CREATE DATABASE cannot run in a transaction, some GUI clients that auto-wrap statements will reject it; run it from psql or with autocommit on.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related PostgreSQL guides

© 2026 Panda Capital Oy Ab. All rights reserved.