Skip to content

Install PostgreSQL on FreeBSD 8.2 and make it work with Django

2012 January 22
tags:
by Richard Knop

Follow up on my previous two blog posts:

I am going to write down installation steps for PostgreSQL on FreeBSD 8.2 so it can be used with django.db.backends.postgresql_psycopg2 adapter.

#cd /usr/ports/databases/postgresql91-server
#make
#make install

Add this line to /etc/rc.conf:

postgresql_enable="YES"

Next, initialize a PostgreSQL database cluster:

#/usr/local/etc/rc.d/postgresql initdb

Now add this line to /usr/local/pgsql/data/postgresql.conf:

listen_addresses = '*'

Thirdly, add this line to /usr/local/pgsql/data/pg_hba.conf:

host   all   all   127.0.01/32 md5

Reboot. Now let’s create a new user for our PostgreSQL database:

#su pgsql
$ createuser -sdrP username
Enter password for new role: ******
Enter it again: ******

$ exit

Finally, we need to install psycopg2 client in order to be able to connect to the PostgreSQL server from a Django web application.

#pip install psycopg2
#/usr/local/sbin/apachectl restart

Cool. Now you should be able to connect to the PostgreSQL server from your Django app. Make sure to create a database first:

#su pgsql
$ createdb myapp
$ exit

Now go to your Django application folder and edit settings.py. Use django.db.backends.postgresql_psycopg2 as ENGINE, also set NAME, USER and PASSWORD fields. Reload the Django app in the browser and it should work fine.

3 Responses leave one →
  1. Bill permalink
    February 16, 2012

    Another very useful tutorial, thanks Richard!

    Note typo in IP address: 127.0.01/32

    See the FreeBSD Wiki (http://wiki.freebsd.org/Jails) for information on making PostgreSQL work in a Jail

    Bill

Trackbacks and Pingbacks

  1. PostgreSQL chear sheet | Zend Framework Blog
  2. Django missing admin CSS stylesheets | Zend Framework Blog

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS