Saturday, December 11, 2004

Setting up java tomcat on linux IX - Install Postgresql


Creating the “postgres” User
Create a UNIX user account to own and manage the PostgreSQL database files. Typically, this user is named postgres, but it can be named anything that you choose.

You will need to have root privileges to create the PostgreSQL superuser. You can use the command shown to add the postgres user.

su - -c "useradd postgres"

Install Postgresql

cd /usr/local/src
tar xvfz postgresql-7.3.4.tar.gz
cd postgresql-7.3.4

then logoff and login as the postgres user (this wont work if your java and ant environment variables and path additions are not setup properly)

./configure --with-tcl --with-java

gmake
su -c "gmake install"
su -c "chown -R postgres.postgres /usr/local/pgsql"

Setting Environment Variables
The use of the PostgreSQL environment variables is not required. However, they are helpful when performing tasks within PostgreSQL, including starting and shutting down the postmaster processes.
The environment variables that should be set are for the man pages and the bin directory. You can do so by adding the following statements into the /etc/profile file.

PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PATH MANPATH

Initializing and Starting PostgreSQL
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

Running postmaster in the background
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /tmp/pgsql.log start

Configuring the PostgreSQL SysV Script
The SysV script will allow the graceful control of the PostgreSQL database through the use of the SysV runlevel system. The SysV script can be used for starting, stopping, and status-checking of PostgreSQL. It is known to work with most Red Hat based versions of Linux, including Mandrake; however, it should work with other SysV systems (e.g., UnixWare, Solaris, etc.) with little modification. The script is named linux. To use it, you will first need to copy the linux script to your init.d directory. You may require root access to do this.
First, change to the directory where you unpacked the PostgreSQL source. eg /usr/local/src/postgresql-7.1.3/. Then, issue a cp command to copy the script from contrib/start-scripts into the init.d

Copying the linux script
cd /usr/local/src/postgresql-7.4.6
su -c "cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresql"

Making the linux script executable
su -c "chmod a+x /etc/rc.d/init.d/postgresql"

There are no additional requirements to use the SysV script with Red Hat, if you do not intend on using it to start PostgreSQL automatically (i.e., if you wish to use the script manually). However, if you do wish for the script to startup PostgreSQL automatically when the machine boots up (or changes runlevels), you will need to have the chkconfig program installed. If chkconfig is installed, you will also need to add the following two lines, including the hash (#) symbol, at the beginning of the /etc/rc.d/init.d/postgresql file:

# chkconfig: 345 85 15
# description: PostgreSQL RDBMS

Starting PostgreSQL with the SysV script:

service postgresql start
Starting PostgreSQL: ok

service postgresql stop
Stopping PostgreSQL: ok

The next step will be to create a new database. This will be a simple test database. We do not recommend using the default template1 database for testing purposes. As you have not created any users with database-creation rights, you will want to make sure that you are logged in as the postgres user when adding a new database.

To create a new database named testdb, enter the command shown:
createdb testdb

psql testdb

You can now start entering SQL commands (e.g., such as SELECT) at the psql prompt
To verify that the database is working correctly, you can issue the command shown in which should give you a listing of the languages installed in the database

SELECT * FROM pg_language;

lanname lanispl lanpltrusted lanplcallfoid lancompiler
----------+---------+--------------+---------------+-------------
internal f f 0 n/a
C f f 0 /bin/cc
sql f f 0 postgres

No comments:

Post a Comment