Requirements
------------

Please note that OpenBSD port of the PostgreSQL server requires a
kernel compiled with SYSVSEM and SYSVSHM options for proper operation.
The GENERIC kernel has these settings.

Using PostgreSQL in an OpenBSD environment
------------------------------------------

If you are installing PostgreSQL for the first time a default database
will have been created for you. If this failed for any reason or if you
want to use non-default paramaters, you can do something similar to the
following steps manually:

       # su - _postgresql
       $ mkdir /var/postgresql/data
       $ initdb -D /var/postgresql/data

If you are upgrading PostgreSQL then you may have a `pgsql' or `postgresql'
user. It is suggested that you follow the steps in

	/usr/local/share/doc/postgresql/INSTALL

for more information on how to upgrade your existing databases. See
also `Special notes for OpenBSD port' below. Replace references to
the `postgresql' user below with `pgsql' or whatever other user you
have selected to be the database administration account.

Auto Start and Stop
-------------------

If you wish to start PostgreSQL automatically during system startup,
add the following lines to /etc/rc.local:

if [ -x /usr/local/bin/pg_ctl ]; then
	su -l _postgresql -c "nohup /usr/local/bin/pg_ctl start \
		-D /var/postgresql/data -l /var/postgresql/logfile \
		-o '-D /var/postgresql/data'"
	echo -n ' postgresql'
fi

To automatically shutdown the database as part of the system shutdown, 
add the following lines to /etc/rc.shutdown:

if [ -f /var/postgresql/data/postmaster.pid ]; then
	su -l _postgresql -c "/usr/local/bin/pg_ctl stop -m fast \
		-D /var/postgresql/data"
	rm -f /var/postgresql/data/postmaster.pid
fi

Network Connections and Tuning
------------------------------

To allow connections over TCP (and other options) edit the file:

	/var/postgresql/data/postgresql.conf

and also edit the pg_hba.conf (in the same directory) making the
appropriate changes to allow connection from your network.

The default sizes in the GENERIC kernel for SysV semaphores
are not really large enough for a database with more than a
handful of connections. A server running such a database should
have at least the following in /etc/sysctl.conf:

	kern.seminfo.semmni=256
	kern.seminfo.semmns=2048

To serve a large number of connections (>250), you may also need
to increase the maximum shared memory segment size, on the i386
try:

	kern.shminfo.shmmax=50331648	# this is 48MB.
					# default on i386 is 32MB
					# other archs will vary

These numbers should be tuned depending on system use. You will also
need to tune the values in the postgresql.conf file to increase the
number of connections to the backend.

By default, the _postgresql user, and so the postmaster and backend
processes run in the login(1) class of "daemon". On a busy server,
it may be advisable to put the _postgresql user and processes in
their own login(1) class with tuned resources, such as more open
file descriptors etc.

For example, add this to the login.conf(5) file:

	postgresql:\
		:openfiles-cur=768:\
		:tc=daemon:

Rebuild the login.conf.db file if necessary:

	# cap_mkdb /etc/login.conf

Change the login class with either vipw(8) or chsh(8).

For more than about 250 connections, these numbers should be
increased. Please report any changes and experiences to the package
maintainers so that we can update this file for future versions.
