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');– ReinsbrainJul 9, 2019 at 10:10
-
2You 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 VandivierJul 9, 2019 at 10:14
2 Answers
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.
-
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 Jul 9, 2019 at 10:26
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