PostgreSQL Meta-Command using psql: Command Information -I

This is in continuation of My last blog about Meta Commands in PostgreSQL. In last blog we have explained what a Meta command is all about. In next few blogs we will explore few of Meta commands. Let’s start with psql command itself.

Once we logged in using psql, the environment should be look like

PostgreSQL> psql

This will bring us to default port 5432 with user postgres and database postgres on localhost.

if our database is not on default port 5432, we can pass port number to psql
PostgreSQL> psql -p 5433

We can connect to different database hosted on different machine by providing host also.
PostgreSQL> psql -U sanjeeva -d postgres -h localhost

PostgreSQL> psql -U sanjeeva -d postgres -h

To execute a command using psql we can use “-c” option
PostgreSQL> psql -U sanjeeva -d postgres -h -c “select version()”

There are many other options which can be found using help options
PostgreSQL> psql –help

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.