1. Home
  2. PostgreSQL
  3. Tutorials
  4. CREATE DATABASE

CREATE DATABASE

In PostgreSQL CREATE DATABASE statement is used for creating new database in server. Login to PostgreSQL database command prompt using command ‘sudo -u postgres psql‘ from terminal.

Syntax :-

CREATE DATABASE database_name;

Example :-

Login to your PostgreSQL server using command line. You will get PostgreSQL database prompt like postgres=# . Now use CREATE DATABASE statement to create database.

postgres=# CREATE DATABASE mydb;

If everything goes successfully, you will get output like “CREATE DATABASE“.

To confirm that database is create use l or list command from database command prompt to list all databases.

postgres=# list


                             List of databases
   Name    |  Owner   | Encoding | Collate | Ctype |   Access privileges
-----------+----------+----------+---------+-------+-----------------------
 mydb      | postgres | UTF8     | en_IN   | en_IN |  
 postgres  | postgres | UTF8     | en_IN   | en_IN |
 template0 | postgres | UTF8     | en_IN   | en_IN | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_IN   | en_IN | =c/postgres          +
           |          |          |         |       | postgres=CTc/postgres
(4 rows)
Tags ,
Was this article helpful to you? Yes No
Advertisement