Working with Postgresql helper commands

Hi Friends,

So today we’ll try to learn a few things on PostgreSql and
see what exactly PostgreSql ‘Helper commands’ are.

Apart from the good old sql queries that you can certainly use,
PostgreSql also provides us with Helper commands which you can use
to fetch information from the PostgreSql DB.

You can fire the PostgreSql Helper commands from the PostgreSql command prompt.

So lets login into the PostgreSql command prompt.
psql is the command line utility you would need for this, so lets begin.

Open Terminal (`ctrl+alt+t` in Ubuntu, check for you particular distro)

psql -h <host_name> -p <port_number> -d <database_name> -U <db_user_name> -W

Type in your <db_password> in the password prompt.

So now since we have connected to out database, lets see a few commands.

Check for All the Databases on the server


Check for size and access privileges of a particular Database

\l+ <database_name>

List Tables in a DB


List Tables in a DB with Size


Details about a particular table

\dt+ <table_name>

Describe a Table in a DB

\d+ <table_name>

Describe table with size and description (with pg_catalog schema)

\dtS+ <table_name>

Change/connect/move to a different Database.

\c <new_database_name>

Will try to come up with more blog post where we can share our information with each other.

Please let us know if you have any comments about the blog in the comments section below or if there are any corrections you may have spotted and you would like us to make those corrections.

Thanks a lot for taking your time & stopping over at the blogpost.
Have a good day!

Author: Admin

Hello Friends, welcome to I am the Admin of the site. I have worked as a software programmer for 7 years. I have started this site to learn as well as share whatever little knowledge i have gained over the period of time. If you wish to contact me, you can drop in an email to: admin[AT]hackerdays[DOT]com or you can also use the contact page. Thank you and I'll see you around.

Let us know your thoughts: