You can use the psql utility to interact with your PostgreSQL database directly from the terminal. With psql similar to the mysql you can run queries, manage databases and automate tasks with scripts over the command-line.
sudo -u postgres psql dbname
If you need to access PostgreSQL as the default postgres superuser, you may need to switch users in Linux first:
sudo -u postgres psql

Once in psql, check your connection to make sure you are in the right database by running:
\conninfo

If you need to switch to a different database before running queries, use:
\c database_name
Before running queries, check which tables exist in your database:
\dt
View the structure of a specific table:
\d table_name
Retrieve all rows from a table:
SELECT * FROM table_name;
For help with SQL commands:
\h
For help with psql-specific commands:
\?
If you need to import data into your PostgreSQL database, you can import database files via command line using similar principles to MySQL imports. For users familiar with MySQL, you can also connect to MySQL with SSH using comparable connection methods.
To exit PostgreSQL you will need to enter the command shown below.
\q
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting