PostgreSQL Basic Commands

Basic CommandDescription
psql -d database -U user -WConnects to a database under a specific user
psql -h host -d database -U user -WConnect to a database that resides on another host
psql -U user -h host “dbname=db sslmode=require”Use SSL mode for the connection
\c dbnameSwitch connection to a new database
\lList available databases
\dtList available tables
\d table_nameDescribe a table such as a column, type, modifiers of columns, etc.
\dnList all schemes of the currently connected database
\dfList available functions in the current database
\dvList available views in the current database
\duList all users and their assign roles
SELECT version();Retrieve the current version of PostgreSQL server
\gExecute the last command again
\sDisplay command history
\s filenameSave the command history to a file
\i filenameExecute psql commands from a file
\?Know all available psql commands
\hGet help
\eEdit command in your own editor
\aSwitch from aligned to non-aligned column output
\HSwitch the output to HTML format
\qExit psql shell

Start Stop and Status check

systemctl status postgresql-13.service

systemctl stop postgresql-13.service

systemctl start postgresql-13.service

PG Port Number 

select * from pg_settings where name=’port’;

Create Database

CREATE DATABASE name

[ [ WITH ] [ OWNER [=] db_owner ]

   [ TEMPLATE [=] template ]

   [ ENCODING [=] encoding ]

   [ TABLESPACE [=] tablespace ]

]


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *