PostgreSQL installation on Mac M1 chip

YaLinChen (Amber)
3 min readJul 8, 2022
Source: Unsplash

To install PostgreSQL on Mac OS system, typically, we go to the “terminal”, install homebrew, and install PostgreSQL with homebrew. But if you are using M1 chip, you probably will get this error.

“Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!”

Here is a solution to the installation.

We first install rosetta and install homebrew with rosetta (for more information, please see this stackoverflow thread)

/usr/sbin/softwareupdate --install-rosetta --agree-to-licensearch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Now, we use homebrew to install postgreSQL. Upgrade the homebrew and then to the installation.

arch -x86_64 brew upgrade
arch -x86_64 brew install postgresql

After the successful installation, we can start using PostgreSQL.

psql -U postgres

This command will initiate you as a “super user” and has the credentials to manage all SQL databases in the server (for example, your computer).When asked for “Password for user postgres:”, enter “postgres” to be a “super user”.

Server/Super user and Client

PostgreSQL, like other database management systems, include this concept of “server/super user and client”. A super user is a role which is set up by default when you install PostgreSQL and has credentials to manage all the databases in the server (for example, if you are doing this project on your own computer, then your computer is the server and you are the super user). A super user can manage and create databases and users with password assignment. Users will be assigned to particular databases by the super user, which is also called “access control”.

A client is anyway who has been created as a user in a certain PostgreSQL system with its user ID and password and access to databases. Therefore, a client does not have to use the same computer the super user is using and should be able to access to the database anywhere with internet conncections. They are clients as they can view, query, and manipulate data only in the database they are allowed to access.

Commands for super users

List all the databases in the server

\l

Create a user with access to a database

You create a user named “pg4e” with the password “secret”.

CREATE USER pg4e WITH PASSWORD 'secret';

You create a database called “people” accessible to the user “pg4e”.

CREATE DATABASE people WITH OWNER 'pg4e';

And so now, the user, which is a client, can access to the database “people” by connecting with the port (if the client is using a different computer) and with the password “secret”.

Commands for users

First, you will have to quit the super user mode.

\q

Then you access the server as a user.

psql people pg4e

\dt :check tables/relations in the database

What’s next

The goal of this post is to set up the PostgreSQL environment on M1 chip. More codes of SQL language such as insert, delete, select, etc., will be covered in future posts.

--

--