LinuxCommandLibrary

createdb

PostgreSQL database creation utility

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. It is a convenience wrapper around the SQL CREATE DATABASE command, providing a command-line interface that's often more convenient than invoking psql directly.
The utility connects to the PostgreSQL server (typically to the postgres or template1 database) and executes the CREATE DATABASE SQL command with the specified parameters. This avoids the need to launch psql interactively just to create a database.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community