<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 'http://www.w3.org/TR/html4/loose.dtd"'>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Install PostgreSQL</title><link rel="stylesheet" href="openacs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="OpenACS Core Documentation"><link rel="up" href="complete-install.html" title="Chapter 3. Complete Installation"><link rel="previous" href="oracle.html" title="Install Oracle 8.1.7"><link rel="next" href="aolserver4.html" title="Install AOLserver 4"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><a href="http://openacs.org"><img src="/doc/images/alex.jpg" style="border:0" alt="Alex logo"></a><table width="100%" summary="Navigation header" border="0"><tr><td width="20%" align="left"><a accesskey="p" href="oracle.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Complete Installation</th><td width="20%" align="right"> <a accesskey="n" href="aolserver4.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="postgres"></a>Install PostgreSQL</h2></div></div><div></div></div><div class="authorblurb"><p>by <a href="mailto:vinod@kurup.com" target="_top">Vinod Kurup</a></p>
          OpenACS docs are written by the named authors, and may be edited
          by OpenACS documentation staff.
        </div><p>Skip this section if you will run only Oracle.</p><p>OpenACS 5.7.0 will run with <a href="individual-programs.html#source-postgresql">PostgreSQL</a> 7.3.2, 7.3.3, and 7.3.4 and 7.4.x.  7.4.7 is the recommended version of PostgreSQL.</p><div class="itemizedlist"><ul type="disc"><li><p><a name="install-postgres-mac"></a><b>Special notes for Mac OS X. </b>If you are running Mac OS X prior to 10.3, you should be
        able to install and use PostGreSQL 7.3.x.  Mac OS X 10.3
        requires PostGreSQL 7.4. </p></li><li><p><a name="install-postgres-debian"></a><b>Special Notes for Debian. </b></p><p>Debian stable user should install PostGreSQL from source
      as detailed below, or they should use the www.backports.org
      backport for Postgres to get a more current version. Debian
      unstable users: the following process has been known to work
      (but you should double-check that the version of PostGreSQL is
      7.3 or above):</p><p>For Debian stable users, you can use backports, by adding
      this line to the /etc/apt/sources.list</p><pre class="screen">
        <b class="userinput"><tt>deb http://www.backports.org/debian stable bison postgresql openssl openssh tcl8.4 courier debconf spamassassin tla diff patch neon chkrootkit
        </tt></b>
      </pre><pre class="screen"><b class="userinput"><tt>apt-get install postgresql postgresql-dev postgresql-doc
ln -s /usr/include/postgresql/ /usr/include/pgsql
ln -s /var/lib/postgres /usr/local/pgsql
ln -s /usr/include/pgsql /usr/local/pgsql/include
su postgres -c &quot;/usr/lib/postgresql/bin/createlang plpgsql template1&quot;</tt></b></pre><p>and proceed to <a href="postgres.html#postgres-tune" title="Tune postgres.  (OPTIONAL)">Tune postgres.  (OPTIONAL)</a> or to the
      next section.</p></li><li><p><a name="install-postgres-rpm"></a><b>Special Notes for Red Hat. </b>Red Hat users: If you install PostgreSQL 7.3.2 from the Red Hat 9 RPM, you
  can skip a few steps.  These shell commands add some links for compatibility with the directories from a source-based install; start the service; create a new group for web service
  users, and modify the postgres user's
  environment (<a href="postgres.html#install-postgres-env">more
  information</a>):</p><pre class="screen">[root root]# <b class="userinput"><tt>ln -s /usr/lib/pgsql/ /var/lib/pgsql/lib</tt></b>
[root root]# <b class="userinput"><tt>ln -s /var/lib/pgsql /usr/local/pgsql</tt></b>
[root root]# <b class="userinput"><tt>ln -s /etc/init.d/postgresql /etc/init.d/postgres</tt></b>
[root root]# <b class="userinput"><tt>ln -s /usr/bin /usr/local/pgsql/bin</tt></b>
[root root]# <b class="userinput"><tt>service postgresql start</tt></b>
Initializing database:
                                                           [  OK  ]
Starting postgresql service:                               [  OK  ]
[root root]# <b class="userinput"><tt>echo &quot;export LD_LIBRARY_PATH=/usr/local/pgsql/lib&quot; &gt;&gt; ~postgres/.bash_profile</tt></b>
[root root]# <b class="userinput"><tt>echo &quot;export PATH=$PATH:/usr/local/pgsql/bin&quot; &gt;&gt; ~postgres/.bash_profile</tt></b>
[root root]# <b class="userinput"><tt>groupadd web</tt></b>
[root root]# <b class="userinput"><tt>su - postgres</tt></b>
-bash-2.05b$
<span class="action"><span class="action">
ln -s /usr/lib/pgsql/ /var/lib/pgsql/lib
ln -s /var/lib/pgsql /usr/local/pgsql
ln -s /usr/bin /usr/local/pgsql/bin
service postgresql start
echo &quot;export LD_LIBRARY_PATH=/usr/local/pgsql/lib&quot; &gt;&gt; ~postgres/.bash_profile
echo &quot;export PATH=$PATH:/usr/local/pgsql/bin&quot; &gt;&gt; ~postgres/.bash_profile
groupadd web
su - postgres</span></span></pre><p>... and then skip to <a href="postgres.html#install-plpgsql" title="">8</a>.  Something similar may work for other binary packages as well.</p></li><li><p>Safe approach: install from source</p><div class="orderedlist"><ol type="1"><li><p><b>Unpack PostgreSQL 7.4.7. </b>If you have not downloaded the postgresql tarball to
        <tt class="computeroutput">/var/tmp/postgresql-7.4.7.tar.gz</tt>,
        <a href="individual-programs.html#source-postgresql">get it</a>.</p><pre class="screen">[root root]# <b class="userinput"><tt>cd /usr/local/src</tt></b>
[root src]# <b class="userinput"><tt>tar xzf /var/tmp/postgresql-7.4.7.tar.gz</tt></b>
[root src]# 
<span class="action"><span class="action">cd /usr/local/src
tar xzf /var/tmp/postgresql-7.4.7.tar.gz</span></span></pre></li><li><p><b>ALTERNATIVE: Unpack PostgreSQL 7.4.7. </b>If you have not downloaded the postgresql tarball to
        <tt class="computeroutput">/var/tmp/postgresql-7.4.7.tar.bz2</tt>,
        <a href="individual-programs.html#source-postgresql">get it</a>.</p><pre class="screen">[root root]# <b class="userinput"><tt>cd /usr/local/src</tt></b>
[root src]# <b class="userinput"><tt>tar xfj /var/tmp/postgresql-7.4.7.tar.bz2</tt></b>
[root src]# 
<span class="action"><span class="action">cd /usr/local/src
tar xfj /var/tmp/postgresql-7.4.7.tar.bz2</span></span></pre></li><li><p><b>Install Bison. </b>Only do this if <b class="userinput"><tt>bison --version</tt></b> is smaller than 1.875 and you install PostgreSQL 7.4 from cvs instead of tarball.</p><pre class="screen">[root root]# <b class="userinput"><tt>cd /usr/local/src</tt></b>
[root src]# <b class="userinput"><tt>wget http://ftp.gnu.org/gnu/bison/bison-1.875.tar.gz</tt></b>
[root src]# <b class="userinput"><tt>tar xfz bison-1.875.tar.gz</tt></b>
[root src]# <b class="userinput"><tt>cd bison-1.875</tt></b>
[root src]# <b class="userinput"><tt>./configure</tt></b>
[root src]# <b class="userinput"><tt>make install</tt></b>
      </pre></li><li><p><b>Create the Postgres user. </b>
	  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.
	</p><p>
	  Debian users should probably use adduser instead of
	  useradd. Type <tt class="computeroutput">man adduser</tt>
	</p><pre class="screen">[root src]# <b class="userinput"><tt>groupadd web</tt></b>
[root src]# <b class="userinput"><tt>useradd -g web -d /usr/local/pgsql postgres</tt></b>
[root src]# <b class="userinput"><tt>mkdir -p /usr/local/pgsql</tt></b>
[root src]# <b class="userinput"><tt>chown -R postgres.web /usr/local/pgsql /usr/local/src/postgresql-7.4.7</tt></b>
[root src]# <b class="userinput"><tt>chmod 750 /usr/local/pgsql</tt></b>
[root src]#
<span class="action"><span class="action">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</span></span></pre><div class="itemizedlist"><ul type="circle"><li><p><b>Mac OS X: Do instead: </b>First make sure the gids and uids below are available (change them if 
they  are not).To list taken uids and gids:</p><pre class="screen"><b class="userinput"><tt>nireport / /groups name gid | grep &quot;[0123456789][0123456789]&quot;
nireport / /users name uid | grep &quot;[0123456789][0123456789]&quot;</tt></b>
          </pre><p>Now you can install the users</p><pre class="screen"><b class="userinput"><tt>sudo niutil -create / /groups/web
sudo niutil -createprop / /groups/web gid <span class="replaceable"><span class="replaceable">201</span></span>
sudo niutil -create / /users/postgres
sudo niutil -createprop / /users/postgres gid <span class="replaceable"><span class="replaceable">201</span></span>
sudo niutil -createprop / /users/postgres uid <span class="replaceable"><span class="replaceable">502</span></span>
sudo niutil -createprop / /users/postgres home /usr/local/pgsql
sudo niutil -create / /users/<span class="replaceable"><span class="replaceable">$OPENACS_SERVICE_NAME</span></span>
sudo niutil -createprop / /users/<span class="replaceable"><span class="replaceable">$OPENACS_SERVICE_NAME</span></span> gid  <span class="replaceable"><span class="replaceable">201</span></span>
sudo niutil -createprop / /users/<span class="replaceable"><span class="replaceable">$OPENACS_SERVICE_NAME</span></span> uid <span class="replaceable"><span class="replaceable">201</span></span>
mkdir -p /usr/local/pgsql
chown -R postgres:web /usr/local/pgsql /usr/local/src/postgresql-7.4.7
chmod 750 /usr/local/pgsql</tt></b></pre></li><li><p><b>FreeBSD users: </b> need to add more parameters.
          </p><pre class="screen">[root src]# <b class="userinput"><tt>mkdir -p /usr/local/pgsql</tt></b>
[root src]# <b class="userinput"><tt>pw groupadd -n web</tt></b>
[root src]# <b class="userinput"><tt>pw useradd -n postgres -g web -d /usr/local/pgsql -s /bin/bash</tt></b>
[root src]# <b class="userinput"><tt>chown -R postgres:web /usr/local/pgsql /usr/local/src/postgresql-7.4.7</tt></b>
[root src]# <b class="userinput"><tt>chmod -R 750 /usr/local/pgsql</tt></b>
[root src]#
<span class="action"><span class="action">mkdir -p /usr/local/pgsql
pw groupadd -n web
pw useradd -n postgres -g web -d /usr/local/pgsql -s /bin/bash
chown -R postgres:web /usr/local/pgsql /usr/local/src/postgresql-7.4.7
chmod -R 750 /usr/local/pgsql</span></span></pre></li></ul></div></li><li><a name="install-postgres-env"></a><p><b>Set up postgres's environment variables. </b>They are necessary for the executable to find its supporting
	libraries.  Put the following lines into the postgres user's environment.</p><pre class="screen">[root src]# <b class="userinput"><tt>su - postgres</tt></b>
[postgres ~] <b class="userinput"><tt>emacs ~postgres/.bashrc</tt></b></pre><p>Paste this line into <tt class="computeroutput">.bash_profile</tt>:</p><pre class="programlisting">source $HOME/.bashrc</pre><p>Paste these lines into <tt class="computeroutput">.bashrc</tt>:</p><pre class="programlisting">export PATH=/usr/local/bin/:$PATH:/usr/local/pgsql/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib</pre><p>Test this by logging in as
	<tt class="computeroutput">postgres</tt> and checking the
	paths; you should see <tt class="computeroutput">/usr/local/pgsql/bin</tt> somewhere in the output (the total output is system-dependent so yours may vary)</p><pre class="screen">[root src]# <b class="userinput"><tt>su - postgres</tt></b>
[postgres pgsql]$ <b class="userinput"><tt>env | grep PATH</tt></b>
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]$ <b class="userinput"><tt>exit</tt></b>
</pre><p>Don't continue unless you see correct output from
      <tt class="computeroutput">env | grep PATH</tt></p></li><li><a name="install-postgres-compile"></a><p><b>Compile and install PostgreSQL. </b>
	  Change to the postgres user and run <tt class="computeroutput">./configure</tt> to set the compilation options automatically. This is the point at which you can
	  configure PostgreSQL in various ways. For example, if you are installing on &quot;OS X&quot; add the flags <tt class="computeroutput"> --with-includes=/sw/include/ --with-libraries=/sw/lib</tt>. If you want to see what the other possibilities are, run <tt class="computeroutput">./configure --help</tt>.
	</p><p>On debian woody (stable, 3.0), do <tt class="computeroutput">./configure --without-readline --without-zlib</tt>.</p><pre class="screen">[root src]# <b class="userinput"><tt>su - postgres</tt></b>
[postgres pgsql]$<b class="userinput"><tt> cd /usr/local/src/postgresql-7.4.7</tt></b>
[postgres postgresql-7.4.7]$ <b class="userinput"><tt>./configure</tt></b>
creating cache ./config.cache
checking host system type... i686-pc-linux-gnu
(many lines omitted&gt;
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]$ <b class="userinput"><tt>make all</tt></b>
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]$ <b class="userinput"><tt>make install</tt></b>
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.
<span class="action"><span class="action">su - postgres
cd /usr/local/src/postgresql-7.4.7
./configure 
make all
make install</span></span></pre></li><li><a name="install-postgres-startup"></a><p><b>Start PostgreSQL. </b>
	  The <tt class="computeroutput">initdb</tt> command initializes the
	  database. <tt class="computeroutput">pg_ctl</tt> is used to start up
	  PostgreSQL. If PostgreSQL is unable to allocate enough memory, see section 11
          Tuning PostgreSQL (below).
	</p><pre class="screen">[postgres postgresql-7.4.7]$ <b class="userinput"><tt>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data</tt></b>
The files belonging to this database system will be owned by user &quot;postgres&quot;.
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]$ <b class="userinput"><tt>/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start</tt></b>
postmaster successfully started
[postgres postgresql-7.4.7]$
<span class="action"><span class="action">/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</span></span></pre><p>
	  PostgreSQL errors will be logged in
	  <tt class="computeroutput">/usr/local/pgsql/data/server.log</tt>
	</p></li><li><a name="install-plpgsql"></a><p><b>Install Pl/pgSQL. </b>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.</p><pre class="screen">[postgres postgresql-7.4.7]$ <b class="userinput"><tt>createlang plpgsql template1</tt></b>
[postgres pgsql]$ <b class="userinput"><tt>createlang -l template1</tt></b>
Procedural languages
  Name   | Trusted?
---------+----------
 plpgsql | t
(1 row)

[postgres pgsql-7.4.7]$
<span class="action"><span class="action">createlang plpgsql template1
createlang -l template1</span></span></pre></li><li><a name="install-postgres-test"></a><p><b>Test PostgreSQL (OPTIONAL). </b>Create a database and try some simple commands. The output should be as shown.
	</p><pre class="screen">[postgres pgsql]$ <b class="userinput"><tt>createdb mytestdb</tt></b>
CREATE DATABASE
[postgres pgsql]$ <b class="userinput"><tt>psql mytestdb</tt></b>
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=# <b class="userinput"><tt>select current_timestamp;</tt></b>
          timestamptz
-------------------------------
 2003-03-07 22:18:29.185413-08
(1 row)

mytestdb=# <b class="userinput"><tt>create function test1() returns integer as 'begin return 1; end;' language 'plpgsql';</tt></b>
CREATE
mytestdb=#<b class="userinput"><tt> select test1();</tt></b>
 test1
-------
     1
(1 row)

mytestdb=# <b class="userinput"><tt>\q</tt></b>
[postgres pgsql]$<b class="userinput"><tt> dropdb mytestdb</tt></b>
DROP DATABASE
[postgres pgsql]$ <b class="userinput"><tt>exit</tt></b>
logout

[root src]#</pre></li><li><p><a name="install-postgres-startonboot"></a>Set PostgreSQL to start on boot.  First, we copy the
        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.  If you haven't <a href="openacs.html#install-from-tarball" title="Installation Option 2: Install from tarball"> untarred the OpenACS tarball</a>, you will need to do so now to access the postgresql.txt file.
	</p><div class="itemizedlist"><ul type="circle"><li><p>Red Hat RPM:</p><p>The init script is already installed; just turn it on for the appropriate run levels.</p><pre class="screen">[root root]# <b class="userinput"><tt>chkconfig --level 345 postgresql on</tt></b>
[root root]# </pre></li><li><p>Red Hat from source:</p><pre class="screen">[root src]# <b class="userinput"><tt>cp /var/tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql</tt></b>
[root src]# <b class="userinput"><tt>chown root.root /etc/rc.d/init.d/postgresql</tt></b>
[root src]# <b class="userinput"><tt>chmod 755 /etc/rc.d/init.d/postgresql</tt></b>
[root src]# 
<span class="action"><span class="action">cp /var/tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql
chown root.root /etc/rc.d/init.d/postgresql
chmod 755 /etc/rc.d/init.d/postgresql</span></span></pre><p>Test the script.</p><pre class="screen">[root root]# <b class="userinput"><tt>service postgresql stop</tt></b>
Stopping PostgreSQL: ok
[root root]# </pre><p>If PostgreSQL successfully stopped, then use the following
		  command to make sure that the script is run appropriately at boot
		  and shutdown.  And turn it back on because we'll use
		  it later.

		</p><pre class="screen">[root root]# <b class="userinput"><tt>chkconfig --add postgresql</tt></b>
[root root]# <b class="userinput"><tt>chkconfig --level 345 postgresql on</tt></b>
[root root]# <b class="userinput"><tt>chkconfig --list postgresql</tt></b>
postgresql      0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root root]# <b class="userinput"><tt>service postgresql start</tt></b>
Starting PostgreSQL: ok
[root root]#
<span class="action"><span class="action">chkconfig --add postgresql
chkconfig --level 345 postgresql on
chkconfig --list postgresql
service postgresql start</span></span></pre></li><li><p>Debian:</p><pre class="screen">[root ~]# <b class="userinput"><tt>cp /var/tmp/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql</tt></b>
[root ~]# <b class="userinput"><tt>chown root.root /etc/init.d/postgresql</tt></b>
[root ~]# <b class="userinput"><tt>chmod 755 /etc/init.d/postgresql</tt></b>
[root ~]# <span class="action"><span class="action">
cp /var/tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql
chown root.root /etc/init.d/postgresql
chmod 755 /etc/init.d/postgresql</span></span></pre><p>Test the script</p><pre class="screen">[root ~]# <b class="userinput"><tt>/etc/init.d/postgresql stop</tt></b>
Stopping PostgreSQL: ok
[root ~]# </pre><p>If PostgreSQL successfully stopped, then use the following
		  command to make sure that the script is run
		  appropriately at boot and shutdown.</p><pre class="screen">
[root ~]# <b class="userinput"><tt>update-rc.d postgresql defaults</tt></b>
 Adding system startup for /etc/init.d/postgresql ...
   /etc/rc0.d/K20postgresql -&gt; ../init.d/postgresql
   /etc/rc1.d/K20postgresql -&gt; ../init.d/postgresql
   /etc/rc6.d/K20postgresql -&gt; ../init.d/postgresql
   /etc/rc2.d/S20postgresql -&gt; ../init.d/postgresql
   /etc/rc3.d/S20postgresql -&gt; ../init.d/postgresql
   /etc/rc4.d/S20postgresql -&gt; ../init.d/postgresql
   /etc/rc5.d/S20postgresql -&gt; ../init.d/postgresql
[root ~]# <b class="userinput"><tt>/etc/init.d/postgresql start</tt></b>
Starting PostgreSQL: ok
[root ~]#</pre></li><li><p>FreeBSD:</p><pre class="screen">[root ~]# <b class="userinput"><tt>cp /tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /usr/local/etc/rc.d/postgresql.sh</tt></b>
[root ~]# <b class="userinput"><tt>chown root:wheel /usr/local/etc/rc.d/postgresql.sh</tt></b>
[root ~]# <b class="userinput"><tt>chmod 755 /usr/local/etc/rc.d/postgresql.sh</tt></b>
[root ~]# <span class="action"><span class="action">
cp /tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /usr/local/etc/rc.d/postgresql.sh
chown root:wheel /usr/local/etc/rc.d/postgresql.sh
chmod 755 /usr/local/etc/rc.d/postgresql.sh</span></span></pre><p>Test the script</p><pre class="screen">[root ~]# <b class="userinput"><tt>/usr/local/etc/rc.d/postgresql.sh stop</tt></b>
Stopping PostgreSQL: ok
[root ~]# </pre><p>If PostgreSQL successfully stopped, then turn it back on because we'll use
		  it later.</p><pre class="screen">[root root]# <b class="userinput"><tt>/usr/local/etc/rc.d/postgresql.sh start</tt></b>
Starting PostgreSQL: ok
[root root]#
<span class="action"><span class="action">/usr/local/etc/rc.d/postgresql.sh start</span></span></pre></li><li><p>SuSE:</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>

			I have received reports that SuSE 8.0 is different from
            previous versions. Instead of installing the boot scripts in
            <tt class="computeroutput">/etc/rc.d/init.d/</tt>, they should
            be placed in <tt class="computeroutput">/etc/init.d/</tt>. If
            you're using SuSE 8.0, delete the
            <tt class="computeroutput">rc.d/</tt> part in each of the
            following commands.

          </p></div><pre class="screen">[root ~]# <b class="userinput"><tt>cp /var/tmp/openacs-5.7.0/packages/acs-core-docs/www/files/postgresql.txt /etc/rc.d/init.d/postgresql</tt></b>
[root ~]# <b class="userinput"><tt>chown root.root /etc/rc.d/init.d/postgresql</tt></b>
[root ~]# <b class="userinput"><tt>chmod 755 /etc/rc.d/init.d/postgresql</tt></b></pre><p>

          Test the script.

        </p><pre class="screen">[root ~]# <b class="userinput"><tt>/etc/rc.d/init.d/postgresql stop</tt></b>
Stopping PostgreSQL: ok</pre><p>

          If PostgreSQL successfully stopped, then use the following
          command to make sure that the script is run appropriately at boot
          and shutdown.

        </p><pre class="screen">[root ~]# <b class="userinput"><tt>cd /etc/rc.d/init.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>ln -s /etc/rc.d/init.d/postgresql K20postgresql</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>ln -s /etc/rc.d/init.d/postgresql S20postgresql  </tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp K20postgresql rc2.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp S20postgresql rc2.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp K20postgresql rc3.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp S20postgresql rc3.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp K20postgresql rc4.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp S20postgresql rc4.d </tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp K20postgresql rc5.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>cp S20postgresql rc5.d</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>rm K20postgresql</tt></b>
root:/etc/rc.d/init.d# <b class="userinput"><tt>rm S20postgresql</tt></b>
root:/etc/rc.d/init.d# </pre><p>

          Test configuration.

        </p><pre class="screen">root:/etc/rc.d/init.d # <b class="userinput"><tt>cd</tt></b>
root:~ # <b class="userinput"><tt>/etc/rc.d/init.d/rc2.d/S20postgresql start</tt></b>
Starting PostgreSQL: ok
root:~ # </pre></li><li><p>Mac OS X 10.3:</p><div class="orderedlist"><ol type="a"><li><p>Install the startup script:</p><pre class="screen"><b class="userinput"><tt>cd /System/Library/StartupItems/</tt></b>
<b class="userinput"><tt>tar xfz /var/lib/aolserver/<span class="replaceable"><span class="replaceable">$OPENACS_SERVICE_NAME</span></span>/packages/acs-core-docs/www/files/osx-postgres-startup-item.tgz</tt></b>
</pre></li></ol></div></li><li><p>Mac OS X 10.4 can use Launchd:</p><div class="orderedlist"><ol type="a"><li><p>Install the startup script:</p><pre class="screen"><b class="userinput"><tt>cd /Library/LaunchDaemons</tt></b>
<b class="userinput"><tt>cp
/var/lib/aolserver/<span class="replaceable"><span class="replaceable">$OPENACS_SERVICE_NAME</span></span>/packages/acs-core-docs/www/files/osx-postgres-launchd-item.txt
org.postgresql.PostgreSQL.plist</tt></b>
</pre><p>If postgres does not start automatically on reboot, see what
    error you get when manually starting it with:</p><pre class="screen">
$ <b class="userinput"><tt>sudo launchctl load /Library/LaunchDaemons/org.postgresql.PostgreSQL.plist</tt></b>
$ <b class="userinput"><tt>sudo launchctl start org.postgresql.PostgreSQL</tt></b></pre></li></ol></div></li></ul></div><p>

      From now on, PostgreSQL should start automatically each time you boot
      up and it should shutdown gracefully each time you shut down. (Note:
      Debian defaults to starting all services on runlevels 2-5. Red Hat
      defaults to starting services on 3-5. So, on Red Hat, PostgreSQL won't
      start on runlevel 2 unless you alter the above commands a
      little. This usually isn't a problem as Red Hat defaults to runlevel 3)

    </p></li><li><p><a name="postgres-tune"></a><b>Tune postgres.  (OPTIONAL). </b>The default values for PostgreSQL are very conservative; we can safely change some of them and improve performance.</p><div class="orderedlist"><ol type="a"><li><p>Change the kernel parameter for maximum shared memory
          segment size to 128Mb:</p><pre class="screen">[root root]# <b class="userinput"><tt>echo 134217728 &gt;/proc/sys/kernel/shmmax</tt></b>
[root root]#</pre><p>Make that change permanent by editing
          <tt class="computeroutput">/etc/sysctl.conf</tt> to
          add these lines at the end:</p><pre class="programlisting"># increase shared memory limit for postgres
kernel.shmmax = 134217728</pre></li><li><p>Edit the PostgreSQL config file, <tt class="computeroutput">/usr/local/pgsql/data/postgresql.conf</tt>, to use more memory.  These values should improve performance in most cases.  (<a href="http://openacs.org/forums/message-view?message_id=94071" target="_top">more information</a>)</p><pre class="programlisting">#       Shared Memory Size
#
shared_buffers = 15200      # 2*max_connections, min 16

#       Non-shared Memory Sizes
#
sort_mem = 32168            # min 32


#       Write-ahead log (WAL)
#
checkpoint_segments = 3     # in logfile segments (16MB each), min 1
</pre><p>Restart postgres (<tt class="computeroutput">service postgresql
          restart</tt>) or
          (<tt class="computeroutput">/etc/init.d/postgres
          restart</tt>) so that the changes take effect.</p></li></ol></div><p>FreeBSD users: See <b class="userinput"><tt>man syctl</tt></b>, <b class="userinput"><tt>man 5 sysctl</tt></b>
      and <b class="userinput"><tt>man 5 loader.conf</tt></b>.</p><p>Performance tuning resources:</p><div class="itemizedlist"><ul type="circle"><li><p>
        <a href="http://www.postgresql.org/docs/7.4/interactive/kernel-resources.html" target="_top">Managing Kernel Resources</a>
        about PostgreSQL shared memory and semaphores with specific operating system notes.
        </p></li><li><p>
        <a href="http://developer.postgresql.org/docs/postgres/kernel-resources.html" target="_top">Managing Kernel Resources (development version)</a>
          This information may be experimental.
        </p></li><li><p>
        <a href="http://www.varlena.com/varlena/GeneralBits/Tidbits/perf.html" target="_top">Tuning PostgreSQL for performance</a></p></li></ul></div></li></ol></div></li></ul></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="install-postgres-moreinfo"></a>more information about PostgreSQL</h3></div></div><div></div></div><div class="itemizedlist"><ul type="disc"><li><p>

          <a href="http://www.postgresql.org/idocs/" target="_top">Official PostgreSQL
          Docs</a>

        </p></li><li><p>


          <a href="http://pascal.scheffers.net/openacs/pgupdate/" target="_top">Migrating
          from 7.0 to 7.1</a>

        </p></li><li><p>

          <a href="http://techdocs.postgresql.org" target="_top">techdocs.postgresql.org</a>

        </p></li><li><p>
          
          <a href="http://www.linuxjournal.com/article.php?sid=4791" target="_top">PostgreSQL
        Performance Tuning</a>

        </p></li></ul></div><div class="cvstag">($Id: postgres.html,v 1.49.2.2 2011/06/12 20:52:57 donb Exp $)</div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="oracle.html">Prev</a> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right"> <a accesskey="n" href="aolserver4.html">Next</a></td></tr><tr><td width="40%" align="left">Install Oracle 8.1.7 </td><td width="20%" align="center"><a accesskey="u" href="complete-install.html">Up</a></td><td width="40%" align="right"> Install AOLserver 4</td></tr></table><hr><address><a href="mailto:docs@openacs.org">docs@openacs.org</a></address></div><a name="comments"></a><center><a href="http://openacs.org/doc/current/postgres.html#comments">View comments on this page at openacs.org</a></center></body></html>