Re: Fastest way to check database's existence

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Kynn Jones <kynnjo(at)gmail(dot)com>
Subject: Re: Fastest way to check database's existence
Date: 2010-10-16 17:04:39
Message-ID: 201010161004.39938.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Saturday 16 October 2010 8:13:12 am Kynn Jones wrote:
> I want to code a Perl function (part of a Perl library) for determining the
> existence of a particular database (in a given host/port).
>
> One way would be to just attempt making a connection to it, trapping any
> errors upon failure (with eval), or discarding the connection upon success.
>
> This approach has the added benefit of also checking the accessibility of
> the database to the user running the code, but for this application this
> added benefit is not necessary. Checking existence is all that matters.
>
> Is there an even faster way to check for a database's existence that does
> not require establishing a connection?

Given the restriction of host/port you probably need to connect as stated in
other posts. For completeness though, it is possible to parse
$DATA/global/pg_database for the existence of database in a particular cluster.
Assuming you can map host/port to cluster then it is a possibility.

>
> (Maybe this question would be more suitable for the pgsql-performance
> list?)
>
> TIA!
>
> ~kynn

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guy Rouillier 2010-10-16 17:15:18 Re: Constraint: string length must be 32 chars
Previous Message Raymond O'Donnell 2010-10-16 17:00:26 Re: Constraint: string length must be 32 chars