Open In App

PostgreSQL – Create Database

PostgreSQL has multiple ways to create a database. In this article we will discuss multiple ways to do so.

1. Using psql Shell:



To create a database through the psql shell we make the use of the CREATE DATABASE statement as below:

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

The various options provided by the CREATE DATABASE statement are explained below:



Example 1:
Here we will create a test database with all default settings.

CREATE DATABASE my_test_db1;

Output:

Example 2:
Here we will create a test database with the following parameters:

CREATE DATABASE my_test_db2
 WITH ENCODING='UTF8'
 OWNER=GeeksForGeeks
 CONNECTION LIMIT=30;

Output:

2. Using pgAdmin:

Follow the below steps to create a new database using pgAdmin.

Article Tags :