Programmatic method to determine currently installed Windows PostrgreSQL version

Started by Will Wrightover 20 years ago7 messagesgeneral
Jump to latest
#1Will Wright
will4wright@yahoo.com

Hi,

I'm in the process of creating an Windows installation
package for a product that uses PostgreSQL.

During the installation I would like to check if
PostgreSQL is installed and if it is, which version.

I think that I can infer that PostgreSQL is installed
by searching for the
\HKLM\SOFTWARE\PostgreSQL\Services or
HLKM\SOFTWARE\PostrgreSQL\Installations registry keys.
However I am not so sure about the version number
identification.

I note that with v8.0.x the following ValueName
exists:
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{5AA3FA26-72A2-4D06-9BFE-98E650A37B6D}
"Version"="8.0"

And with 8.1 beta the following:
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{317D0ED1-8845-40DD-A028-0A3EB8E24F2E}
"Version"="8.1-beta4"

So it looks like the version number is underneath a
key that changes with every new version (new Product
number). And I am therefore not sure if I can use
this knowledge to identify the installed version.

Does anyone have a better idea for a more reliable
identification method?

Thanks,
Will

__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

#2Magnus Hagander
magnus@hagander.net
In reply to: Will Wright (#1)
Re: Programmatic method to determine currently installed Windows PostrgreSQL version

Hi,

I'm in the process of creating an Windows installation
package for a product that uses PostgreSQL.

During the installation I would like to check if PostgreSQL
is installed and if it is, which version.

I think that I can infer that PostgreSQL is installed by
searching for the \HKLM\SOFTWARE\PostgreSQL\Services or
HLKM\SOFTWARE\PostrgreSQL\Installations registry keys.
However I am not so sure about the version number identification.

I note that with v8.0.x the following ValueName
exists:
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{5AA3FA26
-72A2-4D06-9BFE-98E650A37B6D}
"Version"="8.0"

And with 8.1 beta the following:
HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{317D0ED1
-8845-40DD-A028-0A3EB8E24F2E}
"Version"="8.1-beta4"

So it looks like the version number is underneath a key that
changes with every new version (new Product number). And I
am therefore not sure if I can use this knowledge to identify
the installed version.

It changes once for each major version, meaning there is one for 8.0 and
8.1. The whole 8.0.x series share the same id, as will the whole 8.1
series (at least that's the plan). It basically changes when initdb is
required to upgrade, which is why it also changes between betas.

You can safely rely on these once you've seen the ones for a release.
For example, don't use the beta4 one, wait for the 8.1 release one.

Does anyone have a better idea for a more reliable
identification method?

Using these registry keys will reliably identify any PostgreSQL
installations done using the MSI installer - it won't pick up any other
install methods. For those, you could either search the filesystem, or
attempt a connect to the default port etc - but I think those would
either be too slow or a lot less reliable.

//Magnus

#3Will Wright
will4wright@yahoo.com
In reply to: Magnus Hagander (#2)
Re: Programmatic method to determine currently installed Windows PostrgreSQL version
--- Magnus Hagander <mha@sollentuna.net> wrote:

Hi,

I'm in the process of creating an Windows

installation

package for a product that uses PostgreSQL.

During the installation I would like to check if

PostgreSQL

is installed and if it is, which version.

I think that I can infer that PostgreSQL is

installed by

searching for the

\HKLM\SOFTWARE\PostgreSQL\Services or

HLKM\SOFTWARE\PostrgreSQL\Installations registry

keys.

However I am not so sure about the version number

identification.

I note that with v8.0.x the following ValueName
exists:

HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{5AA3FA26

-72A2-4D06-9BFE-98E650A37B6D}
"Version"="8.0"

And with 8.1 beta the following:

HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{317D0ED1

-8845-40DD-A028-0A3EB8E24F2E}
"Version"="8.1-beta4"

So it looks like the version number is underneath

a key that

changes with every new version (new Product

number). And I

am therefore not sure if I can use this knowledge

to identify

the installed version.

It changes once for each major version, meaning
there is one for 8.0 and
8.1. The whole 8.0.x series share the same id, as
will the whole 8.1
series (at least that's the plan). It basically
changes when initdb is
required to upgrade, which is why it also changes
between betas.

You can safely rely on these once you've seen the
ones for a release.
For example, don't use the beta4 one, wait for the
8.1 release one.

Does anyone have a better idea for a more reliable

identification method?

Using these registry keys will reliably identify any
PostgreSQL
installations done using the MSI installer - it
won't pick up any other
install methods. For those, you could either search
the filesystem, or
attempt a connect to the default port etc - but I
think those would
either be too slow or a lot less reliable.

Hi Magnus, thanks for the quick response.
Unfortunately I still have an issue with this regsitry
identification method because I'd like to code my
installer so that it can also identify the postreSQL
versions that were not available at the time I
authored my install check, i.e. future versions.

In essence I know that my product works with
PostrgeSQL 8.0 and 8.1 and it my guees is that it will
continue to work with future PostgreSQL versions. So
I'd like my installer to be able to check that 8.0 or
above is installed.

Is this possible, given the method the PostrgeSQL
installer uses to record it's version number in the
registry?

Thanks,
Will

__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

#4Richard Huxton
dev@archonet.com
In reply to: Will Wright (#3)
Re: Programmatic method to determine currently installed

Will Wright wrote:

Hi Magnus, thanks for the quick response.
Unfortunately I still have an issue with this regsitry
identification method because I'd like to code my
installer so that it can also identify the postreSQL
versions that were not available at the time I
authored my install check, i.e. future versions.

You could issue a "SELECT version()" - that is about as definitive as
you can get.

Don't forget you'll need to cope with the case where a user has 2 or
more versions of PostgreSQL running on the same machine. I'm not sure
it's safe to assume only one installation.

--
Richard Huxton
Archonet Ltd

#5Will Wright
will4wright@yahoo.com
In reply to: Richard Huxton (#4)
Re: Programmatic method to determine currently installed Windows PostrgreSQL version

Thanks Richard, I will look into whether or not I will
have access to the SELECT statement.

Regards,
Will

--- Richard Huxton <dev@archonet.com> wrote:

Will Wright wrote:

Hi Magnus, thanks for the quick response.
Unfortunately I still have an issue with this

regsitry

identification method because I'd like to code my
installer so that it can also identify the

postreSQL

versions that were not available at the time I
authored my install check, i.e. future versions.

You could issue a "SELECT version()" - that is about
as definitive as
you can get.

Don't forget you'll need to cope with the case where
a user has 2 or
more versions of PostgreSQL running on the same
machine. I'm not sure
it's safe to assume only one installation.

--
Richard Huxton
Archonet Ltd

__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs

#6Magnus Hagander
magnus@hagander.net
In reply to: Will Wright (#5)
Re: Programmatic method to determine currently installed Windows PostrgreSQL version

HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{317D0ED1

-8845-40DD-A028-0A3EB8E24F2E}
"Version"="8.1-beta4"

So it looks like the version number is underneath

a key that

changes with every new version (new Product

number). And I

am therefore not sure if I can use this knowledge

to identify

the installed version.

It changes once for each major version, meaning there is

one for 8.0

and 8.1. The whole 8.0.x series share the same id, as will

the whole

8.1 series (at least that's the plan). It basically changes when
initdb is required to upgrade, which is why it also changes between
betas.

You can safely rely on these once you've seen the ones for

a release.

For example, don't use the beta4 one, wait for the
8.1 release one.

Does anyone have a better idea for a more reliable

identification method?

Using these registry keys will reliably identify any PostgreSQL
installations done using the MSI installer - it won't pick up any
other install methods. For those, you could either search the
filesystem, or attempt a connect to the default port etc -

but I think

those would either be too slow or a lot less reliable.

Hi Magnus, thanks for the quick response.
Unfortunately I still have an issue with this regsitry
identification method because I'd like to code my installer
so that it can also identify the postreSQL versions that were
not available at the time I authored my install check, i.e.
future versions.

In essence I know that my product works with PostrgeSQL 8.0
and 8.1 and it my guees is that it will continue to work with
future PostgreSQL versions. So I'd like my installer to be
able to check that 8.0 or above is installed.

To do this, enumerate the keys under PostgreSQL\Installations. You can
count on future versions to register there with a different GUID - so if
you enumerate everything that's there, you can look at the Version value
to see the actual version.

//Magnus

#7Will Wright
will4wright@yahoo.com
In reply to: Magnus Hagander (#6)
Re: Programmatic method to determine currently installed Windows PostrgreSQL version

Thanks Magnus. Much appreciated.

Will

--- Magnus Hagander <mha@sollentuna.net> wrote:

HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\{317D0ED1

-8845-40DD-A028-0A3EB8E24F2E}
"Version"="8.1-beta4"

So it looks like the version number is

underneath

a key that

changes with every new version (new Product

number). And I

am therefore not sure if I can use this

knowledge

to identify

the installed version.

It changes once for each major version, meaning

there is

one for 8.0

and 8.1. The whole 8.0.x series share the same

id, as will

the whole

8.1 series (at least that's the plan). It

basically changes when

initdb is required to upgrade, which is why it

also changes between

betas.

You can safely rely on these once you've seen

the ones for

a release.

For example, don't use the beta4 one, wait for

the

8.1 release one.

Does anyone have a better idea for a more

reliable

identification method?

Using these registry keys will reliably identify

any PostgreSQL

installations done using the MSI installer - it

won't pick up any

other install methods. For those, you could

either search the

filesystem, or attempt a connect to the default

port etc -

but I think

those would either be too slow or a lot less

reliable.

Hi Magnus, thanks for the quick response.
Unfortunately I still have an issue with this

regsitry

identification method because I'd like to code my

installer

so that it can also identify the postreSQL

versions that were

not available at the time I authored my install

check, i.e.

future versions.

In essence I know that my product works with

PostrgeSQL 8.0

and 8.1 and it my guees is that it will continue

to work with

future PostgreSQL versions. So I'd like my

installer to be

able to check that 8.0 or above is installed.

To do this, enumerate the keys under
PostgreSQL\Installations. You can
count on future versions to register there with a
different GUID - so if
you enumerate everything that's there, you can look
at the Version value
to see the actual version.

//Magnus

__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com