I recently had issues connecting to a PostgreSQL (Postgres) database on my local server, and had to perform quite a few steps to get it working properly. The following commands should be run in the terminal. Since I had a version that was installed on my machine a couple of years ago, I had to remove my previous version by performing the first step below.
Remove previous versions of Postgres
brew uninstall --force postgresql and rm -rf /usr/local/var/postgres
Install Postgres with Homebrew
brew install postgresql -v
Since it is your first time running Postgres after installation, you will need to run the following to initialize the Postgres database
It may look like you received an error, but don’t worry, this is not the last step.
Remove old database files
rm -r /usr/local/var/postgres
Run the initdb command again
You should now receive a message of success!
Start the Postgres database server
postgres -D /usr/local/var/postgres
###Username and password Note that your username for your local Postgres database is shown in the following, which is part of the success message on installation.
Your password by default is “postgres”