Skip to content
Snippets Groups Projects
pg_wrapper 1.61 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/perl -w
    
    # 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;
    
    
    @commands = qw/clusterdb createdb createlang createuser dropdb droplang dropuser pg_dump
        pg_dumpall pg_restore psql vacuumdb vacuumlo/;
    
    $cmd = (split '/', $0)[-1];
    grep { $cmd eq $_ } @commands or die "pg_wrapper: invalid command name $cmd";
    
    # Determine $version, $cluster, $db, $port
    
    ($version, $cluster, $db) = user_cluster_map();
    
    if ($cluster) {
    
        $port = (get_conf_value $version, $cluster, 'port');
    }
    
    $ENV{'PGPORT'} = "$port" if $port;
    $ENV{'PGDATABASE'} = $db if $db;
    
    
    @args = (get_program_path ($cmd, $version));
    
    push @args, @ARGV;
    exec @args;
    
    
    Martin Pitt's avatar
    Martin Pitt committed
    __END__
    
    =head1 NAME
    
    pg_wrapper - wrapper for PostgreSQL client commands
    
    =head1 DESCRIPTION
    
    This program is run only as a link to names which correspond to PostgreSQL
    programs in B</usr/lib/postgresql/>I<version>B</bin>. It finds the correct
    cluster and database for the user and calls the correct version of the desired
    program to connect to that cluster and database, supplying any specifed options
    to that command.
    
    =head1 FILES
    
    =over
    
    =item B</etc/postgresql-common/user_clusters>
    
    stores the default cluster and database for users and groups as set by
    the administrators. 
    
    =item B<$HOME/.postgresqlrc>
    
    stores defaults set by the user himself.
    
    =back
    
    =head1 SEE ALSO
    
    
    L<pg_default(1)>, L<pg_exec(1)>, L<user_clusters(5)>, L<postgresqlrc(5)>
    
    Martin Pitt's avatar
    Martin Pitt committed
    
    =head1 AUTHOR
    
    Martin Pitt L<E<lt>mpitt@debian.orgE<gt>>