Thursday, May 30, 2019

How to create a new database in PostgreSQL


postgres=# create role music;
CREATE ROLE
postgres=# create database musicdb with owner = music;
CREATE DATABASE
postgres=# 

Documented here

Use can also use the wrapper "createdb" for convenience:
$ createdb -O music musicdb
CREATE DATABASE musicdb OWNER music;

A complete DDL for creating a database may look like this:
CREATE DATABASE memo
    WITH 
    OWNER = mysuperuser
    TEMPLATE = template0
    ENCODING = 'UTF8'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1;

COMMENT ON DATABASE memo
    IS 'my comment here';

No comments:

Post a Comment