Skip to content

Instantly share code, notes, and snippets.

@gknauth
Created January 18, 2014 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gknauth/8495554 to your computer and use it in GitHub Desktop.
Save gknauth/8495554 to your computer and use it in GitHub Desktop.
#!/bin/bash
PGV=93
PGBIN=/opt/local/lib/postgresql${PGV}/bin
PGDEFDB=/opt/local/var/db/postgresql${PGV}/defaultdb
PGLOG=/opt/local/var/log/postgresql${PGV}/postgres.log
DBUSER=${USER}
## I had ALREADY used MacPorts to install the latest PostgreSQL server.
# sudo port -v selfupdate
# sudo port -v install postgresql${PGV}-server
echo initial database setup
sudo mkdir -p ${PGDEFDB}
sudo chown postgres:postgres ${PGDEFDB}
### added cd ${PGBIN} after reading: http://blog.mirotin.net/131/error-initialize-default-postgres-db
## if you want SQL-ANSI default encoding:
# sudo su postgres -c "cd ${PGBIN} && ./initdb -D ${PGDEFDB}"
## if you want UTF8 default encoding:
sudo su postgres -c "cd ${PGBIN} && ./initdb -E UTF8 -D ${PGDEFDB}"
echo start server
## If you want to run the server, log output to console, ^C to stop the server:
# sudo su postgres -c "${PGBIN}/postgres -D ${PGDEFDB}"
## If you want to run the server and have the log output go to a file:
sudo su postgres -c "cd ${PGBIN} && ./pg_ctl -D ${PGDEFDB} -l ${PGLOG} start"
echo setup automatic server start
sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql${PGV}-server.plist
echo remember to setup PATH in your .bashrc
echo example: "export PATH=${PGBIN}:\$PATH"
echo create dbuser to match OSX username
${PGBIN}/createuser --superuser ${DBUSER} -U postgres
echo to create a new db: ${PGBIN}/createdb dbname
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment