PostgreSQL is open-source RDBMS (Relational Database Management System) developed by the PostgreSQL Global Development Group. It’s ranked 4th following other DB (Oracle DB, MySQL and Microsoft SQL) and keep increasing. Here we’ll be looking into how to setup PostgreSQL on Mac and getting started with basic commands.
Note: Following installation process assume that PostgreSQL was never installed on your Mac.
PostgreSQL Installation
There are many ways to install PostgreSQL on Mac, however here will be using simple solution Postgres.app, go to Downloads, you can install whichever version you want, however to avoid compatibility issue, recommend downloading “Postgres.app with all currently supported versions”.
Path configuration
You can access PostgresSQL by ‘Open Postgres’ and double-clicking below DB icons or simply type psql
on terminal, however terminal way doesn’t work simple like that until path configuration is done.
Open terminal, type or copy those commands
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
Hit enter, admin password is required. Close the terminal and type psql
PostgreSQL basic commands
Now we have PostgreSQL, let’s try basics.
Create Database
Before we try playing with it, let’s create a new database.
On psql terminal window, CREATE DATABASE test
, to check if database is created type \l
and see.
Connect Database
Now we have new ‘test’ database created, let’s connect to it.
psql -h localhost -p 5432 -U USERNAME test
, make sure you type your username. If you’re already connected to psql session, you can change between database by \c test
Conclusion
Installing PostgreSQL with Postgres.app was simple and easy way to do, there are other ways like using Homebrew or MacPorts, however I find using Postgres.app was better in some ways.
This following series will be about Fundamentals of PostgreSQL with practice.