Next Previous Contents

5. PostgreSQL Quick-Steps

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

5.1 Install and Test

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


# rpm -qpl postgre*.rpm (to see list of files. For docs 'man rpm')
# 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 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 )
# chkconfig --add postgresql  (to start pg during booting, see 'man
chkconfig')
# cp /usr/lib/pgsql/python/_pg.so /usr/lib/python1.5/lib-dynload (for
python)
# /etc/rc.d/init.d/postgresql start  (to start up postgres)
# su - postgres
bash$ createdb mydatabase  (this will create a database by name
'mydatabase')
                 (for doc 'man createdb')
bash$ psql mydatabase   (for doc 'man psql')
..... in psql press up/down arrow keys for history line editing or \s
bash$ export DISPLAY=<hostname>:0.0; pgaccess mydatabase; (see 'man
pgaccess')

Now you can start banging away at SQL commands at pgaccess or psql !!
bash$ cd /usr/doc/postgresql*

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

5.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

5.3 Maximum RPM

Download the 'Maximum RPM' textbook from http://www.RPM.org the filename is maximum-rpm.ps.gz And read it on linux using gv command -


# gv maximum-rpm.ps.gz

5.4 Testing PyGreSQL - Python interface


bash$ cd /usr/lib/pgsql/python
bash$ createdb thilo
bash$ psql thilo
thilo=> create table test (aa char(30), bb char(30) );
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$
..... Yow! Seems to work - now install it properly
bash$ su - root
# cp /usr/lib/pgsql/python/_pg.so /usr/lib/python1.5/lib-dynload

5.5 Testing Perl - Perl interface


bash$ cd /usr/doc/postgresql-6.5.3/examples/perl5

Note: 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.004/i386-linux-thread ./example.newstyle

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

Read the example files for using perl interface

5.6 Testing libpq, libpq++ interfaces


bash$ cd /usr/doc/postgresql-6.5.3/examples/libpq++
bash$ su root   --> to change ownership of examples
# chown -R postgres /usr/doc/postgresql-6.5.3/examples
# exit
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$

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

5.7 Testing Java interfaces

For this you MUST install the jdk-*glibc*.rpm package (Java RPM packages)


bash$ cd /usr/doc/postgresql-6.5.3/examples/jdbc
bash$ echo $CLASSPATH
 --> Should show  CLASSPATH=/usr/lib/jdk-1.1.6/lib/classes.zip
bash$ export CLASSPATH=$CLASSPATH:.:/usr/lib/pgsql/postgresql.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$

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

5.8 Testing ecpg interfaces


bash$ cd /usr/doc/postgresql-6.5.3/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

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

5.9 Testing SQL examples - User defined types and functions


bash$ cd /usr/doc/postgresql-6.5.3/examples/sql
Under-development..

5.10 Testing Tcl/Tk interfaces

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


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

5.11 Testing ODBC interfaces

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

5.12 Testing MPSQL Motif-worksheet interfaces

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

5.13 Verification

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


# 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


Next Previous Contents