This document provides instructions on how to setup postgresql locally on your mac using two methods, the first being through pgAdmin4 and the second being through the psql shell. Below please find an overview of what is covered in this document:
- Downloading Postgresql and PgAdmin
- Creation of a user in Postgresql
- Creation of a database with owner of "user" in Postgresql
- Instructions on how to see tables in your database
- Instructions on how to create tables in your database
- Instructions on how to delete tables in your database
To be able to setup Postgresql locally we first need to download it. First we check to see if we already have Postgresql installed by running: psql --version in the command line. This would return the version of Postgres if you have it installed already, if you already have Postgresql installed and don't want to use PgAdmin then please move onto the next section. If not continue reading.
To Install Postgresql we will be using an interactive installer that can be found on Postgres's website. Click the "Download the installer" link under the Interactive installer by EDB section. (NOTE: The installer is by EDB, and will redirect you to another site)
After arriving to the site you can click the download icon for Mac OS X for your desired version of Postgresql. This will install the interactive installer on your computer, which includes postgres and pgAdmin4. Image below:
Now you should have a .dmg file in the download folder, open it and follow the steps in their installer. NOTE: Make sure you select PostgreSQL Server and select pgAdmin and/or Command Line Tools in the "select Components" page based on your preference. I suggest to select all of the options as they are all pretty useful.
The port number of the server can be anything, but default is 5432.
Now that you have Postgresql successfully installed, here are steps to create a new user:
- Launch up PgAdmin4
- Insert the password you used in the installer in the previous section.
- In the tab on the left side of the screen, go to
Servers > Your wanted server (Default is PostgreSQL 15) > Login/Group Roles - Right click and select the
Create > Login/Group Roleoption - You can insert the information you want for the User, click the Save option and you're done!
Note that you area also able to set a password for the user and even superuser priviledges.
- Open up the Mac Terminal
- Run
sudo -u postgres psqlto open up the Postgresql Shell using the default postgres user - Insert the password you used in the installer in the previous section
- If successful you should see that the prompt for the terminal looks something like this:
postgres=# - Now to create a new user write
CREATE USER your_users_name; - A prompt will show to insert password for the user, after setting the password you're done!
Note that if you want to create a superuser you can use CREATE USER your_users_name SUPERUSER; instead in step 5.
More information and additional methods can be found here: How to create a Postgres User
Now that you have a custom user, you can now create a database!
- Launch the app and insert your passwords
- In the tab on the left side of the screen go to
Servers > Your wanted server (Default is PostgreSQL 15) > Databases - Right click and select the
Create > Database...option - Insert the name of the database in
Databasefield - If you want to change the Owner to your created owner, you can aswell in the
Ownerfield
- Open up the Mac Terminal
- Run
sudo -u postgres psqlto open up the Postgresql Shell using the default postgres user and insert password - Now to create a new database write
CREATE DATABASE database_name;
Note that this makes the owner of database_name as the default postgres user. You can specify the owner by using CREATE DATABASE database_name OWNER your_users_name;
You can also find more information here: Postgresql Database: CREATE
This section is about how to see tables and what they contain in your Postgres database. I will be using database_name as a placeholder for your database name, and wanted_table for the table you want to inspect.
- Launch the app and insert your passwords
- In the tab on the left side of the screen go to
Servers > Your wanted server (Default is PostgreSQL 15) > Databases > database_name > public > Tables - Now you see a list of the existing tables.
- To see the columns in the
wanted_table, find it in the list of tables, click on it to expand its options, and click theColumnsoption. This shows all the attribute names for the table.
- Open up the Mac Terminal
- Run
sudo -u postgres psqlto open up the Postgresql Shell using the default postgres user and insert password - You can use
\listto see the databases you have, postgres usually comes with the default databases "postgres", "template0" and "template1" - Now to view the tables in
database_nameyou need to first run\c database_nameto connect to it - If successful your shell prompt should look like the following:
database_name=# - Now to show all tables you have, you can run
\dt - To see the columns of the table you can run
\d wanted_table
You can also find more information here: How to List Databases and Tables in PostgreSQL Using psql and PostgreSQL Describe Table
This section is about how to create tables in your Postgres database. I will be using database_name as a placeholder for your database name, and wanted_table for the table you want to want to create.
- Launch the app and insert your passwords
2 In the tab on the left side of the screen go to
Servers > Your wanted server (Default is PostgreSQL 15) > Databases > database_name > public > Tables3.Right clickTablesand selectCreate > Table...and create your table
- Open up the Mac Terminal
- Run
sudo -u postgres psqlto open up the Postgresql Shell using the default postgres user and insert password - Navigate to your database using
\c database_name - Use Postgresql syntax
CREATE TABLE wanted_table(... attributes ...);to create the table
You can also find more information here: Different methods to create a table in PostgreSQL
This section is about how to delete a table in your Postgres database. I will be using database_name as a placeholder for your database name, and wanted_table for the table you want to want to delete.
- Launch the app and insert your passwords
2 In the tab on the left side of the screen go to
Servers > Your wanted server (Default is PostgreSQL 15) > Databases > database_name > public > Tables3 Find and right clickwanted_tableand clickDelete/Dropand you're done!
- Open up the Mac Terminal
- Run
sudo -u postgres psqlto open up the Postgresql Shell using the default postgres user and insert password - Navigate to your database using
\c database_name - Use Postgresql syntax
DROP TABLE wanted_table;to delete the table
You can also find more information here: How to drop a table in PostgreSQL

