X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 709A79F9D99 for ; Mon, 22 May 2006 14:57:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 80303-02 for ; Mon, 22 May 2006 14:57:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtp6.libero.it (smtp6.libero.it [193.70.192.59]) by postgresql.org (Postfix) with ESMTP id 5B0899F9B01 for ; Mon, 22 May 2006 14:57:35 -0300 (ADT) Received: from localhost (172.16.1.84) by smtp6.libero.it (7.0.027-DD01) id 4464C5B700EE38AA for pgsql-sql@postgresql.org; Mon, 22 May 2006 19:57:34 +0200 Received: from smtp3.libero.it ([172.16.1.53]) by localhost (asav5.libero.it [193.70.192.154]) (amavisd-new, port 10024) with ESMTP id 21255-10-7 for ; Mon, 22 May 2006 19:57:33 +0200 (CEST) Received: from [151.41.65.225] (adsl-ull-225-65.41-151.net24.it [151.41.65.225]) by smtp3.libero.it (Postfix) with ESMTP id 7A2CFABE32 for ; Mon, 22 May 2006 19:57:33 +0200 (MEST) Message-ID: <4471FC00.8010100@libero.it> Date: Mon, 22 May 2006 15:59:28 -0200 From: Manlio Perillo User-Agent: Mozilla Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Does PG have a database References: <4471E6B9.9080002@noaa.gov> In-Reply-To: <4471E6B9.9080002@noaa.gov> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned: with antispam and antivirus automated system at libero.it X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/169 X-Sequence-Number: 25200 Mark Fenbers ha scritto: > I have working PostgreSQL databases on 3 of my ~30 Linux boxes. I want > my software to be able to determine which of my 30 boxes have functional > databases on them. Since Pg is part of the baseline distro, merely > checking for the existence of an executable doesn't solve my problem. > > I tried looping through my list of hosts and running the command: > psql -h $host --list > but this fails on a box with a database with the same error code as on a > box that doesn't have a database, if my PGUSER isn't set and my login ID > is not the username of the database. The PGUSER setting might differ > for each host, so specifying this in the software is not practical. > > Bottom line: What trick can I use to determine whether a box has a > living, breathing Pg database if I don't know the DB owner? > Mark > Just write a custom client that connects to the given host, on some standard ports. If the connection is accepted, there is a possibility that on the other side there is a PostgreSQL server. To make sure send a StartupMessage http://www.postgresql.org/docs/8.1/static/protocol-message-formats.html You can reuse some code of a library I have written: pglib. http://developer.berlios.de/projects/pglib/ It is released under the MIT license, and it is written in Python and Twisted (a framework for writing asynchronous applications). By the way: pglib aims to be a complete replacement for libpq. Regards Manlio Perillo