This recipe shows how to encrypt data using the pgcrypto package.
Make sure you (or your database server) are in a country where encryption is not illegal—it still is in some countries.
Make sure pgcrypto is installed on your database host. On Ubuntu, it comes in package postgresql-contrib.
Install it into the database in which you want to use it:
psql mydb < /usr/share/postgresql/8.4/contrib/pgcrypto.sql
You also need to have GPG keys set up:
pguser@laptop:~$ gpg --gen-key
Answer some questions here, select key type "DSA and Elgamal", and enter an empty password.
Now export the keys:
pguser@laptop:~$ gpg -a --export "PostgreSQL User (test key for PG Cookbook) <email@example.com>" > public.key pguser@laptop:~$ ...