09 January 2008

Learning PL/pgSQL - SQL Procedural Language

I am working on my first project with Postgres and there are a couple of stuff I wanted to document:

To install PL/pgSQL which is not installed by default (!), execute the SQL command on your db:

CREATE LANGUAGE plpgsql;
Otherwise you will get the error message: "ERROR: language "plpgsql" does not exist" ...


Another surprising missing feature is the inability to connect to other databases. It's not included by default in Postgres but seats in the postgres/contrib project within the funcion dblink.

To install it on ubuntu:

sudo apt-get -y install postgresql-8.2 postgresql-contrib



That's not finished! You have to run the script manually to install it.

psql -U postgres your_database_name < /usr/share/postgresql/8.2/contrib/dblink.sql

02 January 2008

Import / Export a postgres db

postgres is the database user. On ubuntu, you should run this command as the user "postgres": su postgres (password by default is 'password' !)

Dump a database into a sql script:

pg_dump database_name -Upostgres -W > ~/dump_script.sql

Restore the database from sql script:

psql -U postgres database_name -f - < dump_script.sql

01 January 2008

21 croissants daily post 01/01/2008

Ruby on Rails: Testing without the database

  • Unit Test = to test our code, not the class under test dependencies. Testing without the DB is also a good way of accelerating tests