6cb03e
README.rpm-dist
6cb03e
-----------------------------------------------------------------------------
6cb03e
Version 9.2, for the PostgreSQL 9.2 RPM set.
6cb03e
Devrim Gündüz <devrim@gunduz.org>
6cb03e
-----------------------------------------------------------------------------
6cb03e
6cb03e
Contents:
6cb03e
 1.)	Introduction and QuickStart
6cb03e
 2.)	Upgrading an installation
6cb03e
 3.)	PostgreSQL RPM packages and rationale
6cb03e
 4.)	Starting multiple postmasters
6cb03e
 5.)	Regression Testing
6cb03e
 6.)	Starting postmaster automatically on startup
6cb03e
 7.)	Grand Unified Configuration(GUC) File
6cb03e
 8.)	Logging set up
6cb03e
 9.)	Rebuilding from the source RPM
6cb03e
10.)	Contrib files
6cb03e
11.)	Further Information Resource
6cb03e
6cb03e
INTRODUCTION
6cb03e
-----------------------------------------------------------------------------
6cb03e
This document exists to explain the layout of the RPMs for PostgreSQL, to 
6cb03e
describe various RPM specifics, and to document special features found
6cb03e
in the RPMset.
6cb03e
6cb03e
This document is written to be applicable to version 9.2 of PostgreSQL,
6cb03e
which is the current version of the RPMs as of this writing. More to the 
6cb03e
point, versions prior to 9.2 are not documented here.
6cb03e
6cb03e
This document is intended for use only with the RPMs supplied in Red Hat
6cb03e
Enterprise Linux, CentOS and Fedora.  Note that there are also "PGDG"
6cb03e
RPMs available directly from the upstream PostgreSQL project.  Those are
6cb03e
slightly different.
6cb03e
6cb03e
QUICKSTART (note that this requires postgresql-server installed)
6cb03e
-----------------------------------------------------------------------------
6cb03e
For a fresh installation, you will need to initialize the cluster first. Run:
6cb03e
6cb03e
	postgresql-setup initdb
6cb03e
6cb03e
as root, and it will prepare a new database cluster for you. Then you will 
6cb03e
need to start PostgreSQL. Again as root, run:
6cb03e
6cb03e
	systemctl start postgresql.service
6cb03e
6cb03e
This command will start a postmaster that willl listen on localhost and Unix 
6cb03e
socket 5432 only.  Edit /var/lib/pgsql/data/postgresql.conf and pg_hba.conf 
6cb03e
if you want to allow remote access -- see the section on Grand Unified 
6cb03e
Configuration.
6cb03e
6cb03e
You will probably also want to do
6cb03e
6cb03e
	systemctl enable postgresql.service
6cb03e
6cb03e
so that the postmaster is automatically started during future reboots.
6cb03e
6cb03e
The file /var/lib/pgsql/.bash_profile is packaged to help with the 
6cb03e
setting of environment variables. You may edit this file, and it won't be
6cb03e
overwritten during an upgrade.  However, enhancements and bugfixes may 
6cb03e
be added to this file, so be sure to check .bash_profile.rpmnew after 
6cb03e
upgrading.
6cb03e
6cb03e
The user 'postgres' is created during installation of the server subpackage.
6cb03e
This user by default is UID and GID 26. The user has the default shell set to
6cb03e
bash, and the home directory set to /var/lib/pgsql.  This user also has no
6cb03e
default password, so the only way to become this user is to su to it from root.
6cb03e
If you want to be able to su to it from a non-root account or log in directly
6cb03e
as 'postgres' you will need to set a password using passwd.
6cb03e
6cb03e
UPGRADING AN INSTALLATION
6cb03e
-----------------------------------------------------------------------------
6cb03e
For a minor-version upgrade (such as 9.2.1 to 9.2.2), just install the
6cb03e
new RPMs; there's usually nothing more to it than that.  Upgrading
6cb03e
across a major release of PostgreSQL (for example, from 9.1.x to 9.2.x)
6cb03e
requires more effort.
6cb03e
6cb03e
If you are upgrading across more than one major release of PostgreSQL
6cb03e
(for example, from 8.3.x to 9.0.x), you will need to follow the "traditional"
6cb03e
dump and reload process to bring your data into the new version.  That is:
6cb03e
*before* upgrading, run pg_dumpall to extract all your data into a SQL file.
6cb03e
Shut down the old postmaster, upgrade to the new version RPMs, initdb,
6cb03e
and run the dump file through psql to restore your data.
6cb03e
6cb03e
In some major releases, the RPMs also support in-place upgrade from the
6cb03e
immediately previous major release.  Currently, you can upgrade in-place
6cb03e
from 9.1.x to 9.2.x.  This is much faster than a dump and reload.
6cb03e
To do an in-place upgrade:
6cb03e
* shut down the old postmaster ("systemctl stop postgresql.service")
6cb03e
* optionally make a backup of /var/lib/pgsql/data/ (recommended!)
6cb03e
* install the new version's RPMs (install all the ones you had before,
6cb03e
  plus postgresql-upgrade)
6cb03e
* as root, run "postgresql-setup upgrade"
6cb03e
* update the configuration files /var/lib/pgsql/data/*.conf with any
6cb03e
  customizations you had before (your old configuration files are in
6cb03e
  /var/lib/pgsql/data-old/)
6cb03e
* as root, run "systemctl start postgresql.service"
6cb03e
* the postgresql-upgrade RPM can be removed after the update is complete,
6cb03e
  as can /var/lib/pgsql/data-old/
6cb03e
6cb03e
NOTE: The in-place upgrade process is new and relatively poorly tested,
6cb03e
so if your data is critical it's a really good idea to make a tarball
6cb03e
backup of /var/lib/pgsql/data/ before running the upgrade.  This will
6cb03e
let you get back to where you were in case of disaster.
6cb03e
6cb03e
POSTGRESQL RPM PACKAGES AND RATIONALE.
6cb03e
-----------------------------------------------------------------------------
6cb03e
PostgreSQL is split up into multiple packages so that users can 'pick and
6cb03e
choose' what pieces are needed, and what dependencies are required.
6cb03e
6cb03e
The RPMset is packaged in the following subpackages:
6cb03e
6cb03e
postgresql:		Key client programs and documentation
6cb03e
postgresql-libs:	Client shared libraries
6cb03e
postgresql-server:	Server executables and data files
6cb03e
postgresql-devel:	Development libraries and include files
6cb03e
postgresql-test:	The regression tests and associated files
6cb03e
postgresql-upgrade:	Support files for upgrading from previous major version
6cb03e
postgresql-docs:	Extra documentation, such as the tutorial files
6cb03e
postgresql-contrib:	Add-on loadable modules and programs
6cb03e
postgresql-plperl:	PL/Perl procedural language
6cb03e
postgresql-plpython:	PL/Python procedural language (for Python 2)
6cb03e
postgresql-plpython3:	PL/Python procedural language (for Python 3)
6cb03e
postgresql-pltcl:	PL/Tcl procedural language
6cb03e
6cb03e
You have to install postgresql and postgresql-libs to do anything.
6cb03e
postgresql-server is needed unless you only plan to use the clients to work
6cb03e
with a remote PostgreSQL server. The others are optional.
6cb03e
6cb03e
Note that there are no postgresql-perl, postgresql-jdbc, postgresql-odbc,
6cb03e
postgresql-python, postgresql-tcl, or postgresql-tk subpackages any longer.
6cb03e
Those programs have been split off into separate source distributions.
6cb03e
They are still available, but in some cases not under those RPM names.
6cb03e
6cb03e
RPM FILE LOCATIONS.
6cb03e
-----------------------------------------------------------------------------
6cb03e
To be in compliance with the Linux FHS, the PostgreSQL RPMs install files in
6cb03e
a manner not consistent with most of the PostgreSQL documentation.  According
6cb03e
to the standard PostgreSQL documentation, PostgreSQL is installed under the
6cb03e
directory /usr/local/pgsql, with executables, source, and data existing in
6cb03e
various subdirectories.
6cb03e
6cb03e
Different distributions have different ideas of some of these file locations.
6cb03e
In particular, the documentation directory can be /usr/doc, /usr/doc/packages,
6cb03e
/usr/share/doc, /usr/share/doc/packages, or some other similar path.
6cb03e
6cb03e
However, the Red Hat / CentOS / Fedora RPM's install the files like 
6cb03e
this:
6cb03e
6cb03e
Executables:		/usr/bin
6cb03e
Libraries:		/usr/lib (or /usr/lib64 on 64-bit machines)
6cb03e
Documentation:		/usr/share/doc/postgresql-docs-x.y.z/html
6cb03e
Contrib documentation:	/usr/share/doc/postgresql-contrib-x.y.z
6cb03e
Source:			not installed
6cb03e
Data:			/var/lib/pgsql/data
6cb03e
Backup area:		/var/lib/pgsql/backups
6cb03e
Templates:		/usr/share/pgsql
6cb03e
Procedural Languages:	/usr/lib/pgsql or /usr/lib64/pgsql
6cb03e
Development Headers:	/usr/include/pgsql
6cb03e
Other shared data:	/usr/share/pgsql
6cb03e
Regression tests:	/usr/lib/pgsql/test/regress  (in the -test package)
6cb03e
			or /usr/lib64/pgsql/test/regress
6cb03e
6cb03e
While it may seem gratuitous to place these files in different locations, the
6cb03e
FHS requires it -- distributions should not ever touch /usr/local.  It may
6cb03e
also seem like more work to keep track of where everything is -- but, that's
6cb03e
the beauty of RPM -- you don't have to keep track of the files, RPM does it
6cb03e
for you.
6cb03e
6cb03e
These RPMs are designed to be LSB-compliant -- if you find this not to be the
6cb03e
case, please let us know by way of the pgsqlrpms-hackers@pgfoundry.org
6cb03e
mailing list.
6cb03e
6cb03e
MULTIPLE POSTMASTERS
6cb03e
-------------------------------------------------------------------------------
6cb03e
The postgresql-server RPM contains a systemd "unit" file, postgresql.service,
6cb03e
that is used to start the PostgreSQL postmaster.  If you need to run multiple
6cb03e
postmasters on one machine, you can create additional unit files derived
6cb03e
from this one.
6cb03e
6cb03e
As an example, let us create a secondary postmaster called, creatively enough,
6cb03e
'secondary'.  Here are the steps:
6cb03e
1.)	Create a file named /etc/systemd/system/secondary.service.
6cb03e
	(Note that user-created unit files must go into /etc not /lib!)
6cb03e
	Put these lines in it:
6cb03e
		.include /lib/systemd/system/postgresql.service
6cb03e
		[Service]
6cb03e
		Environment=PGPORT=nnnn
6cb03e
		Environment=PGDATA=/path/to/data/directory
6cb03e
	Replace "nnnn" and "/path/to/data/directory" with appropriate
6cb03e
	settings that don't conflict with any other postmaster.
6cb03e
2.)	As root, do "/bin/systemctl daemon-reload" to ensure systemd has
6cb03e
	noticed your updates to the service file.
6cb03e
3.)	Create the target PGDATA directory, making sure that its parent
6cb03e
	directories have appropriate ownership and permissions.
6cb03e
4.)	Initdb the target PGDATA with 'postgresql-setup initdb secondary'.
6cb03e
5.)	Edit postgresql.conf in the target PGDATA to change settings as needed.
6cb03e
6.)	Start the new postmaster with 'systemctl start secondary.service'.
6cb03e
	You will probably also want to do 'systemctl enable secondary.service'
6cb03e
	so that the new postmaster is automatically started in future reboots.
6cb03e
6cb03e
When doing a major-version upgrade of a secondary postmaster, add the
6cb03e
service name to the postgresql-setup command, for example 'postgresql-setup
6cb03e
upgrade secondary'.  This will let postgresql-setup find the correct data
6cb03e
directory from the service file.
6cb03e
6cb03e
If you are running SELinux in enforcing mode (which is highly recommended,
6cb03e
particularly for network-exposed services like PostgreSQL) you will need to
6cb03e
adjust SELinux policy to allow the postmaster to use non-default PGPORT or
6cb03e
PGDATA settings.  To allow use of a non-default port, say 5433, do this
6cb03e
as root:
6cb03e
	semanage port -a -t postgresql_port_t -p tcp 5433
6cb03e
To allow use of a non-default data directory, say /special/pgdata, do:
6cb03e
	semanage fcontext -a -t postgresql_db_t "/special/pgdata(/.*)?"
6cb03e
If you already created the directory, follow that with:
6cb03e
	restorecon -R /special/pgdata
6cb03e
These settings are persistent across reboots.  For more information
6cb03e
see "man semanage".
6cb03e
6cb03e
REGRESSION TESTING
6cb03e
-------------------------------------------------------------------------------
6cb03e
If you install the postgresql-test RPM then you can run the PostgreSQL
6cb03e
regression tests.  These tests stress your database installation and produce
6cb03e
results that give you assurances that the installation is complete, and that
6cb03e
your database machine is up to the task.
6cb03e
6cb03e
To run the regression tests under the RPM installation, make sure that the
6cb03e
postmaster has been started (if not, su to root and do "systemctl start
6cb03e
postgresql.service"), su to postgres, cd to /usr/lib/pgsql/test/regress
6cb03e
(or /usr/lib64/pgsql/test/regress on a 64-bit machine),
6cb03e
and execute "make check".
6cb03e
This command will start the regression tests and will both show the
6cb03e
results to the screen and store the results in the file regress.out.
6cb03e
6cb03e
If any tests fail, see the file regression.diffs in that directory for details,
6cb03e
and read the "Regression Tests" section of the PostgreSQL documentation to
6cb03e
find out whether the differences are actually significant.  If you need help
6cb03e
interpreting the results, contact the pgsql-general list at 
6cb03e
postgresql.org.
6cb03e
6cb03e
After testing, run "make clean" to remove the files generated by the test
6cb03e
script.  Then you can remove the postgresql-test RPM, if you wish.
6cb03e
6cb03e
STARTING POSTMASTER AUTOMATICALLY AT SYSTEM STARTUP
6cb03e
-------------------------------------------------------------------------------
6cb03e
Fedora / Red Hat / CentOS use the systemd package to manage server startup.
6cb03e
A systemd unit file for PostgreSQL is provided in the server package, as
6cb03e
/lib/systemd/system/postgresql.service.  To start the postmaster manually,
6cb03e
as root run
6cb03e
	systemctl start postgresql.service
6cb03e
To shut the postmaster down,
6cb03e
	systemctl stop postgresql.service
6cb03e
These two commands only change the postmaster's current status.  If you
6cb03e
want the postmaster to be started automatically during future system startups,
6cb03e
run
6cb03e
	systemctl enable postgresql.service
6cb03e
To undo that again,
6cb03e
	systemctl disable postgresql.service
6cb03e
See "man systemctl" for other possible subcommands.
6cb03e
6cb03e
GRAND UNIFIED CONFIGURATION (GUC) FILE
6cb03e
-------------------------------------------------------------------------------
6cb03e
The PostgreSQL server has many tunable parameters -- the file 
6cb03e
/var/lib/pgsql/data/postgresql.conf is the master configuration file for the
6cb03e
whole system.  
6cb03e
6cb03e
The RPM ships with a mostly-default file -- you will need to tune the
6cb03e
parameters for your installation.  In particular, you might want to allow
6cb03e
nonlocal TCP/IP socket connections -- in order to allow these, you will need
6cb03e
to edit the postgresql.conf file.  The line in question contains the string 
6cb03e
'listen_addresses' -- you need to both uncomment the line and set the value
6cb03e
to '*' to get the postmaster to accept nonlocal connections.  You'll also need
6cb03e
to adjust pg_hba.conf appropriately.
6cb03e
6cb03e
LOGGING SET UP
6cb03e
-------------------------------------------------------------------------------
6cb03e
By default, the postmaster's stderr log is directed into files placed in a
6cb03e
pg_log subdirectory of the data directory (ie, /var/lib/pgsql/data/pg_log).
6cb03e
The out-of-the-box configuration rotates among seven files, one for each
6cb03e
day of the week.  You can adjust this by changing postgresql.conf settings.
6cb03e
6cb03e
REBUILDING FROM SOURCE RPM
6cb03e
-------------------------------------------------------------------------------
6cb03e
If your distribution is not supported by the binary RPMs from PostgreSQL.org, 
6cb03e
you will need to rebuild from the source RPM.
6cb03e
6cb03e
If you have not previously rebuilt any RPMs, set up the required environment:
6cb03e
make a work directory, say ~/rpmwork, then cd into it and do
6cb03e
	mkdir BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
6cb03e
Then make a file ~/.rpmmacros containing
6cb03e
	%_topdir <full path to work directory here>
6cb03e
6cb03e
Download the postgresql .src.rpm for the release you want and place it in
6cb03e
the SRPMS subdirectory, then cd there and execute
6cb03e
	rpmbuild --rebuild postgresql-nnn.src.rpm
6cb03e
The results will appear under the RPMS subdirectory.
6cb03e
6cb03e
You will have to have a full development environment to rebuild the RPM set.
6cb03e
If rpmbuild complains of lack of certain packages, install them and try
6cb03e
again.  In some cases, you can disable features to avoid needing some
6cb03e
development packages, as detailed next.
6cb03e
6cb03e
This release of the RPMset includes the ability to conditionally build 
6cb03e
sets of packages.  The parameters, their defaults, and the meanings are:
6cb03e
6cb03e
beta		0	#build with cassert and do not strip the binaries
6cb03e
runselftest	1	#do "make check" during the build
6cb03e
test		1	#build the postgresql-test package
6cb03e
upgrade		1	#build the postgresql-upgrade package
6cb03e
plpython	1	#build the PL/Python procedural language package
6cb03e
plpython3	1	#build the PL/Python3 procedural language package
6cb03e
pltcl		1	#build the PL/Tcl procedural language package
6cb03e
plperl		1	#build the PL/Perl procedural language package
6cb03e
ssl		1	#build with OpenSSL support
6cb03e
kerberos	1	#build with Kerberos 5 support
6cb03e
ldap		1	#build with LDAP support
6cb03e
nls		1	#build with national language support
6cb03e
pam		1	#build with PAM support
6cb03e
sdt		1	#build with SystemTap support
6cb03e
xml		1	#build with XML support
6cb03e
pgfts		1	#build with --enable-thread-safety
6cb03e
selinux		1	#build contrib/selinux
6cb03e
uuid		1	#build contrib/uuid-ossp
6cb03e
6cb03e
To use these defines, invoke a rebuild like this:
6cb03e
rpmbuild --rebuild --define 'plpython 0' --define 'pltcl 0' \
6cb03e
	--define 'test 0' --define 'runselftest 0' --define 'kerberos 0' \
6cb03e
	postgresql-9.2.0-1.src.rpm
6cb03e
This line would disable the plpython, pltcl, and test subpackages, disable
6cb03e
the regression test run during build, and disable kerberos support.
6cb03e
6cb03e
You might need to disable runselftest if there is an installed version of
6cb03e
PostgreSQL that is a different major version from what you are trying to
6cb03e
build.  The self test tends to pick up the installed libpq.so shared library
6cb03e
in place of the one being built :-(, so if that isn't compatible the test will
6cb03e
fail.  Also, you can't use runselftest when doing the build as root.
6cb03e
6cb03e
More of these conditionals will be added in the future.
6cb03e
6cb03e
CONTRIB FILES
6cb03e
-------------------------------------------------------------------------------
6cb03e
The contents of the contrib tree are packaged into the -contrib subpackage
6cb03e
and are processed with make and make install.  There is documentation in
6cb03e
/usr/share/doc/postgresql-contrib-VERSION for these modules.  Most of the
6cb03e
modules are in /usr/lib/pgsql (or /usr/lib64/pgsql) for loadable
6cb03e
modules, and binaries are in /usr/bin.  In the future these files may be
6cb03e
split out, depending upon function and dependencies.
6cb03e
6cb03e
MORE INFORMATION
6cb03e
-------------------------------------------------------------------------------
6cb03e
You can get more information at http://www.postgresql.org and 
6cb03e
http://yum.pgsqlrpms.org
6cb03e
6cb03e
Please help make this packaging better -- let us know if you find problems, or
6cb03e
better ways of doing things. You can reach us by e-mail at
6cb03e
pgsqlrpms-hackers@pgfoundry.org
6cb03e
-------------------------------------------------------------------------------