Monday, September 22, 2008

Postgresql Installation on Linux (2)

We have installed postgresql successfully.

Now we can do anything post-installation step by step.

1. Shared Libraries
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 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. You should put these commands into a shell start-up file such
as "/etc/profile" or "~/.bash_profile". Some good information about the
caveats associated with this method can be found at
http://www.visi.com/~barr/ldpath.html.
On some systems it might be preferable to set the environment variable
LD_RUN_PATH *before* building.

2. Environment Variables
If you installed into "/usr/local/pgsql" or some other location that is
not searched for programs by default, you should add
"/usr/local/pgsql/bin" (or whatever you set "--bindir" to in step 1)
into your PATH. Strictly speaking, this is not necessary, but it will
make the use of PostgreSQL much more convenient.

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 )


To enable your system to find the man documentation, you need to add
lines like the following to a shell start-up file unless you installed
into a location that is searched by default:

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


3. Create a user account for the PostgreSQL server. This is the user
the server will run as. For production use you should create a
separate, unprivileged account ("postgres" is commonly used). If
you do not have root access or just want to play around, your own
user account is enough, but running the server as root is a
security risk and will not work.
You must have a root access

root#adduser postgres

4. Create a database installation with the "initdb" command. To run
"initdb" you must be logged in to your PostgreSQL server account.
It will not work as root.

root# mkdir /usr/local/pgsql/data
root# chown postgres /usr/local/pgsql/data
root# su - postgres
postgres$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


The "-D" option specifies the location where the data will be
stored. You can use any path you want, it does not have to be under
the installation directory. Just make sure that the server account
can write to the directory (or create it, if it doesn't already
exist) before starting "initdb", as illustrated here.

At this point, if you did not use the "initdb" -A option, you might
want to modify "pg_hba.conf" to control local access to the server
before you start it. The default is to trust all local users.

The previous "initdb" step should have told you how to start up the
database server. Do so now. The command should look something like:

/usr/local/pgsql/bin/postgres -i -D /usr/local /pgsql/data

option -i , if you want the databases can be access from other host (via network)

This will start the server in the foreground. To put the server in
the background use something like:

nohup /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data \
>server.log 2>&1

To stop a server running in the background you can type:
kill `cat /usr/local/pgsql/data/postmaster.pid`

You should put this script on script initiation ( /etc/init.d/pgsql ).

5. Then you can test a create database.

createdb dbexample

and you can work in your database

psql dbexample


6. OK you succesfully installed the postgresql.

GOOD LUCK



No comments: