brew install postgresql
Make sure Postgres is installed by checking what version is installed
postgres -V
Start up Postgres
brew services start postgresql
When you're done for the day, remember to stop the process
brew services stop postgresql
Get onto the postgres sql command line
psql postgres
To find the connection info, database, user, socket and port
postgres=# \conninfo
You should see the postgres prompt postgres=#
, use the prompt to see what users are installed.
This command executes and SQL query that gets all the users in the databse.
postgres=# \du
List all the databases
postgres=# \list
Create a database using the superuser account. Unrecommended in a real development scenario. CREATED DATABASE is a direct sql command, so don't forget the semicolon at the end.
postgres=# CREATE DATABASE mymessages;
To drop the database
postgres=# DROP DATABASE mymessages;
To use the database you just created, you need to connect to it
postgres=# \connect mymessages
To list the tables in the currently connected database
postgres=# \dt
To quit
postgres=# \q