Skip to content

Installing PostgreSQL with MacPorts on OS X

Ans edited this page May 25, 2014 · 4 revisions

Installing PostgreSQL

  1. Install PostgreSQL with sudo port install postgresql93-server. This will install PostgreSQL 9.3.4, check the list of ports for installing a different release.
  2. Install pg gem with gem install pg -- --with-pg-config=/opt/local/lib/postgresql93/bin/pg_config if you're installing PostgreSQL for this project.
  3. Setting up the initial database
  • Make database directory with sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
  • Set permissions with sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
  • Create database with sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
  1. Start/Stop Server
  • First edit your shell environment with pico ~/.profile.
  • Add the following to that file and click control+x on the keyboard:
export PATH=/opt/local/lib/postgresql93/bin:$PATH

alias postgres_start='sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper start';
alias postgres_stop='sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper stop';
alias postgres_restart='sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql93-server/postgresql93-server.wrapper restart';
  • Now, reload the terminal window with . ~/.profile.
  • Finally, start the server with postgres_start or stop it with postgres_stop or restart it with postgres_restart.