Next Previous Contents

6. PostgreSQL Quick-Installation Instructions

PostgreSQL is pronounced as Post-gres-cue-el (Postgres-QL) and not Postgre-es-cue-el.

This chapter will help you to install and run the database very quickly in less than 5 minutes.

6.1 Install and Test

Quick Steps to Install, Test, Verify and run PostgreSQL Login as root.


# cd /mnt/cdrom/RedHat/RPMS
# man rpm
# ls postgre*.rpm
# rpm -qpl postgre*.rpm | less (to see list of files)
# rpm -qpi postgre*.rpm (to see info of package)
# cat /etc/passwd | grep postgres

Note: If you see a 'postgres' user, you may need to backup and clean up the postgres home directory  postgres and delete the unix user 'postgres' or rename the unix user 'postgres' to something like 'postgres2'. Install must be "clean slate"
# rpm -i postgre*.rpm (Must install all packages clients, devel, data
         and main for pgaccess to work )
# man chkconfig
# chkconfig --add postgresql  (to start pg during booting)
# /etc/rc.d/init.d/postgresql start  (to start up postgres)
# man xhost
# xhost +  (To give display access for pgaccess)
# su - postgres
bash$ man createdb
bash$ createdb mydatabase
bash$ man psql
bash$ psql mydatabase
..... in psql press up/down arrow keys for history line editing or \s

bash$ export DISPLAY=<hostname>:0.0
bash$ man pgaccess
bash$ pgaccess mydatabase

Now you can start rapidly BANGING away SQL commands at psql or pgaccess.
bash$ cd /usr/doc/postgresql*

Here read all the FAQs, User, Programmer, Admin guides and tutorials.

6.2 PostgreSQL RPMs

See also "Installation Steps" from http://www.ramifordistat.net/postgres

The maintainer of PostgreSQL RPMs is Lamar Owen and is at lamar.owen@wgcr.org More details about PostgreSQL is at http://www.postgresql.org

6.3 Maximum RPM

Familiarize with RedHat RPM package manager to manage the PostgreSQL installations. Download the 'Maximum RPM' textbook from http://www.RPM.org look for the filename maximum-rpm.ps.gz And read it on linux using the gv command -


# gv maximum-rpm.ps.gz

There is also rpm2deb which converts the RPM packages to Debian linux packages.

6.4 Examples RPM

Examples are needed to do testing of various interfaces to PostgreSQL. Install the postgresql examples directory from -

6.5 Testing PyGreSQL - Python interface

Install examples package, see Examples RPM and then do -


bash$ cd /usr/lib/pgsql/python
bash$ createdb thilo
bash$ psql thilo
thilo=> create table test (aa char(30), bb char(30) );
thilo=> \q
bash$ /usr/bin/python
>>> import _pg
>>> db = _pg.connect('thilo', 'localhost')
>>> db.query("INSERT INTO test VALUES ('ping', 'pong')")
>>> db.query("SELECT * FROM test")
eins|zwei
----+----
ping|pong
(1 row)
>>>CTRL+D
bash$
..... Seems to work - now install it properly
bash$ su - root
# cp /usr/lib/pgsql/python/_pg.so /usr/lib/python1.5/lib-dynload

6.6 Testing Perl - Perl interface

Install examples package, see Examples RPM and then do -


root# chown -R postgres.postgres /var/lib/pgsql/examples
bash$ cd /var/lib/pgsql/examples/perl5
bash$ perl ./example.pl

Note: If the above command does not work then do this. Gloabl var @INC should include the Pg.pm module in directory site_perl hence use -I option below
bash$ perl -I/usr/lib/perl5/site_perl/5.005/i386-linux-thread ./example.pl

.... You ran the perl which is accessing PostgreSQL database!!

Read the example.pl file for using perl interface.

6.7 Testing libpq, libpq++ interfaces

Install examples package, see Examples RPM and then do -


root# chown -R postgres.postgres /var/lib/pgsql/examples
bash$ cd /var/lib/pgsql/examples/libpq
bash$ gcc testlibpq.c -I/usr/include/pgsql -lpq
bash$ export PATH=$PATH:.
bash$ a.out

bash$ cd /var/lib/pgsql/examples/libpq++
bash$ g++ testlibpq0.cc -I/usr/include/pgsql -I/usr/include/pgsql/libpq++
-lpq++ -lpq -lcrypt
bash$ ./a.out  (Note: Ignore Error messages if you get any - as below)
> create table foo (aa int, bb char(4));
No tuples returned...
status = 1
Error returned: fe_setauthsvc: invalid name: , ignoring...
> insert into foo values ('4535', 'vasu');
No tuples returned...
status = 1
Error returned: fe_setauthsvc: invalid name: , ignoring...
> select * from foo;
aa   |bb   |
-----|-----|
4535 |vasu |
Query returned 1 row.
>
>CTRL+D
bash$

.... You ran direct C/C++ interfaces to PostgreSQL database!!

6.8 Testing Java interfaces

Install examples package, see Examples RPM and also install the following -


root# chown -R postgres.postgres /var/lib/pgsql/examples
bash$ cd /var/lib/pgsql/examples/jdbc
bash$ echo $CLASSPATH
 --> Should show  
CLASSPATH=/usr/lib/pgsql/jdbc7.0-1.2.jar:.:/home/java/jdk1.2.2/lib:/usr/lib/pgsql:/usr/lib/pgsql/classes.zip:/usr/lib/pgsql/pg.jar  

with proper jdbc*.jar version numbers.
And the directories /usr/lib/pgsql and /usr/libjdk*/lib should contain *.jar files.

bash$ export CLASSPATH=/usr/lib/pgsql/jdbc7.0-1.2.jar:.:/home/java/jdk1.2.2/lib:/usr/lib/pgsql:/usr/lib/pgsql/classes.zip:/usr/lib/pgsql/pg.jar  

Edit all psql.java file  and comment out the 'package' line.
bash$ javac psql.java
bash$ java psql jdbc:postgresql:template1 postgres < password >   
[1] select * from pg_tables;
tablename       tableowner      hasindexes      hasrules
pg_type postgres        true    false   false
pg_attribute    postgres        true    false   false
[2]
CTRL+C
bash$

.... You ran direct Java interfaces to PostgreSQL database!

6.9 Testing ecpg interfaces

Install examples package, see Examples RPM and then do -


root# chown -R postgres.postgres /var/lib/pgsql/examples
bash$ cd /var/lib/pgsql/examples/ecpg
bash$ ecpg test1.pgc -I/usr/include/pgsql
bash$ cc test1.c -I/usr/include/pgsql -lecpg -lpq -lcrypt
bash$ createdb mm
bash$ ./a.out

.... You ran Embedded "C"-SQL to PostgreSQL database!

6.10 Testing SQL examples - User defined types and functions

Install examples package, see Examples RPM and then do -


root# chown -R postgres.postgres /var/lib/pgsql/examples
bash$ cd /var/lib/pgsql/examples/sql
Under-development..

6.11 Testing Tcl/Tk interfaces

Example of Tcl/Tk interfaces is pgaccess program. Read the file /usr/bin/pgaccess using an editor -


bash$ view /usr/bin/pgaccess
bash$ export DISPLAY=<hostname of your machine>:0.0
bash$ createdb mydb
bash$ pgaccess mydb

6.12 Testing ODBC interfaces

  1. Get the win32 pgsql odbc driver from http://www.insightdist.com/psqlodbc/
  2. See also /usr/lib/libpsqlodbc.a

6.13 Testing MPSQL Motif-worksheet interfaces

Get the RPMs from http://www.mutinybaysoftware.com

6.14 Verification

To verify the top quality of PostgreSQL, run the Regression test package :- Login as root -


# rpm -i postgresql*test.rpm
And see README file or install the source code tree which has regress directory
# rpm -i postgresql*.src.rpm
# cd /usr/src/redhat/SPECS
# more postgresql*.spec   (to see what system RPM packages you need to
install)
# rpm -bp postgresql*.spec  (.. this will prep the package)

Regression test needs the Makefiles and some header files like *fmgr*.h
which can be built by -
# rpm --short-circuit -bc postgresql*.spec ( .. use short circuit to
bypass!)
Abort the build by CTRL+C, when you see 'make -C common  SUBSYS.o'
By this time configure is successful and all makefiles and headers
are created. You do not need to proceed any further
# cd /usr/src/redhat/BUILD
# chown -R postgres postgresql*
# su - postgres
bash$ cd /usr/src/redhat/BUILD/postgresql-6.5.3/src/test/regress
bash$ more README
bash$ make clean; make all runtest
bash$ more regress.out

6.15 Emergency Bug fixes

Sometimes emergency bug fix patches are released after the GA release of PostgreSQL. You can apply these optional patches depending upon the needs of your application. Follow these steps to apply the patches - Change directory to postgresql source directory

                # rpm -i postgresql*.src.rpm
                # cd /usr/src/postgresql6.5.3
                # man patch
                # patch -p0 < patchfile
                # make clean
                # make
The patch files are located in
Next Previous Contents