Index: openacs-4/packages/acs-core-docs/www/xml/install-guide/postgres.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/xml/install-guide/postgres.xml,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-core-docs/www/xml/install-guide/postgres.xml 28 Feb 2003 05:27:39 -0000 1.7 +++ openacs-4/packages/acs-core-docs/www/xml/install-guide/postgres.xml 25 May 2003 19:17:10 -0000 1.8 @@ -1,218 +1,156 @@ - Install PostgreSQL 7.2.3 - + Install PostGreSQL 7.2.4 + - by Vinod Kurup + by Vinod Kurup - - Skip this page if you're not interested in PostgreSQL. - - - - Download the PostgreSQL source - - + Skip this section if you will run only Oracle. - Download PostgreSQL 7.2.3 from the mirror closest to you. The list of - mirrors is at http://www.postgresql.org. - Download it to /tmp. + OpenACS &version; will run with PostGreSQL 7.2.x or 7.3.2. It + has not been fully tested with 7.3.2; 7.2.4 is the recommended + version of PostgreSQL to use. - - - - As root, unpack it into - /usr/local/src - - - -joeuser:~$ su - -Password: *********** -root:~# cd /usr/local/src -root:/usr/local/src# tar xzf /tmp/postgresql-7.2.3.tar.gz - - - - - Create the Postgres user - - Still as root, 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. Also give the postgres user a - password: - + This page assumes you have downloaded postgresql to +/tmp/postgresql-7.2.4.tar.gz. If not, +get it. + - -root:~# groupadd web -root:~# useradd -g web -d /usr/local/pgsql postgres -root:~# passwd postgres - -root:~# mkdir -p /usr/local/pgsql -root:~# chown -R postgres.web /usr/local/pgsql /usr/local/src/postgresql-7.2.3 -root:~# chmod 750 /usr/local/pgsql -root:~# exit -logout -joeuser:~$ su - postgres -Password: *********** - - - - Set up postgres's environment variables - - Edit /usr/local/pgsql/.bash_profile - so it looks like this: + + + Unpack PostGreSQL. +[root@yourserver root]# cd /usr/local/src +[root@yourserver src]# tar xzf /tmp/postgresql-7.2.4.tar.gz +[root@yourserver src]# +cd /usr/local/src +tar xzf /tmp/postgresql-7.2.4.tar.gz + + + + 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. - - -LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib -PATH=$PATH:/usr/local/pgsql/bin - -export PATH LD_LIBRARY_PATH - - - - Logout and login again as - postgres. Use the - echo command to make sure that - /usr/local/pgsql/bin is now in your - PATH - - - - -postgres:~$ exit -logout -joeuser:~$ su - postgres -Password: ************ -postgres:~$ echo $PATH -/usr/local/bin:/usr/bin:/bin: ... :/usr/local/pgsql/bin - - - + + [root@yourserver src]# groupadd web +[root@yourserver src]# useradd -g web -d /usr/local/pgsql postgres +[root@yourserver src]# mkdir -p /usr/local/pgsql +[root@yourserver src]# chown -R postgres.web /usr/local/pgsql /usr/local/src/postgresql-7.2.4 +[root@yourserver src]# chmod 750 /usr/local/pgsql +[root@yourserver 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.2.4 +chmod 750 /usr/local/pgsql + + + Set up postgres's environment variables. They are + necessary for the executable to find its supporting + libraries. For convenience, we'll simply append the necessary + lines to the postgres shell config file. + [root@yourserver src]# echo "export LD_LIBRARY_PATH=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib" >> ~postgres/.bashrc +[root@yourserver src]# echo "export PATH=$PATH:/usr/local/pgsql/bin" >> ~postgres/.bashrc +echo "export LD_LIBRARY_PATH=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib" >> ~postgres/.bashrc +echo "export PATH=$PATH:/usr/local/pgsql/bin" >> ~postgres/.bashrc + Test this by logging in as + postgres and checking the + paths; you should see /usr/local/pgsql/bin + [root@yourserver src]# su - postgres +[postgres@yourserver pgsql]$ env | grep PATH +LD_LIBRARY_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@yourserver pgsql]$ exit + + + + Compile and install PostgreSQL - - First, we run ./configure to set the - compilation options automatically. This is the point at which you can + 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. For example, if you want to - enable - Unicode support, add the flags - --enable-locale and - --enable-multibyte. If you want to - see what the other possibilities are, run ./configure - --help. - + enable + UnicodeUnicodein PostGreSQL support, add the flags --enable-locale and --enable-multibyte. If you want to see what the other possibilities are, run ./configure --help. - - -postgres:~$ cd /usr/local/src/postgresql-7.2.3 -postgres:/usr/local/src/postgresql-7.2.3$ ./configure -postgres:/usr/local/src/postgresql-7.2.3$ make all - - - - Compilation will take a while (about 10 minutes). Once it's done, you - will see the following message: - - - - -All of PostgreSQL is successfully made. Ready to install. - - - - Next, we'll install PostgreSQL. If all is successful, you'll see the - following Thank You message. - - - - -postgres:/usr/local/src/postgresql-7.2.3$ make install -... -Thank you for choosing PostgreSQL, the most advanced open source database engine. - - - - Prepare PostgreSQL for OpenFTS - - - OpenFTS is the module that provides full text search to OpenACS - &version;. We won't be installing it until later, but since it needs - a special PostgreSQL module called 'tsearch', we'll install it now. - - - -postgres:/usr/local/src/postgresql-7.2.3$ cd contrib/tsearch -postgres:/usr/local/src/postgresql-7.2.3/contrib/tsearch$ make -postgres:/usr/local/src/postgresql-7.2.3/contrib/tsearch$ make install - - - + + [root@yourserver src]# su - postgres +[postgres@yourserver pgsql]$ cd /usr/local/src/postgresql-7.2.4 +[postgres@yourserver postgresql-7.2.4]$ ./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@yourserver postgresql-7.2.4]$ make all +make -C doc all +make[1]: Entering directory `/usr/local/src/postgresql-7.2.4/doc' +(many lines omitted) +make[1]: Leaving directory `/usr/local/src/postgresql-7.2.4/src' +All of PostgreSQL successfully made. Ready to install. +[postgres@yourserver postgresql-7.2.4]$ make install +make -C doc install +make[1]: Entering directory `/usr/local/src/postgresql-7.2.4/doc' +(many lines omitted) +Thank you for choosing PostgreSQL, the most advanced open source database +engine. +su - postgres +cd /usr/local/src/postgresql-7.2.4 +./configure +make all +make install + + + Start PostgreSQL - - The initdb command initializes the database. pg_ctl is used to start up PostgreSQL. - - - -postgres:/usr/local/src/postgresql-7.2.3/contrib/tsearch$ cd -postgres:~$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data -postgres:~$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start -postmaster successfully started - + + [postgres@yourserver tsearch]$ /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@yourserver tsearch]$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start +postmaster successfully started +[postgres@yourserver tsearch]$ +/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 - - - - - Set up plpgsql and allow your user to have access - - - Next, we'll install plpgsql into our PostgreSQL installation so that - we can use stored procedures. We'll also create a database user named - joeuser (replace with your own - username), so that you'll be able to access the database via - AOLserver. - - - - -postgres:~$ createlang plpgsql template1 -postgres:~$ # Test if we succeeded -postgres:~$ createlang -l template1 + + + Set up plpgsql 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@yourserver pgsql]$ createlang plpgsql template1 +[postgres@yourserver pgsql]$ createlang -l template1 Procedural languages - Name | Trusted? + Name | Trusted? ---------+---------- - plpgsql | t + plpgsql | t (1 row) -postgres:~$ createuser joeuser -Shall the new user be allowed to create databases? (y/n) y -Shall the new user be allowed to create more new users? (y/n) y -CREATE USER - - - - Test PostgreSQL - - - Create a database and try some simple commands. The output should be - as shown. - +[postgres@yourserver pgsql]$ +createlang plpgsql template1 +createlang -l template1 + + + Test PostgreSQL. Create a database and try some simple commands. The output should be as shown. - -postgres:~$ createdb mytestdb + [postgres@yourserver pgsql]$ createdb mytestdb CREATE DATABASE -postgres:~$ psql mytestdb +[postgres@yourserver pgsql]$ psql mytestdb Welcome to psql, the PostgreSQL interactive terminal. Type: \copyright for distribution terms @@ -221,62 +159,92 @@ \g or terminate with semicolon to execute query \q to quit -mytestdb=# select current_timestamp; - timestamp ------------------------- - 2001-12-20 14:24:30-05 +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'; +mytestdb=# create function test1() returns integer as 'begin return 1; end;' language 'plpgsql'; CREATE -mytestdb=# select test1(); - test1 +mytestdb=# select test1(); + test1 ------- 1 (1 row) -mytestdb=# \q -postgres:~$ dropdb mytestdb -DROP DATABASE +mytestdb=# \q +[postgres@yourserver pgsql]$ dropdb mytestdb +DROP DATABASE +[postgres@yourserver pgsql]$ exit +logout - - - - Getting PostgreSQL to start on boot - - - Download postgresql.txt to - /tmp. Then follow the instructions - specific to your distribution: - +[root@yourserver src]# + + + 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 so three sets of instructions are provided. + + Red Hat: + + [root@yourserver src]# cp /tmp/&tarballpath;/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql +[root@yourserver src]# chown root.root /etc/rc.d/init.d/postgresql +[root@yourserver src]# chmod 755 /etc/rc.d/init.d/postgresql +[root@yourserver src]# +cp /tmp/&tarballpath;/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 + + Test the script. + + [root@yourserver root]# service postgresql stop +Stopping PostgreSQL: ok +[root@yourserver root]# - - Debian: - - -postgres:~$ su - -Password: *********** -root:~# cp /tmp/postgresql.txt /etc/init.d/postgresql -root:~# chown root.root /etc/init.d/postgresql -root:~# chmod 700 /etc/init.d/postgresql - - Test the script - - -root:~# /etc/init.d/postgresql stop -Stopping PostgreSQL: ok - - - - If PostgreSQL successfully stopped, then use the following + If PostgreSQL successfully stopped, then use the following command to make sure that the script is run appropriately at boot - and shutdown. + and shutdown. And turn it back on because we'll use + it later. + + [root@yourserver root]# chkconfig --add postgresql +[root@yourserver root]# chkconfig --list postgresql +postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off +[root@yourserver root]# service postgresql start +Starting PostgreSQL: ok +[root@yourserver root]# +chkconfig --add postgresql +chkconfig --list postgresql +service postgresql start + + Debian: + root:~# cp /tmp/&tarballpath;/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql +root:~# chown root.root /etc/init.d/postgresql +root:~# chmod 700 /etc/init.d/postgresql +root:~# +cp /tmp/&tarballpath;/packages/acs-core-docs/www/files/postgresql.txt /etc/init.d/postgresql +chown root.root /etc/init.d/postgresql +chmod 700 /etc/init.d/postgresql + Test the script + + root:~# /etc/init.d/postgresql stop +Stopping PostgreSQL: ok +root:~# + + If PostgreSQL successfully stopped, then use the following + command to make sure that the script is run + appropriately at boot and shutdown. - -root:~# update-rc.d postgresql defaults + +root:~# update-rc.d postgresql defaults Adding system startup for /etc/init.d/postgresql ... /etc/rc0.d/K20postgresql -> ../init.d/postgresql /etc/rc1.d/K20postgresql -> ../init.d/postgresql @@ -285,55 +253,16 @@ /etc/rc3.d/S20postgresql -> ../init.d/postgresql /etc/rc4.d/S20postgresql -> ../init.d/postgresql /etc/rc5.d/S20postgresql -> ../init.d/postgresql -root:~# /etc/init.d/postgresql start +root:~# /etc/init.d/postgresql start Starting PostgreSQL: ok -root:~# exit -postgres:~$ exit - +root:~# + + + SuSE: + + + - Red Hat: - - -postgres:~$ su - -Password: *********** -root:~# cp /tmp/postgresql.txt /etc/rc.d/init.d/postgresql -root:~# chown root.root /etc/rc.d/init.d/postgresql -root:~# chmod 700 /etc/rc.d/init.d/postgresql - - - - Test the script. - - - - -root:~# /etc/rc.d/init.d/postgresql stop -Stopping PostgreSQL: ok - - - - If PostgreSQL successfully stopped, then use the following - command to make sure that the script is run appropriately at boot - and shutdown. - - - - -root:~# chkconfig --add postgresql -root:~# chkconfig --list postgresql -; You should see: -postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off -root:~# /etc/rc.d/init.d/postgresql start -Starting PostgreSQL: ok -root:~# exit -postgres:~$ exit - - - SuSE: - - - - I have received reports that SuSE 8.0 is different from previous versions. Instead of installing the boot scripts in /etc/rc.d/init.d/, they should @@ -343,24 +272,19 @@ following commands. - + + + root:~# cp /tmp/&tarballpath;/packages/acs-core-docs/www/files/postgresql.txt /etc/rc.d/init.d/postgresql +root:~# chown root.root /etc/rc.d/init.d/postgresql +root:~# chmod 700 /etc/rc.d/init.d/postgresql + - -postgres:~$ su - -Password: *********** -root:~# cp /tmp/postgresql.txt /etc/rc.d/init.d/postgresql -root:~# chown root.root /etc/rc.d/init.d/postgresql -root:~# chmod 700 /etc/rc.d/init.d/postgresql - - - Test the script. - -root:~# /etc/rc.d/init.d/postgresql stop -Stopping PostgreSQL: ok + root:~# /etc/rc.d/init.d/postgresql stop +Stopping PostgreSQL: ok @@ -369,38 +293,37 @@ and shutdown. + + root:~# cd /etc/rc.d/init.d +root:/etc/rc.d/init.d# ln -s /etc/rc.d/init.d/postgresql K20postgresql +root:/etc/rc.d/init.d# ln -s /etc/rc.d/init.d/postgresql S20postgresql +root:/etc/rc.d/init.d# cp K20postgresql rc2.d +root:/etc/rc.d/init.d# cp S20postgresql rc2.d +root:/etc/rc.d/init.d# cp K20postgresql rc3.d +root:/etc/rc.d/init.d# cp S20postgresql rc3.d +root:/etc/rc.d/init.d# cp K20postgresql rc4.d +root:/etc/rc.d/init.d# cp S20postgresql rc4.d +root:/etc/rc.d/init.d# cp K20postgresql rc5.d +root:/etc/rc.d/init.d# cp S20postgresql rc5.d +root:/etc/rc.d/init.d# rm K20postgresql +root:/etc/rc.d/init.d# rm S20postgresql +root:/etc/rc.d/init.d# + + - -root:~# cd /etc/rc.d/init.d -root:/etc/rc.d/init.d# ln -s /etc/rc.d/init.d/postgresql K20postgresql -root:/etc/rc.d/init.d# ln -s /etc/rc.d/init.d/postgresql S20postgresql -root:/etc/rc.d/init.d# cp K20postgresql rc2.d -root:/etc/rc.d/init.d# cp S20postgresql rc2.d -root:/etc/rc.d/init.d# cp K20postgresql rc3.d -root:/etc/rc.d/init.d# cp S20postgresql rc3.d -root:/etc/rc.d/init.d# cp K20postgresql rc4.d -root:/etc/rc.d/init.d# cp S20postgresql rc4.d -root:/etc/rc.d/init.d# cp K20postgresql rc5.d -root:/etc/rc.d/init.d# cp S20postgresql rc5.d -root:/etc/rc.d/init.d# rm K20postgresql -root:/etc/rc.d/init.d# rm S20postgresql - - - Test configuration. - - -root:/etc/rc.d/init.d # cd -root:~ # /etc/rc.d/init.d/rc2.d/S20postgresql start + + root:/etc/rc.d/init.d # cd +root:~ # /etc/rc.d/init.d/rc2.d/S20postgresql start Starting PostgreSQL: ok -root:~ # exit - - +root:~ # + + + + - - 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 @@ -409,15 +332,49 @@ little. This usually isn't a problem as Red Hat defaults to runlevel 3) - + + + + Tune postgres. OPTIONAL + The default values for PostGreSQL are very conservative; we can safely change some of them and improve performance. + + + + Change the kernel parameter for maximum shared memory + segment size to 128Mb: + [root@yourserver root]# echo 134217728 >/proc/sys/kernel/shmmax +[root@yourserver root]# + Make that change permanent by editing + emacs /etc/sysctl.conf to + add these lines at the end: +# increase shared memory limit for postgres +kernel.shmmax = 134217728 + + + Edit the PostGreSQL config file, /usr/local/pgsql/data/postgresql.conf to use more memory. These values should improve performance in most cases. (More information) + # Shared Memory Size +# +shared_buffers = 15200 # 2*max_connections, min 16 - - Learn more about PostgreSQL - +# Non-shared Memory Sizes +# +sort_mem = 32168 # min 32 - Here are some links: - +# Write-ahead log (WAL) +# +wal_files = 3 # range 0-64 +checkpoint_segments = 3 # in logfile segments (16MB each), min 1 + + Restart postgres (service postgres restart) so that the changes take effect. + + + + + + + + Learn more about PostgreSQL @@ -429,6 +386,7 @@ + Migrating from 7.0 to 7.1 @@ -449,7 +407,7 @@ Performance Tuning - +