Convalesco

Current revision: 0.4

Last update: 2017-03-22 18:42:09 +0200 UTC

Tact is the art of making a point without making an enemy.

I. Newton


Macports and PostgreSQL

Date: 03/06/2015, 18:17

Category: technology



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.