Convalesco

Current revision: 0.11

Last update: 2026-05-29 12:46:21 +0000 UTC

Anti-intellectualism has been a constant thread winding its way through our political and cultural life, nurtured by the false notion that democracy means that "my ignorance is just as good as your knowledge".

I. Asimov


Macports and PostgreSQL

Date: 03/06/2015, 18:17

Category: technology

Revision: 1



I chose to go with PostgreSQL as my default DB for my next Rails project. In order to use PostgreSQL with MacPorts, all you need the following:


$ sudo port install postgresql92-server
$ sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
$ sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb
$ sudo su postgres -c '/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql922/defaultdb'
$ sudo port load postgresql92-server

Now postgreSQL will start at boot. You don’t have to manually start/stop the database anymore. In order to use a newer version, e.g. postgresql93-server, just change the version numbers.

When you first create install the database, only the user postgres will be available. I like to create a role with my username. To do that under OSX issue the following commands:


$ psql -U postgres
postgres=# CREATE ROLE atma;
postgres=# ALTER ROLE <username> WITH LOGIN CREATEDB;
postgres=# \q

Now you can create new databases using your username as role via command line using the createdb command:


$ createdb my_dev_db

Now you can add the relevant info to your application.