nedeľa 6. septembra 2009

How to install PostgreSQL module for Python

How to install psycopg2?

On Ubuntu Linux (9.04):
sudo apt-get install python-psycopg2

On Mac OS X (Leopard) - valid for PostgreSQL 8.4:
export PATH="/Library/PostgreSQL/8.4/bin:$PATH"
sudo easy_install -U setuptools
sudo easy_install psycopg2

In case of problems, install PostgreSQL first. Don't know how? Don't worry, it is pretty straightforward. For example on Linux, but also on Mac OS X or Windows.

sobota 5. septembra 2009

How to install and configure PostgreSQL server on Ubuntu Linux 9.04

Installation

sudo apt-get install postgresql

Create database

sudo su postgres
psql
postgres=# CREATE DATABASE dsbis_db WITH ENCODING 'utf-8';

where dsbis_db is database name.

Create database user

postgres=# CREATE ROLE dsbis_db_user LOGIN PASSWORD 'ojweod30';
postgres=# ALTER DATABASE dsbis_db OWNER TO dsbis_db_user;

Configure host-based authorization

If you need e.g. allow remote access to this database, you need to edit this configuration file: /etc/postgresql/8.3/main/pg_hba.conf.

To be able to connect locally with your newly added database user, add this line:
local all all md5
possibly as replacement of this line:
local all all ident sameuser
if you do not want to allow connecting to database to all local users of your Linux system.

Restart database server

sudo /etc/init.d/postgresql-8.3 restart

NOTE: Now, you can set your newly created database login/password in your application settings and it should work. But remember, that if you application resides on another host, probably you will need to allow connections from it in pg_hba.conf (see section above, about host baset authorization).