return to first page linux journal archive
keywordscontents

Source Code for owner.pl

#!/usr/local/bin/perl -w

use Pg;

$conn = Pg::connectdb("dbname = template1");
if ($conn->status == PGRES_CONNECTION_BAD) {
    $msg = $conn->errorMessage;
    print
"unable to establish connection to the backend\n";
    print "$msg\n";
    exit(1);
}
@query =(
"SELECT usename, datname FROM pg_user, pg_database",
	"WHERE usesysid = int2in(int4out(datdba))",
	"ORDER BY usename, datname;");
$result = $conn->exec("@query");

if ($result->resultStatus != PGRES_TUPLES_OK) {
    $msg = $result->cmdStatus;
    print "Error processing the query!\n";
    print "$msg\n";
    exit(1);
}

$tuples = $result->ntuples;
for ($i = 0; $i < $tuples; $i++) {
    $uname = $result->getvalue($i, 0);
    $db = $result->getvalue($i,1);
    write;
}

format STDOUT_TOP =
Owner of PostgreSQL Databases:

Username	Database
.
format STDOUT =
$uname, $db
.