You came to the right place where you’ll learn some helpful commands that can help you out when you’re going to use PostgreSQL:
-
Let's say if we want to login as a different user (for example, guest1) to a database (food) that you have and want to go to,
well you would write it like this:
psql -U guest1 -d food -h localhost -
If you want to exit out of the postgres client account, you would type out this command:
\q -
We can list all the databases by typing this out:
\lor\list -
To change into a particular databse, you can type this out:
\c nba -
In order to show a list of tables that is in your current database that you are in, you would type this out:
\dor\dt -
To describe the format of a particular table, this is the command to use:
\d celtics -
To describe in more detail the format of a particular table, you would be typing this out:
\d+ celtics -
To import sql commands from an sql file, you can type out:
\i nba.sql -
To delete a particular database, just type this out:
DROP DATABASE nba -
To show all the data in a table of your choice, just type this out:
SELECT * FROM celtics
Source: http://www.postgresonline.com/downloads/special_feature/postgresql83_psql_cheatsheet.pdf