Official Documentation and Tutorial
brew install postgresql
Make sure that brew service is installed
brew tap homebrew/services
Start PostgreSQL as a background service: (will start automatically at login)
brew services start postgresql
stop and restart:
brew services stop [restart] postgresql
(to add)
psql
pgAdmin
psql mydb
then execute commands for the database.
Use psql directly
For example:
psql mydb -c "\l"
psql mydb -c "[command]"
\l
\dt
\d table
\q
Full doc here.