You can use the Perl utility called cpan to install the Pg module. We will not cover cpan in its entirety. Details on configuring and using cpan is beyond the scope of this document.


You need to have the Pg module installed on both the master and slave machine.

Step 1: Set environment variables

You need to set the environment variables POSTGRES_INCLUDES and POSTGRES_LIB to the include and lib directory. The command below will set them to the correct path:

   POSTGRES_INCLUDE = /usr/local/pgsql/include
   POSTGRES_LIB = /usr/local/pgsql/lib

Step 2: Create root user

A root user is required when installing the Pg module because the cpan utility will run some tests as the root user. You can disable these tests, but this document will not cover how to do so.

Log in as your postgres superuser and create a root database user. Use the command:

   su - postgres
   createuser root

Warning Creating a PostgreSQL root user

Normally, you shouldn't create a PostgreSQL root user. However, to install the Pg module requires some tests that run as the root user. To close any security holes that may occur from creating a PostgreSQL root user, you should closely follow all of the steps outlined in this section. Especially step 4, which is removing the PostgreSQL root user.

It will ask you what type of permission should this user have. You should specify the PostgreSQL root user to only have permission to create databases but not be able to create users.

Step 3: Using cpan to install the Pg module

Start the cpan process by using the command:


You can now use the command below to install the Pg module. It will take a few minutes to install.

   install Pg

Once it has finished running, the last line should display the message:

  /usr/bin/make install  -- OK

You can exit the cpan program by typing:


Step 4: Removing the PostgreSQL root user

It is important that you drop the PostgreSQL user named root after the installation process has completed. It is not necessary to give a root user access to the PostgreSQL database because it is a security concern. Use the command:

   dropuser root