LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

createdb

Create a new PostgreSQL database

TLDR

Create a database with the default name (current user)
$ createdb
copy
Create a database with a specific name
$ createdb [dbname]
copy
Create a database with a specific owner
$ createdb -O [owner] [dbname]
copy
Create a database with a specific encoding
$ createdb -E [UTF8] [dbname]
copy
Create a clean database from template0
$ createdb -T [template0] [dbname]
copy
Create a database on a remote server
$ createdb -h [hostname] -p [5432] -U [user] [dbname]
copy
Show the SQL command being executed
$ createdb -e [dbname]
copy

SYNOPSIS

createdb [options] [dbname] [description]

DESCRIPTION

createdb creates a new PostgreSQL database. It is a convenience wrapper around the SQL CREATE DATABASE command, providing a command-line interface that is often more convenient than invoking psql directly.The database name defaults to the current system user name if not specified. An optional description (comment) can be provided as the second argument.

PARAMETERS

-D tablespace, --tablespace tablespace

Default tablespace for the database.
-E encoding, --encoding encoding
Character encoding for the database.
-l locale, --locale locale
Locale for the database.
-O owner, --owner owner
Database owner user.
-T template, --template template
Template database to copy from (default template1).
-e, --echo
Echo the SQL commands that createdb sends to the server.
--icu-locale locale
ICU locale for the database.
--icu-rules rules
ICU collation rules for the database.
--locale-provider provider
Locale provider (libc or icu).
--strategy strategy
Database creation strategy (wallog or filecopy).
-V, --version
Print the createdb version and exit.
-h host, --host host
Server hostname or socket directory.
-p port, --port port
Server port number.
-U user, --username user
User name to connect as.
-w, --no-password
Never prompt for password.
-W, --password
Force password prompt.
--maintenance-db db
Database to connect to when creating the new database. Defaults to postgres, or template1 if postgres does not exist.

INSTALL

sudo apk add postgresql17-client
copy

CAVEATS

Requires CREATEDB privilege or superuser role. The default template is template1; use template0 for a clean database without local additions. Connection parameters can also be set via the standard PostgreSQL environment variables (PGHOST, PGPORT, PGUSER, PGDATABASE).

HISTORY

createdb has been part of the PostgreSQL distribution since its early versions, providing a simple command-line interface to the CREATE DATABASE SQL command.

SEE ALSO

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

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid