#!/usr/bin/perl

use DBI;

$dbh = DBI->connect("dbi:Pg:dbname=template1","postgres","",
		    {PrintError => 0});

if ($DBI::err != 0) {
  print $DBI::errstr . "\n";
  exit($DBI::err);
}

$query = "SELECT * FROM pg_tables";

$sth = $dbh->prepare($query);
$rv = $sth->execute();
if (!defined $rv) {
  print "При выполнении запроса '$query' возникла ошибка: " . $dbh->errstr . "\n";
  exit(0);
}

while (@array = $sth->fetchrow_array()) {
  foreach $i (@array) {
    print "$i\t";
  }
  print "\n";
}

$sth->finish();
$dbh->disconnect();
