Postgres - Create a new database and options
1. Using Query Editor
Postgres Create database statement:
CREATE DATABASE db_name;
To assign owner to the new database:
CREATE DATABASE db_name OWNER role_name;
Apart from assigning owner with OWNER
, we have some other options to add to the statement:
-
TEMPLATE: The template to create the new database. The default template is template1.
-
ENCODING: The character set encoding to use in the new database.
-
LC_COLLATE: Collation order to use in the new database.
-
LC_CTYPE: Character classification to use in the new database.
-
TABLESPACE: Tablespace name for the new database.
-
CONNECTION LIMIT: The maximum concurrent connections.
The full statement will be something like this:
CREATE DATABASE db_name
OWNER = role_name
TEMPLATE = template
ENCODING = encoding
LC_COLLATE = collate
LC_CTYPE = ctype
TABLESPACE = tablespace_name
CONNECTION LIMIT = max_concurrent_connection;
2. Create a database from the shell:
createdb db_name
Granting ownership:
createdb -O role_name db_name
3. Using TablePlus
In TablePlus, you can create a new PostgreSQL database from its GUI Tool:
- Click on the database button to see the list of current databases (Cmd + K)
- Click + button to create a new database
- Don’t forget to commit changes (Cmd + S) to the server after creating
TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.