Now that Amazon Web Services is supporting PostgreSQL I figured it’s about time I got around to getting it setup locally.
First step was to install PostgreSQL via MacPorts:
|# install and select|
|sudo port install postgresql93-server|
|sudo port select –set postgresql postgresql93|
|# load at startup|
|sudo port load postgresql93-server|
|# create the default database|
|sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb|
|sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb|
|sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'|
|# create a new user (or you can simply use the default user postgres which does not require a password)|
|createuser –superuser your_username -U postgres -P|
|# create a new database|
You should now be able to connect to your database using pgAdmin or a similar tool. If you’re having trouble, a quick reboot of your machine should get it working (assuming you set PostgreSQL to load at startup).
I also wanted to try out PostgresSQL Studio which requires Tomcat so that got installed next:
|sudo port install tomcat6|
|# add -Djava.awt.headless=true to /opt/local/share/java/tomcat6/bin/tomcatctl (line 65)|
|JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true"|
|# without this you’ll get this error in /opt/local/share/java/tomcat6/logs/catalina.err:|
|# 2013-11-16 23:39:17.389 jsvc[1698:203] Apple AWT Java VM was loaded on first thread — can't start AWT.|
|# Nov 16, 2013 11:39:17 PM org.apache.catalina.startup.Bootstrap initClassLoaders|
|# SEVERE: Class loader creation threw exception|
|# java.lang.InternalError: Can't start the AWT because Java was started on the first thread. Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line|
|# load at startup|
|sudo port load tomcat6|
Installing Tomcat led to a momentary headache as it would not start, throwing the following error – Apple AWT Java VM was loaded on first thread — can’t start AWT. All of the OS X / MacPorts / Tomcat instructions on Google were pretty out of date so it took a bit of digging to figure out what was going on. Luckily the fix was rather simple – just edit tomcatctl with the change shown in the Gist above.
The final step was to download PostgreSQL Studio, unzip the file and drop pgstudio.war into /opt/local/share/java/tomcat6/webapps/.
After a few moments Tomcat will autodeploy the war and you’ll be able to browse the application at http://localhost:8080/pgstudio/.