Re: Is postgres installed?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: christophe(dot)andre(at)elsys-design(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is postgres installed?
Date: 2010-05-22 09:38:53
Message-ID: 4BF7A62D.5030008@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 21/05/2010 9:43 PM, christophe(dot)andre(at)elsys-design(dot)com wrote:
> Hi,
>
> How I know whether Postgres is already installed or not on a machine(on
> Linux and Windows)?
> I found that pg_ctl --version could be used

Only if PostgreSQL's binary directory is on the PATH, which it may not
be especially on Windows.

There's no reliable way to detect a PostgreSQL install on UNIX/Linux/BSD
either. You can look for pg_ctl on the path and tell the user that the
pg_ctl for the postgresql install they want to use simply must be on the
path. However, some Linux flavours support parallel installation of
multiple versions of PostgreSQL (and multiple clusters for a given
version), and will *not* have pg_ctl on the path for versions of
PostgreSQL installed on the system.

On Ubuntu/Debian you'll only find `pg_ctlcluster', which is a pg_ctl
wrapper that takes additional 'version' and 'cluster' arguments. On
these systems you can use pg_lsclusters to find PostgreSQL clusters.

Alternately, you could simply require the user to set up the PATH
manually, eg

PATH=/usr/lib/postgresql/8.4/bin:$PATH ./yourprogram

which will work anywhere and everywhere there's a Pg install.

> or I also tried to check into
> the registry (for windows HKLM\SOFTWARE\PostgreSQL\Installations), however
> with Windows Server 2003 pg_ctl is not recognized (probably not in the
> path) and the registries are not written (nothing appears under
> HKLM\SOFTWARE\)

How was Pg installed? Using which installer package?

Here (Vista, XP and Windows 7) Pg appears under
HKLM\Software\Postgresql\Installations\postgresql-8.4
as installed by the EnterpriseDB "one-click" installer.

If you "installed" Pg from the zip file, there's no real way to figure
out if it's installed except checking the PATH for pg_ctl.exe or
checking the running process list for postgres.exe . Both are fallible -
the former if pg_ctl isn't on the path, the latter if PostgreSQL is
installed but not currently running.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2010-05-22 10:36:03 Re: copy data from one db into another via copy & psql
Previous Message Andreas Schmitz 2010-05-21 20:43:49 Re: cleaning wal files from postgres