Wednesday, September 7, 2011

Adding UUID generation support in Postgresql (uuid_ossp)

UUID generation support can be added in postgres by adding the third party module called 'uuid_ossp'.  I will explain the step to follow in ubuntu 10.04 LTS with postgres 9.0.4.

1) Add the uuid_ossp library to your system (If it is not there). This can be done by downloading the latest source from 'http://www.ossp.org/pkg/lib/uuid/.

2)  Check the postgres version by psql -V
3) Check whether the contrib support is there in postgres installation.

This can be done by checking for the "contrib" directory in /usr/share/postgresql/9.0

If it is not there add the contrib support by using the following command.

apt-get install postgresql-contrib-9.0

Now check for the contrib directory.

The UUID_OSSP support can be added to each database using the following command.

psql -d <database> -U <user> -f /usr/share/postgresql/9.0/contrib/uuid-ossp.sql

You can verify the UUID support by running the following query.


select uuid_generate_v1mc()

Enjoy the time with postgres :)