Monday, March 7, 2016

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 Postgrsql 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
\l+

Check for size and access privileges of a particular Database
\l+ <database_name>

List Tables in a DB
\d

List Tables in a DB with Size
\dt+

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!

No comments: