Basic commands in PostgreSQL

Share via:

Hello Everyone,

This article will help you learning basic commands in postgreSQL.

Psql is an interactive terminal to work with the PostgreSQL database. It is used to retrieve data from the PostgreSQL database server faster and more effectively.

The below commands are very helpful for beginner’s :

How to connect PostgreSQL database using psql :

Note : Installation of PostgreSQL done by root user. During the installation of PostgreSQL software a user called  postgres will be created.

How to check databases available in cluster  

Command :select * from pg_database;

by default  PostgreSQL will provide three database

1.postgres

2.template1

3.template0

template 1 is the one used by default. You can alter / add / remove objects there to affect every newly created DB. CREATE DATABASE basically makes a copy of it on the file level (very fast) to create a new instance.

template0 starts out being the same and should never be changed – to provide a virgin template with original settings.

Check current database:

Command : select current_database(); 

Check current user :

Command : select current_user;

Check of list of roles:

Command : \du

List of databases with Size,Tablespace and Description :

Command : \l

Command : \l+

How to check version of PostgreSQL :

Tablespaces in PostgreSQL:

Command :  select * from pg_tablespace;

List of tables:

Commands: \d or \d

If tables are not available in PostgreSQL we will receive below output

Create a tables and use commands :

Note : If given command executes successfully postgres will give same command as output.

If tables are available :

List of Schemas :

List of functions :

Display command history :

Command : \s

Help command:

Exit form PostgreSQL :

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook  : https://www.facebook.com/ktexperts/
LinkedIn    : https://www.linkedin.com/company/ktexperts/
Twitter       : https://twitter.com/ktexpertsadmin
YouTube   :  https://www.youtube.com/c/ktexperts
Instagram  : https://www.instagram.com/knowledgesharingplatform

 

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Add Comment