PostgreSQL DB Creation, User Creation in Windows, Linux

When we work on SpringBoot Applications, it is necessary to know PostgreSQL DB Creation, User Creation in Windows, Linux. Here, we have the steps for DB Creation.

PostgreSQL DB Creation in Windows:

Step 1: Open PostgreSQL Command Line (psql)

psql -U postgres

Step 2: Enter the Password

After giving password, we could enter the PostgreSQL Command line (postgres=#)

Step 3: DB Creation

CREATE DATABASE ecommerce;

Step 3 A (Optional): To verify Database is created, type \l (small L)

PostgreSQL DB Creation in Linux: (Linux Mint)

Step 1: Open Terminal (Shortcut: ctrl+alt+t) and type as below

sudo -i -u postgres

Step 2: Enter your password

Step 3: Type psql (Now, You’ll enter the PostgreSQL command line (postgres=#))

Step 4: DB Creation

CREATE DATABASE ecommerce;

Step 4 A:(Optional) To verify DB was created successfully, you can type \l (small L)

PostgreSQL User Creation in Windows and Linux:

Step 1: Now, we create user with username as ‘ecom’ and password as ‘ecom’. It is not necessary to give the same word as Password. We can give different passwords.

CREATE USER ecom WITH PASSWORD 'ecom';

Step 2: Grant all privileges to this user.

GRANT ALL PRIVILEGES ON DATABASE ecommerce TO ecom;

Step 3: To connect to the created DB:

\c ecommerce; 

In case, if you want to learn Postgres in Detail through Tamil, you can watch this video.