View · Index

Install Postgresql

A quick install guide for Postgres 8.2 which takes everything into account can be found at http://cognovis.de/developer/en/pg82 

For RPMs, see http://yum.pgsqlrpms.org/


These instructions should work for 7.4 to 8.2.

Get the source code

http://www.postgresql.org/download/

Install from source

Unpack PostgreSQL 7.4.7. If you have downloaded the postgresql tarball to /var/tmp/postgresql-7.4.7.tar.gz

[root root]# cd /usr/local/src
[root src]# tar xzf /var/tmp/postgresql-7.4.7.tar.gz
[root src]# 
cd /usr/local/src
tar xzf /var/tmp/postgresql-7.4.7.tar.gz

If you have downloaded the postgresql tarball to /var/tmp/postgresql-7.4.7.tar.bz2

[root root]# cd /usr/local/src
[root src]# tar xfj /var/tmp/postgresql-7.4.7.tar.bz2
[root src]# 
cd /usr/local/src
tar xfj /var/tmp/postgresql-7.4.7.tar.bz2

Create the Postgres user. Create a user and group (if you haven't done so before) for PostgreSQL. This is the account that PostgreSQL will run as since it will not run as root. Since nobody will log in directly as that user, we'll leave the password blank.

[root src]# groupadd web
[root src]# useradd -g web -d /usr/local/pgsql postgres
[root src]# mkdir -p /usr/local/pgsql
[root src]# chown -R postgres.web /usr/local/pgsql /usr/local/src/postgresql-7.4.7
[root src]# chmod 750 /usr/local/pgsql
[root src]#
groupadd web
useradd -g web -d /usr/local/pgsql postgres
mkdir -p /usr/local/pgsql
chown -R postgres.web /usr/local/pgsql /usr/local/src/postgresql-7.4.7
chmod 750 /usr/local/pgsql

Set up postgres's environment variables. They are necessary for the executable to find its supporting libraries. Put the following lines into the postgres user's environment.

[root src]# su - postgres
[postgres ~] emacs ~postgres/.bashrc

Paste this line into .bash_profile:

source $HOME/.bashrc

Paste these lines into .bashrc:

export PATH=/usr/local/bin/:$PATH:/usr/local/pgsql/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib

Test this by logging in as postgres and checking the paths; you should see /usr/local/pgsql/bin

[root src]# su - postgres
[postgres pgsql]$ env | grep PATH
LD_LIBRARY_PATH=:/usr/local/pgsql/lib
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin/X11:/usr/X11R6/bin:/root/bin:/usr/local/pgsql/bin:/usr/local/pgsql/bin
[postgres pgsql]$ exit

Don't continue unless you see correct output from env | grep PATH

Compile and install PostgreSQL. Change to the postgres user and run ./configure to set the compilation options automatically. This is the point at which you can configure PostgreSQL in various ways. To see what the possibilities, run ./configure --help.

[root src]# su - postgres
[postgres pgsql]$ cd /usr/local/src/postgresql-7.4.7
[postgres postgresql-7.4.7]$ ./configure
creating cache ./config.cache
checking host system type... i686-pc-linux-gnu
(many lines omitted>
linking ./src/makefiles/Makefile.linux to src/Makefile.port
linking ./src/backend/port/tas/dummy.s to src/backend/port/tas.s
[postgres postgresql-7.4.7]$ make all
make -C doc all
make[1]: Entering directory `/usr/local/src/postgresql-7.4.7/doc'
(many lines omitted)
make[1]: Leaving directory `/usr/local/src/postgresql-7.4.7/src'
All of PostgreSQL successfully made. Ready to install.
[postgres postgresql-7.4.7]$ make install
make -C doc install
make[1]: Entering directory `/usr/local/src/postgresql-7.4.7/doc'
(many lines omitted)
Thank you for choosing PostgreSQL, the most advanced open source database
engine.
su - postgres
cd /usr/local/src/postgresql-7.4.7
./configure
make all
make install

Start PostgreSQL. The initdb command initializes the database. pg_ctl is used to start up PostgreSQL.

[postgres postgresql-7.4.7]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
(17 lines omitted)
or
    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
[postgres postgresql-7.4.7]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start
postmaster successfully started
[postgres postgresql-7.4.7]$
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start

PostgreSQL errors will be logged in /usr/local/pgsql/data/server.log

Install Pl/pgSQL.Set up plpgsq and allow your user to have access. Plpgsql is a PL/SQL-like language. We add it to template1, which is the template from which all new databases are created. We can verify that it was created with the createlang command in list mode.

[postgres postgresql-7.4.7]$ createlang plpgsql template1
[postgres pgsql]$ createlang -l template1
Procedural languages
  Name   | Trusted?
---------+----------
 plpgsql | t
(1 row)

[postgres pgsql-7.4.7]$
createlang plpgsql template1
createlang -l template1

If you are installing Postgres 8.x, follow additional instructions at en:How_to_install_in_Postgres_8.x

If you are installing tsearch2, follow additional instructions at en:postgresql-tsearch2

Test PostgreSQL (OPTIONAL). Create a database and try some simple commands. The output should be as shown.

[postgres pgsql]$ createdb mytestdb
CREATE DATABASE
[postgres pgsql]$ psql mytestdb
Welcome to psql, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help on internal slash commands
       \g or terminate with semicolon to execute query
       \q to quit

mytestdb=# select current_timestamp;
          timestamptz
-------------------------------
 2003-03-07 22:18:29.185413-08
(1 row)

mytestdb=# create function test1() returns integer as 'begin return 1; end;' language 'plpgsql';
CREATE
mytestdb=# select test1();
 test1
-------
     1
(1 row)

mytestdb=# \q
[postgres pgsql]$ dropdb mytestdb
DROP DATABASE
[postgres pgsql]$ exit
logout

[root src]#

Set PostgreSQL to start on boot. First, we copy the SERVERROOT/packages/acs-core-docs/www/files/postgresql.txt init script, which automates startup and shutdown, to the distribution-specific init.d directory. Then we verify that it works. Then we automate it by setting up a bunch of symlinks that ensure that, when the operating system changes runlevels, postgresql goes to the appropriate state. Red Hat and Debian and SuSE each work a little differently. Be sure to check OS distribution notes for specifics (and examples)

Once installed, PostgreSQL should start automatically each time you boot up and it should shutdown gracefully each time you shut down.

previous March 2024
Sun Mon Tue Wed Thu Fri Sat
25 26 27 28 29 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6

Popular tags

17 , 5.10 , 5.10.0 , 5.9.0 , 5.9.1 , ad_form , ADP , ajax , aolserver , asynchronous , bgdelivery , bootstrap , bugtracker , CentOS , COMET , compatibility , CSP , CSRF , cvs , debian , docker , docker-compose , emacs , engineering-standards , exec , fedora , FreeBSD , guidelines , host-node-map , hstore
No registered users in community xowiki
in last 30 minutes
Contributors

OpenACS.org