psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results.
Installation
From the terminal:
- Using HomeBrew:
brew install libpq- Than add symlink:
brew link --force libpq
Connection
psql -h [HOSTNAME] -p [PORT] -U [USERNAME] -W -d [DATABASENAME]Once you run that command, the prompt will ask you for your password. (Which we specified with the
-Wflag.)Alternatively, if you wat just to connect to a database in your local machine you can just write:
psqlto open the run the tool\c [database_name]To lits all the databases present in you machine, you can use
\l.
Basic Commands
- Create DB:
CREATE DATABASE [database_name]; - Delete DB:
DROP DATABASE [database_name]; - List all relations (tables):
\d - List information about a table:
\d table_name