Sunday, November 27, 2011

Installing PostgreSQL on FreeBSD


This post describes the steps required to complete the initial configuration of PostgreSQL DBMS with 32KB block-size [By default block size is 8KB] on a system running on FreeBSD.


Step1: Download latest PostgreSQL Source module from www.Postgresql.org

# wget http://wwwmaster.postgresql.org/download/mirrors-ftp/source/v9.0.5/postgresql-9.0.5.tar.bz2

Step 2: Install PostgreSQL 9.0.5

# bunzip2 postgresql-9.0.5.tar.bz2

# tar -xvf postgresql-9.0.5.tar

# ./configure --prefix=/usr/local/pgsql90/ --with-blocksize=32 --with-wal-blocksize=32 --enable-thread-safety --with-includes=/usr/local/include --with-libraries=/usr/local/lib --with-openssl --enable-integer-datetimes --enable-nls --with-perl --with-libxml --with-ossp-uuid

# make

# make install

Step 3: Verify the PostgreSQL directory structure

After the installation, make sure bin,include,lib and share directories are created under the /usr/local/pgsql90 directory.


Step 4: Create PostgreSQL Data directory

Create the postgres data directory and make pgsql user as the owner.

#mkdir /export/raid/pgsql/data90

#chown pgsql:pgsql /export/raid/pgsql/data90

#chmod 700 /export/raid/pgsql/data90

Step 5: Initialize PostgreSQL data directory

Before you can start creating any PostgreSQL database,the empty data directory created in the above step should be initialized using the initdb command as shown below

# /usr/local/pgsql90/bin/initdb -D /export/raid/pgsql/data90 -X <pg_xlog directory>

Step 6: Validate the PostgreSQL Data directory


Step 7: Set environment variable according to PostgreSQL 9.0 in .bash_profile located under “pgsql” user home directory.


#!/bin/sh
# The script sets environment variables helpful for PostgreSQL

export PATH=/usr/local/pgsql90/bin:$PATH
export PGDATA=/export/raid/pgsql/data90
export PGDATABASE=postgres
export PGUSER=pgsql
export PGPORT=5432

Step 8: Start PostgreSQL Database

Use the Postgre postmaster command to start the postgreSQL server in the background as shown below

$/usr/local/pgsql90/bin/pg_ctl -D /export/raid/pgsql/data90 start -o "-p 5432"