Installing PostgreSQL on a Mac with Homebrew

Suppose you had a look at the 2021 stack overflow developer survey results. In that case, you might have seen that PostgreSQL, or Postgres for short, is now the second most loved database.

And I’ve been loving Postgres myself, so time to dedicate an a…


This content originally appeared on DEV Community and was authored by Chris Bongers

Suppose you had a look at the 2021 stack overflow developer survey results. In that case, you might have seen that PostgreSQL, or Postgres for short, is now the second most loved database.

And I've been loving Postgres myself, so time to dedicate an article on how to set it up on a Mac.
This article will guide you through installing Postgres on your Mac and exploring the first database.

Stack overflow most loved databases 2021

In this article, I'll be using Homebrew. If you haven't used it before, check out my article on using Homebrew.

Installing Postgresql with Homebrew

The first thing we want to do is install Postgres.

Before running any install command in Homebrew, it's good to make sure you are up to date.

brew update

Now it's time to install Postgres, and you can run this command.

brew install postgresql

Once it's done, you should see this output line amongst some other stuff.

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /opt/homebrew/var/postgres

That means you are set!

Managing the Postgres database

To start the database, you can simply run the following command in your terminal:

brew services start postgresql

And to stop the Postgres database from running:

brew services stop postgresql

Once it's up and running, we want to create a root user to log in and interact with the database.

psql postgres

This will log you into the Postgres server.

Postgres server login

From here, you can create a new user with a password.

CREATE ROLE chris WITH LOGIN PASSWORD 'password';
ALTER ROLE chris CREATEDB;

My user's name here is chris, and my password is super secure as it is: password.

Note: Use secure passwords, please this is just a demo setup.

Connecting to the Postgres database

I find it easiest to use visual database connection tools.

If you are unsure what client to use: I've written down my top 5 database clients.

We'll use TablePlus to connect to our newly created Postgres database.

Open the app, and create a new connection.
For the type, you can choose "PostgreSQL".

TablePlus new PostgreSQL database connection

As for the connection details, you should use:

  • User: The one you just created, in my case chris.
  • Password: The password you set in my case password.
  • Database: This will be postgres.

The rest of the data should already be set up correctly.

You can then test the connection by clicking the "Test" button at the bottom. It should turn everything green.

Postgres connection green

And that's it you are now connected to your Postgres database.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter


This content originally appeared on DEV Community and was authored by Chris Bongers


Print Share Comment Cite Upload Translate Updates
APA

Chris Bongers | Sciencx (2022-01-12T07:30:50+00:00) Installing PostgreSQL on a Mac with Homebrew. Retrieved from https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/

MLA
" » Installing PostgreSQL on a Mac with Homebrew." Chris Bongers | Sciencx - Wednesday January 12, 2022, https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/
HARVARD
Chris Bongers | Sciencx Wednesday January 12, 2022 » Installing PostgreSQL on a Mac with Homebrew., viewed ,<https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/>
VANCOUVER
Chris Bongers | Sciencx - » Installing PostgreSQL on a Mac with Homebrew. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/
CHICAGO
" » Installing PostgreSQL on a Mac with Homebrew." Chris Bongers | Sciencx - Accessed . https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/
IEEE
" » Installing PostgreSQL on a Mac with Homebrew." Chris Bongers | Sciencx [Online]. Available: https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/. [Accessed: ]
rf:citation
» Installing PostgreSQL on a Mac with Homebrew | Chris Bongers | Sciencx | https://www.scien.cx/2022/01/12/installing-postgresql-on-a-mac-with-homebrew/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.