LinuxCommandLibrary

createdb

TLDR

Create database

$ createdb [dbname]
copy
Create with owner
$ createdb -O [owner] [dbname]
copy
Create with encoding
$ createdb -E [UTF8] [dbname]
copy
Create from template
$ createdb -T [template0] [dbname]
copy
Create on remote server
$ createdb -h [hostname] -p [5432] -U [user] [dbname]
copy
Create with tablespace
$ createdb -D [tablespace] [dbname]
copy
Show executed SQL
$ createdb -e [dbname]
copy

SYNOPSIS

createdb [options] [dbname] [description]

DESCRIPTION

createdb creates a PostgreSQL database. Wrapper around SQL CREATE DATABASE command. Connects to postgres database to issue the command.

PARAMETERS

-D tablespace, --tablespace tablespace

Default tablespace
-E encoding, --encoding encoding
Character encoding
-l locale, --locale locale
Locale for database
-O owner, --owner owner
Database owner
-T template, --template template
Template database
-e, --echo
Show commands sent to server
--strategy strategy
Database creation strategy

CONNECTION OPTIONS

-h host, --host host

Server hostname
-p port, --port port
Server port
-U user, --username user
Connect as user
-w, --no-password
Never prompt for password
-W, --password
Force password prompt
--maintenance-db db
Connection database

DEFAULTS

Database name defaults to current system user. Connects to postgres database (or template1) to create new database.

CAVEATS

Requires CREATEDB privilege or superuser role. Default template is template1. Use template0 for clean database without local additions.

SEE ALSO

dropdb(1), psql(1), pg_dump(1)

Copied to clipboard