PostgreSQL on Mac OS X
Step-by-step instructions
PostgreSQL is an open source object-relational database. It is a popular database choice when using a relational database.
Installing PostgreSQL on Mac OS X is simple.
Software versions
The instructions in this post were created / tested using the following sofware versions:
- Mac OS X Yosemite 10.10
- HomeBrew 0.9.5
- PostgreSQL 9.4
Install PostgreSQL via Brew
First, we will update Brew and then install PostgreSQL.
brew update
brew install postgres
Start PostgreSQL
Start the PostgreSQL server in the foreground. There are optional instructions below in case you would like to start PostgreSQL automatically.
Brew initializes the database during installation.
postgres -D /usr/local/var/postgres
Login to PostgreSQL for the first time.
Press
Cmd + T
to open a new terminal tab.whoami is surrounded by backticks, not single quotes.
createdb `whoami`
Login to PostgreSQL with your user account.
psql
Optional: Install AdminPack
AdminPack is used by PgAdmin. If you plan on using the PgAdmin UI, then installing AdminPack is a good idea.
psql postgres -c 'CREATE EXTENSION "adminpack";'
Optional: Configure PostgreSQL to start automatically
The commands below configure PostgreSQL to start automatically.
mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Summary
Congrats. PostgreSQL is now installed on Mac OS X. You are now ready to start using PostgreSQL for development.
------------------------------
install log:
➜ ~ brew install postgres==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.5.0.el_capitan.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.5.0.el_capitan.bottle.1.tar.gz
==> /usr/local/Cellar/postgresql/9.5.0/bin/initdb /usr/local/var/postgres
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.5) of PostgreSQL, see:
https://www.postgresql.org/docs/9.5/static/upgrading.html
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
==> Summary
🍺 /usr/local/Cellar/postgresql/9.5.0: 3,113 files, 35.0M
Comments
Post a Comment