Get Started with Postgres on Mac in 4 Steps

We will be going through how to setup Postgres locally on mac. We will cover the following:

  • Starting Postgres
  • Using psql to interact with database in command-line
  • Creating your first database.
  • Manage Data (Create Table, Inserting Data, Viewing Data)
  • Stopping Postgres

Let's start off with making sure we have Postgres installed locally. Open up terminal on mac and run postgres --version. You should see the version information outputted.

Your Postgres version should show

If you don't see the postgres version or need to install it still. Check out the Install Postgres on Mac post. Now that we have that out of the way, let's continue.

Step 1

In terminal, run the following command. It will start Postgres locally.
brew services start postgresql

Step 2

Next, let's go into the Postgres server now that it's up and running. Run the following:
psql postgres

The postgres psql command line.

This will enable us to start running queries on the Postgres database. Let's now create our first database. In terminal, run:

Once the database has been created, lets set it to the database we will use to create our first table. To do this, we want to run:
\c app

This will confirm we are connected to new database.

Step 3

Let's create our first table, insert data, and view it.
CREATE TABLE "groups" ( id serial, "title" varchar NOT NULL);

Now that the table is created, let's insert our first group.
INSERT INTO groups (title) VALUES ('Red');

Lastly, let's see the data we inserted.
SELECT * FROM 'groups' LIMIT 100;

Further Learning

By default your computer is using your user. If you want to create new users and roles, I recommend checking out the documentation on roles.

**Note: Stop your local Postgres server, you can run:
brew services stop postgresql

In future posts, we will be diving deeper into PostGres features, extending it, and using it to build applications. Thanks.

Eric Cavazos

Eric Cavazos

I love to build software, workout, and snowboard...

View Comments