Thread: PG minor version in data directory?

PG minor version in data directory?

From
Justin Clift
Date:
Hiyas,

Anyone know if there's a good way to tell what *minor* version
of PostgreSQL a data directory has been run with?

   eg 15.3 vs 15.4

Am working on some "automatic upgrade" stuff, and I'm only aware
of the major version being tracked in PGDATA/PG_VERSION.

If the minor version is already tracked somewhere as well, that
would be extremely useful for my use case.

Otherwise, I'll have to start manually adding info to track it.

Regards and best wishes,

Justin Clift



Re: PG minor version in data directory?

From
"David G. Johnston"
Date:
On Fri, Aug 18, 2023 at 6:36 PM Justin Clift <justin@postgresql.org> wrote:
If the minor version is already tracked somewhere as well, that
would be extremely useful for my use case.


The data directory doesn't have a concept of "minor version".  Only the installed libraries and binaries do.

David J.

Re: PG minor version in data directory?

From
Justin Clift
Date:
On 2023-08-19 14:10, David G. Johnston wrote:
> On Fri, Aug 18, 2023 at 6:36 PM Justin Clift <justin@postgresql.org> 
> wrote:
> 
>> If the minor version is already tracked somewhere as well, that
>> would be extremely useful for my use case.
>> 
>> 
> The data directory doesn't have a concept of "minor version".  Only the
> installed libraries and binaries do.

Thanks, that's what I figured.  I'll have to keep state in a 
PG_VERSION_MINOR
there or something. :)

Regards and best wishes,

Justin Clift



Re: PG minor version in data directory?

From
"Peter J. Holzer"
Date:
On 2023-08-19 14:22:25 +1000, Justin Clift wrote:
> On 2023-08-19 14:10, David G. Johnston wrote:
> > On Fri, Aug 18, 2023 at 6:36 PM Justin Clift <justin@postgresql.org>
> > wrote:
> >
> > > If the minor version is already tracked somewhere as well, that
> > > would be extremely useful for my use case.
> > >
> > >
> > The data directory doesn't have a concept of "minor version".  Only the
> > installed libraries and binaries do.
>
> Thanks, that's what I figured.  I'll have to keep state in a
> PG_VERSION_MINOR
> there or something. :)

Wouldn't it be better to ask whatever system you use to install the
software for the version?

E.g. on Debian derived Linuux distributions:

% dpkg -l postgresql-14
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version               Architecture Description
+++-==============-=====================-============-=========================================================
ii  postgresql-14  14.9-0ubuntu0.22.04.1 amd64        The World's Most Advanced Open Source Relational Database

or

% apt policy postgresql-14
postgresql-14:
  Installed: 14.9-0ubuntu0.22.04.1
  Candidate: 14.9-0ubuntu0.22.04.1
  Version table:
 *** 14.9-0ubuntu0.22.04.1 500
        500 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     14.2-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages

If you compile the software yourself, you could always ask postgres:

% /usr/lib/postgresql/14/bin/postgres --version
postgres (PostgreSQL) 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1)

        hp

--
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachment

Re: PG minor version in data directory?

From
Justin Clift
Date:
On 2023-08-19 19:14, Peter J. Holzer wrote:
> On 2023-08-19 14:22:25 +1000, Justin Clift wrote:
<snip>
>> Thanks, that's what I figured.  I'll have to keep state in a
>> PG_VERSION_MINOR
>> there or something. :)
> 
> Wouldn't it be better to ask whatever system you use to install the
> software for the version?

In the general sense, yes. :)

For the very specific use case I'm working with (!), things are a bit
different.  It's for this, if that helps with context:

   * https://github.com/pgautoupgrade/docker-pgautoupgrade
   * https://hub.docker.com/r/pgautoupgrade/pgautoupgrade  <-- docker 
repo

It's a docker container that people use for running PostgreSQL, but
also has the ability to (automatically) upgrade the data files from
older versions.  That's the piece I'm working on.

Such a thing is useful for people that need a PG docker container,
and whose needs are fairly simple.  They can use point at this one,
and they'll have a self-upgrading PG version that's fairly "fire and
forget".

Thus far (1 month in), it seems to work ok (for us) and some other
people.

Am obviously looking to improve its capabilities over time too. :)

+ Justin