Links: Homepage | Downloads | Documentation
Dependencies: None
Version: 9.4.4

PostgreSQL is an enterprise-class, open source object-relational database system. It has been in active development for more than 15 years and has a strong reputation for standards compliance, reliability and data integrity.

Get the Code

Switch to /usr/local/src and download the source package.

cd /usr/local/src
curl --remote-name

Extract the archive and move into the folder.

tar -xzvf postgresql-VERSION.tar.gz
cd postgresql-VERSION

Compile and Install

Configure, compile and install into /usr/local/postgresql-VERSION.

./configure --prefix=/usr/local/postgresql-VERSION
make world
make install-world

Create a symbolic link that points /usr/local/postgresql to /usr/local/postgresql-VERSION.

ln -s postgresql-VERSION /usr/local/postgresql


Execute the following lines to update your Bash startup script.

echo 'export PATH=/usr/local/postgresql/bin:$PATH' >> ~/.bash_profile
echo 'export MANPATH=/usr/local/postgresql/share/man:$MANPATH' >> ~/.bash_profile

Load the new shell configurations.

source ~/.bash_profile


Create a folder that will contain your databases. My databases are located in /usr/local/var/postgresql. You can place your databases wherever you'd like but make sure you update the path when mentioned in this article.

mkdir -p /usr/local/var/postgresql


If you are copying the data from a former PostgreSQL installation, you can skip this step. You may have to upgrade your database in some circumstances (like 9.3.x to 9.4.x). Check the documentation.

Initialize your database installation.

initdb --pgdata=/usr/local/var/postgresql

Manual Start/Stop

To start the PostgreSQL server.

pg_ctl -D /usr/local/var/postgresql start

To stop the PostgreSQL server.

pg_ctl -D /usr/local/var/postgresql stop

Automatically Start the Server at Boot

Create a configuration file for Launchd.

nano ~/Library/LaunchAgents/org.postgresql.postgres.plist

Copy and paste the following text into the aforementioned file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">




Register with Launchd and start the server.

launchctl load ~/Library/LaunchAgents/org.postgresql.postgres.plist

Deregister with Launchd.

launchctl unload ~/Library/LaunchAgents/org.postgresql.postgres.plist

Verify the Installation

Verify that you have successfully installed PostgreSQL.

postgres --version

Show a list of available databases (the server has to be running).

psql -l