An easy way to install and manage PostgreSQL on Mac
Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac app. It includes everything you need to get started.
Installation
Download your version of PostgreSQL from here
The dmg
file comes with PostgreSQL
and postgresapp
GUI to manage.
Installation Directories
Binaries:
/Applications/Postgres.app/Contents/Versions/latest/bin
Headers:
/Applications/Postgres.app/Contents/Versions/latest/include
Libraries:
/Applications/Postgres.app/Contents/Versions/latest/lib
Default data directory:
~/Library/Application Support/Postgres/var-XX
(XX is the major version of PostgreSQL)
You can also view these directories using the postgresapp
GUI
Now you can connect with the server using psql
or your favourite GUI
tools:
There are many clients for PostgreSQL on the Mac. Below is a list of some of the Mac Apps I found (in alphabetic order).
If you need to provide an URL, use postgresql://
YOURUSERNAME@localhost
/YOURUSERNAME
OR with a password,
postgresql://YOURUSERNAME:
YOURPASSWORD@localhost
/YOURUSERNAME
Uninstalling
Quit Postgres.app & drag it to the Trash
Delete the data directory (default location:
~/Library/Application Support/Postgres
)Delete preferences for Postgres.app by executing the following command:
defaults delete com.postgresapp.Postgres2
Remove the
$PATH
config for the command line tools (optional):
sudo rm /etc/paths.d/postgresapp
Upgrading Major Version
When upgrading to a new major version of PostgreSQL, you need to migrate your data. The easiest way to migrate your data is using pg_dumpall, but there are alternative methods that can be useful when you have very large databases, or if you want to migrate only parts of the database.
Migrate data using pg_dumpall
This is the easiest way to migrate your data.
Make sure that the old server is running
Create a compressed SQL dump of your server (this could take some time):
pg_dumpall --quote-all-identifiers | gzip >postgresapp.sql.gz
Stop the old server, then start the new server.
Download and install the desired major version from here, during installation, choose replace
Now restore the SQL dump:
gunzip <postgresapp.sql.gz | psql
Don’t forget in
Server Settings..
to swap which server to start automatically