Installing PostgreSQL
There are several options for installing PostgreSQL onto your system. The following sections provide an overview of how to install postgreSQL. Choose an option that best suits your installation.
Installing PostgreSQL using apt-get
At this time, PostgreSQL 8.3 is required for SCInterface. By default, apt-get will install PostgreSQL version 8.3 (as of December 2009). Version 8.2 or earlier are not supported by SCInterface v2.2 or later. We highly recommend either installing from distro or installing from source.
Install PostgreSQL using cPanel
To install PostgreSQL on the same server that is running a cPanel server, complete the following:
- Login as root
- Type:
- cd /scripts/
- ./installpostgres
- cPanel will automatically install PostgreSQL using yum and initialize the database for you.
Install PostgreSQL using yum
Yum can be used to install PostgreSQL on a RedHat or CentOS platform. Run the following commands to get PostgreSQL installed with yum.
yum install postgresql postgresql-server postgresql-libs postgresql-devel /etc/rc.d/init.d/postgresql start
-OR-
yum install postgresql postgresql-server postgresql-libs postgresql-devel /etc/rc.d/init.d/postgresql initdb /etc/rc.d/init.d/postgresql start
Installing PostgreSQL from Distro
Each *nix distribution maintains package sources differently. Here is a quick list of ways to install PostgreSQL:
- Go to http://www.postgresql.org
- Click on the "downloads" tab at the top.
- Choose a mirror (FTP or HTTP is fine).
- Then, in the directories section, click on "binary", then the latest version (v.8.3 at the time of writing)
- The "linux", then "rpms", then "fedora" if you're using fedora, "redhat" if you're using redhat entreprise or CentOS
- Then click on the version that is more suitable for your release, CentOS 4.1 would choose rhel-es-4
- for those of you that use pgp signatures to validate the downloads : take the url that comes after PGP Key: and feed it to rpm --import (i.e. rpm --import http://www.gunduz.org/devrimgunduz.pgp.pub)
- Download and install the postgresql, postgresql-libs and postgresql-server packages. (and any other if they interest you)
Installing for PostgreSQL for CentOS 4
If these downloaded and installed successfully, next you will want to Test PostgreSQL Database Communication.
To confirm which RPM version you have installed, from the console type:
rpm -qa | grep postgres
Installing for PostgreSQL v8.3 for CentOS 4
Use yum to install by typing:
yum install postgres
Installing for PostgreSQL for CentOS 5
If these downloaded and installed successfully, next you will want to Test PostgreSQL Database Communication.
To confirm which RPM version you have installed, from the console type:
rpm -qa | grep postgres
Installing for PostgreSQL v8.3 for CentOS 5
Use yum to install by typing:
yum install postgres
Installing PostgreSQL from source
Make sure that the following is installed on your system:
- gcc
- gmake
- readline
- readline-devel
- zlib
- zlib-devel
Please reference your *nix operating system for instructions on installing these dependencies.
If you have not already done so, login as root to you SCM server and execute the following to retrieve the PostgreSQL tarball. This download assumes that we will be installing PostgreSQL v8.x. To get the complete URL, please visit: http://www.postgresql.org/ftp/source/
cd ~ wget ftp://ftp.postgresql.org/pub/source/v8.x.x/postgresql-8.x.x.tar.gz
If this tarball is not available, please go to http://wwwmaster.postgresql.org/download/ and locate a mirror that is the closest to your location. Or go to http://www.postgresql.org/ftp/source/.
From the same folder extract the postgresql-8.x.x.tar.gz by typing:
tar -xzvf postgresql-8.x.x.tar.gz
Next, we will need to go into the newly extracted directory to compile and configure PostgreSQL for your platform by typing:
cd <postgresql_tarball_directory>
where <postgresql_tarball_directory> is the directory of the recently extracted PostgreSQL source.
Finally, we will compile the source for PostgreSQL. The following was slightly modified directly from the PostgreSQL 8.2 Documentation.
./configure gmake su gmake install adduser postgres OR useradd postgres mkdir -p /usr/local/pgsql/data chown -R postgres /usr/local/pgsql su - postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data exit
Once finished with installing PostgreSQL, we need to Test PostgreSQL Database Communication.
Test PostgreSQL Database Communication
In order to test database connectivity, open up two shell (sh, csh, etc.). If installed using an RPM, type the following in the console window:
/etc/init.d/postgresql start
OR
If installed from source, type the following in the console window:
su - postgres /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
Use this first shell window to monitor the status of your PostgreSQL server. You will see something on the screen similar to this:
LOG: database system was shut down at 2006-03-08 08:17:42 EST LOG: checkpoint record is at 0/33A794 LOG: redo record is at 0/33A794; undo record is at 0/0; shutdown TRUE LOG: next transaction ID: 565; next OID: 10794 LOG: next MultiXactId: 1; next MultiXactOffset: 0 LOG: database system is ready
Within the second shell window, we will create a test database and test the connection into the database. To do this type:
/usr/local/pgsql/bin/createdb test /usr/local/pgsql/bin/psql test
If you have setup your PostgreSQL database successfully, the following will appear after invoking the psql command:
Welcome to psql 8.x.x, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
test=#
Type \q to exit from the console and close the second console window. Return back to the first console window and press CTRL-C to terminate the postmaster command.
You have successfully installed PostgreSQL and are now ready to install the SCM.
Installing PostgreSQL Libraries (libpqxx)
Before installing libpqxx, make sure you have installed PostgreSQL as indicated above. If you have not already done so, login as root and run the following:
cd ~ wget http://pqxx.org/download/software/libpqxx/libpqxx-2.6.9.tar.gz tar xzvf libpqxx-2.6.9.tar.gz cd ~/libpqxx-2.6.9 ./configure --prefix=/usr/local/pgsql make make install
Make sure that
This concludes installing the library dependency libpqxx.
Make sure libpq is in your library path
The following was used from the PostgreSQL documentation available at at http://www.postgresql.org/docs/8.2/interactive/install-post.html.
On some systems that have shared libraries (which most systems do) you need to tell your system how to find the newly installed shared libraries. The systems on which this is not necessary include BSD/OS, FreeBSD, HP-UX, IRIX, Linux, NetBSD, OpenBSD, Tru64 UNIX (formerly Digital UNIX), and Solaris.
The method to set the shared library search path varies between platforms, but the most widely usable method is to set the environment variable LD_LIBRARY_PATH like so: In Bourne shells (sh, ksh, bash, zsh)
LD_LIBRARY_PATH=/usr/local/pgsql/lib export LD_LIBRARY_PATH
or in csh or tcsh
setenv LD_LIBRARY_PATH /usr/local/pgsql/lib
Replace /usr/local/pgsql/lib with whatever you set --libdir to in step 1.
If in doubt, refer to the manual pages of your system (perhaps ld.so or rld). If you later on get a message like
psql: error in loading shared libraries libpq.so.2.1: cannot open shared object file: No such file or directorythen this step was necessary. Simply take care of it then.
If you are on BSD/OS, Linux, or SunOS 4 and you have root access you can run
/sbin/ldconfig /usr/local/pgsql/lib
(or equivalent directory) after installation to enable the run-time linker to find the shared libraries faster. Refer to the manual page of ldconfig for more information.
For more information, refer to section "14.6.1. Shared Libraries" at http://www.postgresql.org/docs/8.2/interactive/install-post.html for more info
Create a postgres startup script
The source installation will not automatically start on bootup. This is a requirement if you want the SCM to start when you bootup the machine. Postgres must be started before SCM.
Locate the file contrib/start-scripts/linux in the PostgreSQL source distribution. If you need to download the source, go to the section on installing PostgreSQL from source.
First, copy the linux startup script to /etc/rc.d/init.d
cp <postgres_source_dir>/contrib/start-scripts/linux /etc/rc.d/init.d/postgresql
make it executable
chmod 775 /etc/rc.d/init.d/postgresql
Make sure to add it to start for your runlevel. This varies from distro to distro. Typically for Redhat and Suse you will use 'chkconfig' and for Debian/Ubuntu 'update-rc.d'
chkconfig:
chkconfig --add postgresql chkconfig postgresql on
update-rc.d:
update-rc.d postgresql start 95 2 3 5
Starting PostgreSQL After Creating Startup Script
Type the following to start PostgreSQL if you completed the above steps:
/etc/rc.d/init.d/postgresql start
To check the status, type:
/etc/rc.d/init.d/postgresql status
Make sure the postgres tools are in your path
This is optional but highly recommended if you have installer issues
To do this, add the following to your shell start-up file, such as ~/.bash_profile (or /etc/profile, if you want it to affect every user):
PATH=/usr/local/pgsql/bin:$PATH export PATH
If you are using csh or tcsh, then use this command:
set path = ( /usr/local/pgsql/bin $path )
refer to section "14.6.2. Environment Variables" at http://www.postgresql.org/docs/8.2/interactive/install-post.html for more info