lunedì 29 ottobre 2012

Using Json on a Ubuntu 12.04 server with Postgresql 9.1

The plv8js raised lots of curiosity close to the Postgresql community. So I decided to try it on my Ubuntu server (12.04) running Postgresql 9.1 db. I know that newer Postgresql 9.2 comes with that library, but I want test it on well tested released. So first of all I assume you have already installed Postgresql, make and g++ packages, so now install:

$sudo apt-get install libv8-3.7.12.22 libv8-dev 

which is, at the moment I write, the lastest libv8 release packaged. After that download

$sudo wget https://plv8js.googlecode.com/files/plv8js-20120719.tar.gz

Compile and install the library

$sudo tar zxvf plv8js-20120719.tar.gz
$cd plv8js
$sudo make
$sudo make install

After that the file plv8.so is placed inside the directory /usr/lib/postgresql/9.1/lib, while
plv8.control and plv8--1.1.0.sql are placed inside the directory /usr/share/postgresql/9.1/extension

To make sure all is correclty installed and working, it is a good idea do a quick test.
Supposing we have already created a database called PGV8 we can use the psql command line:
 
$ sudo -s -u postgres 
postgres$ createlang -d PGV8 plv8 
 
in order to enable plv8 language, and
 
postgres$ sudo psql -d PGV8 -c "CREATE EXTENSION plv8"
 
in order to register the plv8 stored procedure.
If no errors are displayed, our database is ready to take advantage of this
new feauture.
Posta un commento