Newer
Older
# Call a PostgreSQL client program with the version, cluster and default
# database specified in ~/.postgresqlrc or
# /etc/postgresql-common/user_clusters.
#
# (C) 2005 Martin Pitt <mpitt@debian.org>
use lib '/usr/share/postgresql-common';
use PgCommon;
# Check for PGCLUSTER in %ENV
if (defined $ENV{PGCLUSTER}) {
($version, $cluster) = split ('/', $ENV{PGCLUSTER}, 2);
error 'Invalid version specified with $PGCLUSTER' unless $version;
error 'Invalid cluster specified with $PGCLUSTER' unless $cluster;
error 'Cluster specified with $PGCLUSTER does not exist' unless cluster_exists $version, $cluster;
}
# Check for --cluster argument and filter it out
if ($ARGV[$i] eq '--cluster') {
error '--cluster option needs an argument (<version>/<cluster>)' if ($i >= $#ARGV);
($version, $cluster) = split ('/', $ARGV[$i+1], 2);
error 'No version specified with --cluster' unless $version;
error 'No cluster specified with --cluster' unless $cluster;
error 'Cluster does not exist' unless cluster_exists $version, $cluster;
splice @ARGV, $i, 2;
last;
}
}
# Determine $version, $cluster, $db, $port from map files
($version, $cluster, $db) = user_cluster_map() unless $cluster;

Martin Pitt
committed
$port = get_cluster_port($version, $cluster);
unless ($ENV{'PGHOST'}) {
# default to cluster specific Unix socket directory
$ENV{'PGHOST'} = get_cluster_socketdir $version, $cluster;
}
$ENV{'PGPORT'} = "$port" if $port && !$ENV{'PGPORT'};
error 'You must install at least one postgresql-client-<version> package.' unless $version;
error 'Invalid PostgreSQL cluster version' unless -d "/usr/lib/postgresql/$version";
my $cmd = get_program_path (((split '/', $0)[-1]), $version);
error 'pg_wrapper: invalid command name' unless $cmd;
unshift @ARGV, $cmd;
exec @ARGV;
__END__
=head1 NAME
pg_wrapper - wrapper for PostgreSQL client commands
I<client-program> [B<--cluster> I<version>/I<cluster>] [...]
(I<client-program>: B<psql>, B<createdb>, B<dropuser>, and all other client
programs installed in C</usr/lib/postgreqsl/>I<version>C</bin>).
=head1 DESCRIPTION
This program is run only as a link to names which correspond to PostgreSQL
programs in C</usr/lib/postgresql/>I<version>C</bin>. It determines the
configured cluster and database for the user and calls the appropriate version
of the desired program to connect to that cluster and database, supplying any
specifed options to that command.
By default, the cluster is determined from the configuration files
L<user_clusters(5)> and L<postgresqlrc(5)>. However, this can be overriden by
specifying the C<$PGCLUSTER> environment variable or the B<--cluster>
I<version>/I<cluster> option.
=head1 ENVIRONMENT
=over
=item B<PGCLUSTER>
If C<$PGCLUSTER> is set, its value (of the form I<version>/I<cluster>)
specifies the desired cluster, similar to the B<--cluster> option. However, if
B<--cluster> is specified, it overrides the value of C<$PGCLUSTER>.
stores the default cluster and database for users and groups as set by
the administrators.
stores defaults set by the user himself.
=back
=head1 SEE ALSO
=head1 AUTHOR
Martin Pitt L<E<lt>mpitt@debian.orgE<gt>>