Below are the procedures to install and configure Postgresql on mac using home-brew (Currently Postgresql 9.6.1)
- Update Homebrew using command
$ brew update
- Install postgresql
$ brew install postgresql
- Initialize the database
$ initdb /usr/local/var/postgres/
- Start the database server
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
$ pg_ctl -D /usr/local/var/postgres/ -l logfile start
- Create the database
$ created nameOfYourDatabase
- Start the database
$ psql nameOfYourDatabase
- Stop a database server
pg_ctl -D /usr/local/var/postgres stop -s -m fast
Using a LaunchAgent and plist to Launch PostgreSQL on Startup:
- Create a directory for LaunchAgents (usually created by default)
$ mkdir -p ~/Library/LaunchAgents
- Create symbolic link from launchAgents to Postgresql
$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
- Load the symbolic link file
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Notes:
When creating a new database system, either remove or empty
the directory /usr/local/var/postgres
, or run initdb
with an argument other than /usr/local/var/postgres
.
Reference:
* install PostgreSQL 9 in Mac OSX via Homebrew
* Install PostgreSQL on Mac OS X via Brew
* How to Start PostgreSQL Server on Mac OS X