Menu

PostgreSQL Commands – Step-by-Step Guide
📰

PostgreSQL Commands – Step-by-Step Guide

DEV Community: postgres·Vasanthakumari N·2 days ago
#mVah60nr
Reading 0:00
15s threshold

PostgreSQL is an open-source relational database management system (RDBMS) used to store, manage, and retrieve data.

Step 1: Check whether PostgreSQL is installed

Run:

psql --version

Step 2: If PostgreSQL is not installed

On Linux Mint / Ubuntu, install it using:

sudo apt update

sudo apt install postgresql

Step 3: Switch to PostgreSQL user

sudo -i -u postgres

Then open PostgreSQL:

psql

Purpose: Switches the current terminal session to the postgres Linux user.

sudo --> Executes a command with elevated privileges

-i --> Starts an interactive login shell

-u --> Specifies the user

postgres --> PostgreSQL system user

Step 4: Check PostgreSQL version

Select version();

Step 5: Get Help

\h

Purpose: Displays help about SQL commands in PostgreSQL.

Step 6: List All Databases

\l

Purpose: Displays all databases available in the PostgreSQL server.

Step 7: Create a Database

CREATE DATABASE movie;

Purpose: Creates a new database named movie.

Note: SQL commands should end with a semicolon…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.