Current revision: 0.8

Last update: 2024-01-12 12:51:22 +0000 UTC

The heaviest penalty for declining to rule is to be ruled by someone inferior to yourself.

Plato , The Republic - 380 B.C.

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.