If you own Apple Silicon Mac and you want to spin up the PostgreSQL Server, your option could be limited. But don’t worry, with Docker, we can easily install PostgreSQL Server on Mac M1. In this article, we will show you step by step to install PostgreSQL Server on Apple Silicon Mac. We will use this server to store our spatial data. As you might know, we need to install PostGIS extension in PostgreSQL database so we can store spatial data.
Steps to Install PostgreSQL Server on Mac M1
Step 1. Install Docker Desktop
We will use Docker container for our PostgreSQL Server. So, first, we need to install Docker on the Mac. Please follow my previous tutorial to install Docker on Apple Silicon Mac. Or, you can simply download the DMG installer for Docker from this link.
Step 2. Dowload postgres image
Open Docker Desktop application and then search for postgres. You will see many images that match.
Click the version that you want to download. In this case, we download the one on top as shown above. Click Pull to start download. Once the download completed, you should see postgres image in the Docker Desktop Image tab.
Step 3. Run postgres Docker Container
Now click the Start/Play button next to the postgres image. It will show a new window where we can set some optional settings. Enter the container name, and then add the following Environment variables.
- variable: POSTGRES_USER, value: gis
- variable: POSTGRES_PASSWORD, value: gis.123
- variable: -d, value: leave empty
Change the value as you need. The POSTGRES_USER is the user for the PostgreSQL and POSTGRE_PASSWORD is the password.
Click Run to run the container. Your PostgreSQL Container now should be up and running. You can see it from the Containers menu as shown below.
At this point, our PostgreSQL database is up and running. We can connect to it using our favorite database administration software such as dBeaver.
Step 4. Connect to the server via Terminal
In case you want to connect to the server via Terminal, you can follow these steps.
Open Terminal and then execute ps command
sudo docker ps
This command will show any active Containers.
In the example above, my container name is cool_einstein. Now let’s execute the psql command. This command is commonly used to connect to the PostgreSQL Server to manage users, database, tables, and so on.
sudo docker exec -it cool_einstein psql -U gis
That’s it. I hope this short tutorial can give you a better understanding about how to run/install PostgreSQL Server on Apple Silicon Mac.