Commit e2fca7bd authored by Oliver Elphick's avatar Oliver Elphick

initial import

parents
# Makefile for postgresql-common Debian package
BINDIR = $(prefix)/bin
MANDIR = $(prefix)/man
CFLAGS = -g -Wall
PROGS = pg_wrapper
LINKS = pg_exec pg_default psql
SRCS = pg_wrapper.c pg_default.c pg_files.c pg_exec.c
OBJS = pg_wrapper.o pg_default.o pg_files.o pg_exec.o
all: pg_wrapper
clean:
-rm $(PROGS) $(LINKS) $(OBJS)
-rm *~
install: pg_wrapper
install pg_wrapper $(BINDIR)
$(LINKS): install
cd $(BINDIR) && \
for f in $(LINKS); do \
ln -f pg_wrapper $f \
done
pg_wrapper: $(OBJS)
gcc $(CFLAGS) $(OBJS) -o $@
$(OBJS): pg_wrapper.h
postgresql TODO
===============
Things that need doing in the new PostgreSQL packaging for Debian.
1. Man pages are installed in /usr/share/postgresql<X.X>/man. Provide a
program to be run by the postinst script to run update-alternatives
on every manpage to link it to /usr/share/man/man<X>/<page>
2. Write pg_ctl_common to start or stop all database versions at once.
3. Work out the contents of /etc/default/postgresql.conf,
/etc/default/postgresql/x.x, /etc/postgresql and /etc/postgresql/x.x.
4. Make do.maintenance version-specific. It needs to check
/etc/postgresql/cluster.ports in order to find out which ports to run a
vacuum on and /var/run/postgresql/.s.PGSQL.${PGPORT} to be sure the
postmaster for that port is running.
5. Write a utility to change the port on which a particular postmaster
is running or to create a database and start a postmaster on some
new port:
a. Prompt for current port (if any);
b. If current port is not blank:
shutdown the postmaster on that port
look up PostgreSQL version from
/etc/postgresql/cluster.ports
prompt for new port
move /etc/postgresql/<oldport> to .../<newport>
edit /etc/postgresql/<newport>/postgresql.conf
else
prompt for: cluster.ports parameters
write line in cluster.ports
create /etc/postgresql/<newport>
initdb
move $PGDATA/config files to /etc/postgresql/<newport> and
create symlinks in their place
c. Start postmaster on the new port
6. There is a conflict between libecpg4.2 and libecpg4.1. Both provide
libecpg_compat.so.1.1 and libpgtypes.so.1.2. Do we remove them from
libecpg4.1? or do we create new binary packages for them? Ask Michael.
7. The init routine needs to be moved to postgresql-common and to read
cluster_ports to see what to do. postgresql-contribx.x need to check
a file supplied by postgresql-common to see whether and with what
parameters to run autovacuum.
8. Do we need separate pam files in each source package?
9. Should we do a general debconf query for all pg versions? rather than
one per source package?
# This file maps PostgreSQL database clusters against their database
# versions, the ports on which their postmasters are to listen, the Unix
# logins of their administrators and the directories where their data are
# to be found.
#
# Cluster: the name of the cluster; this must be unique in this file.
# Status: "active" if a postmaster should be started at boot time;
# "inactive" if it can only be started by the administrator;
# "upgrading" only when the database is being upgraded from
# one major version to another - an "upgrading" database is
# inaccessible except to the administrator;
# "failed-upgrade" if an upgrade failed.
# Owner: The Unix login of the cluster owner and administrator.
# Version: The database version of the cluster.
# Port: The port on which this cluster's postmaster should listen;
# ports 5430 and 5431 are reserved for cluster upgrades.
# Pgdata: The pathname of the data directory for this cluster.
#
# This file will be altered by initdb, which will add lines when a
# new cluster is created. pg_version_upgrade will change the active flag
# to "upgrading" while an upgrade is taking place
#
# CLUSTER STATUS OWNER VERSION PORT CLUSTERPATH
.\" Hey, Emacs! This is an -*- nroff -*- source file.
.\"
.TH CLUSTER_PORTS 5 "November 2003" "Debian Project" "Debian Linux"
.SH NAME
cluster_ports \- File linking PostgreSQL clusters to ports
.SH DESCRIPTION
.P
This file maps PostgreSQL database clusters against their database
versions, the ports on which their postmasters are to listen, the Unix
logins of their administrators and the directories where their data are
to be found.
.SH FORMAT
.P
Comments are introduced by the character
.BR # .
Comments may follow data on a line; the first comment character terminates
the data.
Leading whitespace and blank lines are ignored.
.P
Each uncommented, non-blank line describes a cluster.
.P
Fields must be given in the following order, separated by whitespace:
.TP
.B CLUSTER
The name of the cluster; this must be unique in this file.
.TP
.B STATUS
.IP ""
.RB "'" active "'"
if a postmaster should be started at boot time;
.IP ""
.RB "'" inactive "'"
if it can only be started by the administrator;
.IP ""
.RB "'" upgrading "'"
only when the database is being upgraded from
one major version to another - an 'upgrading' database is
inaccessible except to the administrator;
.IP ""
.RB "'" failed-upgrade "'"
if an upgrade failed.
.TP
.B OWNER
The Unix login of the cluster owner and administrator. This must not
be
.BR root .
.TP
.B VERSION
The database version of the cluster. This value should be the same as
that recorded in $PGDATA/PG_VERSION. It is required here in case the
wrapper program should not have the permissions to read that file.
.TP
.B PORT
The port on which this cluster's postmaster should listen;
ports 5430 and 5431 are reserved for cluster upgrades.
The cluster whose postmaster listens on port 5432 is the default cluster
for any user who does not match any line in
.IR user_clusters .
.TP
.B CLUSTERPATH
The pathname of the directory containing the data directory for this cluster.
.SH NOTES
This file will be altered by initdb (when run by root or postgres)
which will add lines when a new cluster is created.
.B pg_version_upgrade
will change the active flag to
.B upgrading
while an upgrade is taking place.
.P
If you wish to edit this file to change the port numbers
attached to clusters, you must use
.B /etc/init.d/postgresql stop
to stop all the postmasters. If you do not, from the time you file
your changes, the postmasters will still be listening on the old ports
but users connecting though this system will be connecting to the new
ports. Users will not be pleased with you...
.P
Use
.B /etc/init.d/postgresql start
when you have filed your changes.
.SH EXAMPLE
# CLUSTER STATUS USER PORT CLUSTERPATH
.PD 0
.P
postgresql active postgres 5432 /var/lib/postgres/db # 7.3
.P
developers inactive postgres 5433 /var/lib/postgres/devel # 7.4
.P
mycustomer01 active cust01 5436 /usr3/cust/cust01 # 7.3
.PD
.SH SEE ALSO
.BR pg_wrapper (1),
.BR user_clusters (5)
.SH AUTHOR
Oliver Elphick
.RI < olly@lfix.co.uk >
postgresql-common (1) unstable; urgency=low
* New package to provide a common infrastructure for different PostgreSQL
versions.
-- Oliver Elphick <olly@lfix.co.uk> Mon, 29 Oct 2004 21:58:52 +0100
Source: postgresql-common
Section: misc
Priority: optional
Maintainer: Oliver Elphick <Oliver.Elphick@lfix.co.uk>
Uploaders: Martin Pitt <mpitt@debian.org>
Standards-Version: 3.6.1
Build-Depends: debhelper (>= 4.1.29)
Package: postgresql-common
Architecture: any
Section: misc
Conflicts: postgresql (<= 7.4.2-3), postgresql-client (<= 7.4.2-3)
Replaces: postgresql (<= 7.4.2-3), postgresql-client (<= 7.4.2-3)
Depends: postgresql-client7.4 | postgresql-client7.3 | postgresql-client7.2 | postgresql-client8.0
Description: Manager for PostgreSQL database clusters
postgresql-common provides a structure under which multiple versions of
PostgreSQL may be installed and/or multiple clusters maintained at one
time.
.
This package is required by the postgresqlx.x packages themselves and also
by the postgresql-clientx.x frontend packages.
.
PostgreSQL is an object-relational database, which supports a large part
of SQL 99. It is the free software rival to Oracle.
This package was written for Debian by Oliver Elphick olly@lfix.co.uk.
Copyright (c) 2004 Oliver Elphick.
This software is licensed under the GNU General Public Licence, version
2 or later (at the licensee's option). A full copy of the license is
to be found at /usr/share/common-licenses/GPL-2 on any Debian system.
In the event that this package is copied for use in a non-Debian system,
a copy of the licence must be included with it.
# Regular cron jobs for the postgresql-common package
#
#[TODO] check the pathnames and the operation of do.maintenance to ensure that this
# correcly vacuums all database clusters
#
# To ensure proper access rights, 'ident sameuser' access for localhost is
# required in /etc/postgresql/pg_hba.conf. This is now the default setting for
# the Debian configuration.
#
# If password access for local is turned on in /etc/postgresql/<port>/pg_hba.conf,
# you must create a file ~postgres/.pgpass containing a line specifying the
# password, as explained in section 1.11 of the PostgreSQL Programmer's Guide
# (package postgresql-doc8.0).
#
# If autovacuum is turned on in /etc/default/postgresql/<port>, you need
# to give the -F option to do.maintenance for it to do anything.
# Run VACUUM ANALYSE on all databases every 5 hours if pg_autovacuum is not
# running
2 0,5,10,15,20 * * 1-6 postgres if [ -z "`ps --no-headers -C pg_autovacuum`" -a -x /usr/lib/postgresql/bin/do.maintenance ]; then /usr/lib/postgresql/bin/do.maintenance -a; fi
# On Sunday you may wish to run a VACUUM FULL ANALYSE as well
# If you do not run a 24/7 site, you may want to uncomment the next line
# so as to do a regular VACUUM FULL. If you need 24/7 connectivity, save
# VACUUM FULL for when you think you really need it
# 10 3 * * Sun postgres /usr/bin/test -x /usr/lib/postgresql/8.0/bin/do.maintenance && /usr/lib/postgresql/8.0/bin/do.maintenance -a -f -F
#! /bin/bash
#
# [TODO] convert this script to read /etc/postgresql/cluster.ports and to see
# to the vacuuming of every listed cluster
# Script for automatic maintenance of Debian PostgreSQL8.0, to be run by cron,
# with the owner being the postgres superuser
# Use of this script with PostgreSQL passwords is likely to be insecure.
# The preferred method for ensuring access is to have "ident" authentication
# enabled by having this line in /etc/postgresql/8.0/pg_hba.conf:
#
# local all postgres ident sameuser
#
# this will allow the postgres superuser on the local machine to connect as
# itself without giving a password. This is the default configuration for
# the Debian package.
#
# If password access for "local" is turned on in
# /etc/postgresql/8.0/pg_hba.conf,
# you must create a file ~postgres/.pgpass containing a line specifying the
# password, as explained in section 1.11 of the PostgreSQL Programmer's Guide
# (package postgresql-doc).
. /etc/default/postgresql/8.0
syntax() {
echo Syntax: $0 [-v] [-a] [-f] [-F] [-u user] [-u]
exit 1
}
verbose=
analyse=
while getopts aFfvu: arg
do
case $arg
in
a)
analyse=ANALYZE
;;
F)
force=FORCE
;;
f)
full=FULL
;;
v)
verbose=VERBOSE
;;
u)
user=$OPTARG
;;
*)
syntax;;
esac
done
/usr/sbin/invoke-rc.d --query postgresql start
if [ $? -ne 104 ]
then
[ -n "$verbose" ] &&
echo "PostgreSQL is currently disabled by update-rc.d or file-rc"
exit 1
fi
if [ ! -S /var/run/postgresql/.s.PGSQL.${PGPORT} ]
then
[ -n "$verbose" ] &&
echo "The PostgreSQL8.0 postmaster is not running (there is no UNIX socket)"
exit 1
fi
if [ -r $PGDATA/postmaster.pid ]
then
# check the postmaster is running
if ! /bin/kill -0 `sed '2,$d' $PGDATA/postmaster.pid`
then
[ -n "$verbose" ] &&
echo "The PostgreSQL8.0 postmaster is not running (no process)"
exit 1
fi
fi
if [ -r $PGDATA/autovacuum.pid ]
then
# check if autovacuum is running
if /bin/kill -0 `cat $PGDATA/autovacuum.pid`
then
if [ -z "$force" ]
then
echo "The PostgreSQL8.0 autovacuum daemon is running and force is not enabled"
exit 1
fi
fi
fi
if [ -n "$user" ]
then
UNAME="-U$user"
fi
dblist=$(/usr/lib/postgresql/8.0/bin/psql $UNAME -q -t -d template1 -P border=0 -c "
SELECT datname
FROM pg_database
WHERE datallowconn
ORDER BY datname")
IFS='
'
(
for database in $dblist
do
echo "\c '${database}'"
echo "vacuum ${full} ${verbose} ${analyse};"
done
) | /usr/lib/postgresql/8.0/bin/psql -d template1 -t -q ${UNAME} 2>&1
usr/bin
usr/share/doc/postgresql-common
etc/postgresql
usr/bin/pg_wrapper usr/bin/pg_exec
usr/bin/pg_wrapper usr/bin/pg_default
usr/bin/pg_wrapper usr/bin/psql
usr/bin/pg_wrapper usr/bin/pg_dump
usr/bin/pg_wrapper usr/bin/pg_dumpall
usr/bin/pg_wrapper usr/bin/initdb
usr/bin/pg_wrapper usr/bin/createdb
usr/bin/pg_wrapper usr/bin/createuser
usr/bin/pg_wrapper usr/bin/dropdb
usr/bin/pg_wrapper usr/bin/dropuser
usr/bin/pg_wrapper usr/bin/pg_restore
usr/bin/pg_wrapper usr/bin/clusterdb
usr/bin/pg_wrapper usr/bin/vacuumdb
usr/bin/pg_wrapper usr/bin/psql
#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# This file is public domain software, originally written by Joey Hess.
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
build: build-stamp
build-stamp:
dh_testdir
# Add here commands to compile the package.
$(MAKE)
touch build-stamp
clean:
dh_testdir
dh_testroot
rm -f build-stamp
# Add here commands to clean up after the build process.
-$(MAKE) clean
#-$(MAKE) distclean
dh_clean
install: build
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs
# Add here commands to install the package into debian/<packagename>
$(MAKE) prefix=`pwd`/debian/`dh_listpackages`/usr install
# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.
# Build architecture-dependent files here.
binary-arch: build install
install -m 644 cluster_ports user_clusters `pwd`/debian/`dh_listpackages`/etc/postgresql/
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installcatalogs
# dh_installpam
# dh_installmime
# dh_installinit
# dh_installcron
# dh_installinfo
# dh_undocumented
dh_installman *[1-8]
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
# dh_python
# dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
# Default values for postgresql-common and for all versioned postgresql
# packages
# Copyright (c) Oliver Elphick 2003
# Part of the Debian package, postgresql. The Debian packaging is
# licensed under GPL v.2
#
# POSTGRES_HOME is the PostgreSQL administrator's home directory. (The
# administrator is not typically a real user, but a system user for which
# direct login is disabled. On Debian, this user is 'postgres'.)
POSTGRES_HOME=/var/lib/postgres
# Where to find the PostgreSQL database clusters. This is the parent
# of all clusters installed by versioned packages and the default location
# for those created by initdb.
POSTGRES_CLUSTERS=/var/lib/postgres/clusters
# Any special options to pass to the postmaster through pg_ctl's -o option.
# This may include such options as "-h hostname", for which there is no
# parameter defined. However most options can be set by editing
# postgresql.conf appropriately.
POSTMASTER_OPTIONS=""
# Minimum number of entries in the kernel file table. If the table size is
# lower, postgresql.startup attempts to increase it by writing this parameter
# into /proc/sys/kernel/file-max. This is only effective if the kernel has
# been compiled to support run-time configuration.
#
# This parameter is multiplied by the number of clusters before being
# applied to the system.
KERNEL_FILE_MAX=1032
# Logging directory for output from the postmasters.
#
# Warning: if you use syslog for logging (syslog=2 in postgresql.conf) for
# any cluster, you may not be able to distinguish the output for different
# postmasters, unless you take special steps to have syslog put its logging
# into separate files.
#
# You can override this setting for individual clusters
#
# If you change this, remember to change /etc/logrotate.d/postgresql too.
POSTGRES_LOGDIR=/var/log/postgresql/
#!/usr/bin/perl -d
#
# pg_ctl_common
#
# Script to start multiple PostgreSQL postmasters according to the
# configuration
#
my $ix = 0;
my $action = "";
my $cluster;
print @ARGV,"\n";
if ( $ARGV[0] eq "-c" ) {
$cluster = $ARGV[1];
$ix = 2;
}
$action = $ARGV[$ix++];
if ($action eq "start" || $action eq "reload" || $action eq "status") {
print "Action = $action\n";
} elsif ($action eq "stop" || $action eq "restart") {
if ($ARGV[$ix++] eq "-m") {
$mode = $ARGV[$ix];
} else {
$mode = "fast";
}
print "Action = $action; mode = $mode\n";
} else {
print "Syntax: pg_ctl_common [-c cluster] start|stop|restart|reload|status\n";
exit 1;
}
my ($clname, $status, $owner, $version, $port, $path);
open CLUSTER_PORTS, "/etc/postgresql/cluster_ports" or die "Cannot open /etc/postgresql/cluster_ports";
while (<CLUSTER_PORTS>) {
if (m/^ *#/) {
print "Comment: $_\n";
} else {
sscanf $_, '%s %s %s %s %s %s', $clname, $status, $owner, $version, $port, $path;
printf "Cluster: %s; Status: %s; Owner: %s; Version: %s; Port: %s; Path: %s\n", $clname, $status, $owner, $version, $port, $path;
if (! defined $cluster || $cluster eq $clname) {
# operate on this line
# Check that we have permission for the operation
if ($uid != 0 && $USER ne $owner) {
printf "Need root permission to operate on cluster $clname\n"
} else {
if ($uid == 0) { # adopt the correct identity here # }
$cmd = "/usr/lib/postgresql/$version/bin/pg_ctl -D $path";
setenv PGPORT, $port;
if (action eq "start") {
$options = "-p /usr/lib/postgresql/$version/bin/postmaster ";
} elsif ($action eq "stop" || $action eq "restart") {
$options = "-m $mode";
}
system("$cmd $options");
}
if ($uid == 0) { # abandon assumed identity # };
}
}
}
.\" Hey, Emacs! This is an -*- nroff -*- source file.
.\"
.TH PG_DEFAULT 1 "October 2003" "Debian Project" "Debian Linux"
.SH NAME
pg_default \- Sets cluster and database for PostgreSQL commands
.SH SYNOPSIS
.P
.B pg_default
.BR -a " | "
.BI -u " user "
.RB "| " -g
.I " group"
.RB [ -f ]
.BI -c " cluster"
[
.BI -d " database"
]
.P
.B pg_default
[
.BI -c " cluster"
[
.BI -d " database"
]] | [-V]
.SH OPTIONS
.TP
.BI -u " user"
Specify the Unix login for which the defaults are to be set.
This option may be used only by root or the administrator.
.TP
.BI -g " group"
Specify the Unix group for which the defaults are to be set.
This option may be used only by root or the administrator.
.TP
.B -a
Specify the default choice for all users, that will apply if no more
specific match of user or group is found.
This option may be used only by root or the administrator.
.TP
.B -f
Set the FORCED flag in
.IR user_clusters ,
so that the user is unable to override the choice made for him.
This option may be used only by root or the administrator.
.TP
.BI -c " cluster"
Specify the name of the cluster (in
.IR cluster_ports )
to which the user should connect by default when a PostgreSQL command is run.
.TP
.BI -d " database"
Specify the name of the database within the specified cluster to which the
user should connect by default. If
.I database
is *, the connection will be to a database whose name is the same as the
user's login.
.TP
.B -V
When
.B pg_default
is used to report the current settings, this option makes
it report the default system settings as well as the user's own settings,
or it reports that the system settings cannot be overridden.
.SH DESCRIPTION
.P
When
.B pg_default
is run with no options, it reports the default database
and cluster for the current user.
If
.B -c
is specified,
.B pg_default
sets the PostgreSQL cluster for a user, and the database too, if
.B -d
is also given.
.P
The superuser (root) or the PostgreSQL administrator (postgres) may
use the
.B -u
and
.B -g
options to set the defaults for another user and the
.B -a
option to set the default cluster and database.
The
.B -f
option is used to set the FORCED flag in
.IR user_clusters ,
so that the user
is not permitted to override the administrator's choices for him.
.P
Other users can set only their own options, which are stored in
.IR ~/.postgresqlrc .
.SH FILES
.TP
.I /etc/postgresql/user_clusters
stores the default cluster and database for users and groups as set by
the administrators. By setting the FORCED flag for a user or group, it
is possible for an administrator to override a
user's choices so that the user can connect only to the cluster and
database selected for him.
.TP
.I $HOME/.postgresqlrc
stores defaults set by the user himself.
.SH BUGS
The FORCED flag is meant to protect naive users from stupid mistakes. It
is not a security measure, since it can easily be bypassed by entering the
desired pathname and setting PGPORT directly.
.SH SEE ALSO
.BR pg_exec (1),
.BR pg_wrapper (1)
.SH AUTHOR
Oliver Elphick <olly@lfix.co.uk>
#/*
pg_default.c
Set defaults for pg_wrapper.
Copyright (c) 2003 Oliver Elphick <olly@lfix.co.uk>
Licence: GNU Public Licence v.2 or later
*/
#include "pg_wrapper.h"
#include "pg_vars.h"