pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedGet PG primary version without substring manipulation?
6+ messages / 6 participants
[nested] [flat]
* Get PG primary version without substring manipulation?
@ 2024-06-13 12:52 Ron Johnson <ronljohnsonjr@gmail.com>
2024-06-13 13:17 ` Re: Get PG primary version without substring manipulation? Peter Adlersburg <peter.adlersburg@gmail.com>
2024-06-13 13:17 ` Re: Get PG primary version without substring manipulation? Keith Fiske <keith.fiske@crunchydata.com>
2024-06-13 16:50 ` Re: Get PG primary version without substring manipulation? J T <jorge.torralba@gmail.com>
0 siblings, 3 replies; 6+ messages in thread
From: Ron Johnson @ 2024-06-13 12:52 UTC (permalink / raw)
To: Pgsql-admin <pgsql-admin@lists.postgresql.org>
cut, awk, head, bash, etc are easy enough, but am I overlooking some
intrinsic method of getting just PG's primary version number (9.6 or 14, in
my case) without doing substring manipulation?
$ ssh foo.example.com pg_config --version
PostgreSQL 9.6.24
$ ssh foo.example.com psql --version
psql (PostgreSQL) 9.6.24
$ psql -h foo.example.com -Xtc "SELECT version();"
PostgreSQL 9.6.24 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
20150623 (Red Hat 4.8.5-44), 64-bit
$ ssh bar.example.com pg_config --version
PostgreSQL 14.12
$ ssh bar.example.com psql --version
psql (PostgreSQL) 14.12
$ psql -h bar.example.com -Xtc "SELECT version();"
PostgreSQL 14.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0
20210514 (Red Hat 8.5.0-20), 64-bit
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Get PG primary version without substring manipulation?
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2024-06-13 13:17 ` Peter Adlersburg <peter.adlersburg@gmail.com>
2 siblings, 0 replies; 6+ messages in thread
From: Peter Adlersburg @ 2024-06-13 13:17 UTC (permalink / raw)
To: ronljohnsonjr@gmail.com; +Cc: pgsql-admin@lists.postgresql.org
cat <your data dir>/PG_VERSION
kr
Ron Johnson <ronljohnsonjr@gmail.com> schrieb am Do., 13. Juni 2024, 14:52:
> cut, awk, head, bash, etc are easy enough, but am I overlooking some
> intrinsic method of getting just PG's primary version number (9.6 or 14, in
> my case) without doing substring manipulation?
>
> $ ssh foo.example.com pg_config --version
> PostgreSQL 9.6.24
> $ ssh foo.example.com psql --version
> psql (PostgreSQL) 9.6.24
> $ psql -h foo.example.com -Xtc "SELECT version();"
> PostgreSQL 9.6.24 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
> 20150623 (Red Hat 4.8.5-44), 64-bit
>
> $ ssh bar.example.com pg_config --version
> PostgreSQL 14.12
> $ ssh bar.example.com psql --version
> psql (PostgreSQL) 14.12
> $ psql -h bar.example.com -Xtc "SELECT version();"
> PostgreSQL 14.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0
> 20210514 (Red Hat 8.5.0-20), 64-bit
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Get PG primary version without substring manipulation?
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2024-06-13 13:17 ` Keith Fiske <keith.fiske@crunchydata.com>
2024-06-14 00:30 ` Re: Get PG primary version without substring manipulation? Ian Lawrence Barwick <barwick@gmail.com>
2 siblings, 1 reply; 6+ messages in thread
From: Keith Fiske @ 2024-06-13 13:17 UTC (permalink / raw)
To: Ron Johnson <ronljohnsonjr@gmail.com>; +Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
On Thu, Jun 13, 2024 at 8:52 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
> cut, awk, head, bash, etc are easy enough, but am I overlooking some
> intrinsic method of getting just PG's primary version number (9.6 or 14, in
> my case) without doing substring manipulation?
>
> $ ssh foo.example.com pg_config --version
> PostgreSQL 9.6.24
> $ ssh foo.example.com psql --version
> psql (PostgreSQL) 9.6.24
> $ psql -h foo.example.com -Xtc "SELECT version();"
> PostgreSQL 9.6.24 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
> 20150623 (Red Hat 4.8.5-44), 64-bit
>
> $ ssh bar.example.com pg_config --version
> PostgreSQL 14.12
> $ ssh bar.example.com psql --version
> psql (PostgreSQL) 14.12
> $ psql -h bar.example.com -Xtc "SELECT version();"
> PostgreSQL 14.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0
> 20210514 (Red Hat 8.5.0-20), 64-bit
>
>
If you're logging into the database, I prefer getting the number value like
this when using it for comparisons. Still need to do some manipulation if
you just want the major version, but it's a lot easier to work with than
the strings you were getting with other methods.
keith=# select current_setting('server_version_num')::int;
current_setting
-----------------
160002
--
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Get PG primary version without substring manipulation?
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
2024-06-13 13:17 ` Re: Get PG primary version without substring manipulation? Keith Fiske <keith.fiske@crunchydata.com>
@ 2024-06-14 00:30 ` Ian Lawrence Barwick <barwick@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Ian Lawrence Barwick @ 2024-06-14 00:30 UTC (permalink / raw)
To: Keith Fiske <keith.fiske@crunchydata.com>; +Cc: Ron Johnson <ronljohnsonjr@gmail.com>; Pgsql-admin <pgsql-admin@lists.postgresql.org>
2024年6月13日(木) 22:18 Keith Fiske <keith.fiske@crunchydata.com>:
>
>
>
> On Thu, Jun 13, 2024 at 8:52 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
>>
>> cut, awk, head, bash, etc are easy enough, but am I overlooking some intrinsic method of getting just PG's primary version number (9.6 or 14, in my case) without doing substring manipulation?
>>
>> $ ssh foo.example.com pg_config --version
>> PostgreSQL 9.6.24
>> $ ssh foo.example.com psql --version
>> psql (PostgreSQL) 9.6.24
>> $ psql -h foo.example.com -Xtc "SELECT version();"
>> PostgreSQL 9.6.24 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
>>
>> $ ssh bar.example.com pg_config --version
>> PostgreSQL 14.12
>> $ ssh bar.example.com psql --version
>> psql (PostgreSQL) 14.12
>> $ psql -h bar.example.com -Xtc "SELECT version();"
>> PostgreSQL 14.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
Be aware that the --version output of binary files tells you the version number
of the first matching binary in the shell path, but there's no guarantee that
this will be the same as the version of the running server.
> If you're logging into the database, I prefer getting the number value like this when using it for comparisons. Still need to do some manipulation if you just want the major version, but it's a lot easier to work with than the strings you were getting with other methods.
>
> keith=# select current_setting('server_version_num')::int;
> current_setting
> -----------------
> 160002
How about:
SELECT array_to_string(numbers[1 : array_upper(numbers,1) -1], '.')
FROM
(SELECT string_to_array(current_setting('server_version'), '.') numbers) n;
Regards
Ian Barwick
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Get PG primary version without substring manipulation?
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
@ 2024-06-13 16:50 ` J T <jorge.torralba@gmail.com>
2024-06-14 07:25 ` Re: Get PG primary version without substring manipulation? Laurenz Albe <laurenz.albe@cybertec.at>
2 siblings, 1 reply; 6+ messages in thread
From: J T @ 2024-06-13 16:50 UTC (permalink / raw)
To: Ron Johnson <ronljohnsonjr@gmail.com>; +Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Don't forget ...
cat /datadirectory/PG_VERSION
JT
On Thu, Jun 13, 2024 at 5:52 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
> cut, awk, head, bash, etc are easy enough, but am I overlooking some
> intrinsic method of getting just PG's primary version number (9.6 or 14, in
> my case) without doing substring manipulation?
>
> $ ssh foo.example.com pg_config --version
> PostgreSQL 9.6.24
> $ ssh foo.example.com psql --version
> psql (PostgreSQL) 9.6.24
> $ psql -h foo.example.com -Xtc "SELECT version();"
> PostgreSQL 9.6.24 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5
> 20150623 (Red Hat 4.8.5-44), 64-bit
>
> $ ssh bar.example.com pg_config --version
> PostgreSQL 14.12
> $ ssh bar.example.com psql --version
> psql (PostgreSQL) 14.12
> $ psql -h bar.example.com -Xtc "SELECT version();"
> PostgreSQL 14.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0
> 20210514 (Red Hat 8.5.0-20), 64-bit
>
>
--
Thanks,
Jorge Torralba
----------------------------
Note: This communication may contain privileged or other confidential
information. If you are not the intended recipient, please do not print,
copy, retransmit, disseminate or otherwise use the information. Please
indicate to the sender that you have received this email in error and
delete the copy you received. Thank You.
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: Get PG primary version without substring manipulation?
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
2024-06-13 16:50 ` Re: Get PG primary version without substring manipulation? J T <jorge.torralba@gmail.com>
@ 2024-06-14 07:25 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 6+ messages in thread
From: Laurenz Albe @ 2024-06-14 07:25 UTC (permalink / raw)
To: J T <jorge.torralba@gmail.com>; Ron Johnson <ronljohnsonjr@gmail.com>; +Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
On Thu, Jun 13, 2024 at 5:52 AM Ron Johnson <ronljohnsonjr@gmail.com> wrote:
> cut, awk, head, bash, etc are easy enough, but am I overlooking some intrinsic
> method of getting just PG's primary version number (9.6 or 14, in my case) without
> doing substring manipulation?
I like
psql -Atq -c "SELECT current_setting('server_version_num')::integer / 10000"
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2024-06-14 07:25 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 12:52 Get PG primary version without substring manipulation? Ron Johnson <ronljohnsonjr@gmail.com>
2024-06-13 13:17 ` Peter Adlersburg <peter.adlersburg@gmail.com>
2024-06-13 13:17 ` Keith Fiske <keith.fiske@crunchydata.com>
2024-06-14 00:30 ` Ian Lawrence Barwick <barwick@gmail.com>
2024-06-13 16:50 ` J T <jorge.torralba@gmail.com>
2024-06-14 07:25 ` Laurenz Albe <laurenz.albe@cybertec.at>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox