1

I can quickly query the database name with SELECT current_database(); but I've been searching for way to also query the cluster name and version with no luck - hoping someone can suggest a solution.

  • cannot retract a question after I've found an answer: select name || '=' || setting from pg_settings where name in ('port','cluster_name'); – Reinsbrain Jul 9 '19 at 10:10
  • 2
    You could always self-answer (if your solution is materially different to the answers already posted) and accept your own answer if you feel it best suits your question. 😉 – Peter Vandivier Jul 9 '19 at 10:14
2

That would be

SELECT current_setting('cluster_name'), current_setting('server_version');

You can get all parameters that way. For automated processing, server_version_num is often better.

| improve this answer | |
  • I mistakenly presumed you can only find settings that are defined in postgresql.conf and now know otherwise - I'm a little more powerful postgresql dev now thanks to @Laurenz Albe – Reinsbrain Jul 9 '19 at 10:26
2

You can also query the pg_settings view

SELECT name, setting FROM pg_settings WHERE name in ('cluster_name','server_version','port');

@Laurenz Albe suggests using current_setting() which makes it easier to select results in a single row

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.