Re: Discovering postgres binary directory location

From: Mark Johnson <remi9898(at)gmail(dot)com>
To: Paul Förster <paul(dot)foerster(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Raul Kaubi <raulkaubi(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Discovering postgres binary directory location
Date: 2020-11-12 15:19:38
Message-ID: CADZ4tWMUxhGv_gQE2tJ=w--=GRgK1xv7pFY7Rx7bivqPC=LS3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On any given server there could be zero, one, or many PGHOME/bin
locations. The OP wants to identify all of them. The default location
used by package-based installers is different from the default location of
software built from source, and when building from source you can specify a
non-default location. My server has PG 9.6, 12.1, and 13 from RPM and also
12.1 from source.

The solution might be as easy as finding all installations of a core
PostgreSQL executable like pg_ctl. I would not search for psql since you
will find one or more links in system folders and so your monitoring tool
would need some logic to filter out the links. The word postgres is both
an executable and a user directory name. Hence I am using pg_ctl in my
example. This example was written on CentOS 7.7.

# find / -name pg_ctl
/usr/pgsql-13/bin/pg_ctl
/usr/local/pgsql/bin/pg_ctl
/usr/pgsql-12/bin/pg_ctl
/usr/pgsql-9.6/bin/pg_ctl
/root/Downloads/postgresql-12.1/src/bin/pg_ctl
/root/Downloads/postgresql-12.1/src/bin/pg_ctl/pg_ctl
You have mail in /var/spool/mail/root

Notice above my server has three RPM installs and one source code install.
Also notice the results contain two false positives (in the Downloads
directory) and also a message about mail. You'll have to figure out how to
separate the good and bad results.

To strip off the file name and only return the directory, you can used the
-printf option as shown below or if not supported on your system use a host
command like sed or awk. This does not remove false positives or system
messages.

find / -name 'pg_ctl' -printf "%h\n"
/usr/pgsql-13/bin
/usr/local/pgsql/bin
/usr/pgsql-12/bin
/usr/pgsql-9.6/bin
/root/Downloads/postgresql-12.1/src/bin
/root/Downloads/postgresql-12.1/src/bin/pg_ctl
You have mail in /var/spool/mail/root

Careful when stripping out the false positives. PostgreSQL installed from
source can be pretty much anywhere including a Downloads directory, /tmp,
and so on. In my case, the Downloads directory has a src sub-directory,
which tells me it is just a staging area for source code.

-Mark

On Thu, Nov 12, 2020 at 1:22 AM Paul Förster <paul(dot)foerster(at)gmail(dot)com>
wrote:

> Hi Raul, hi Adrian,
>
> > On 11. Nov, 2020, at 23:26, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
> wrote:
> >
> > On 11/11/20 2:22 PM, Raul Kaubi wrote:
> >> Hi
> >> CentOS 7
> >> Postgres 9 to 12
> >> I am looking ways to universally discover postgresql binary directory
> for monitoring purpose.
> >> For example postgres 12, it is: */usr/pgsql-12*
> >
> > pg_config --bindir
> > /usr/local/pgsql12/bin
>
> or by query:
>
> postgres=# select setting from pg_config where name = 'BINDIR';
> setting
> -------------------------
> /data/postgres/12.4/bin
> (1 row)
>
> Cheers,
> Paul
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Paul Förster 2020-11-12 15:37:12 Re: Discovering postgres binary directory location
Previous Message Bruce Momjian 2020-11-12 15:06:24 Re: Christopher Browne