Can I use the hostname of the server in a PostgreSQL
SELECT statement? The following may be close but apparently does not quite work:
\set x \! hostname select :x;
This is for PostgreSQL 9.6 on Debian.
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
What is called is
getaddrinfo that provides a
CANONNAME but that's essentially just your own method of addressing the server not the "symbolic hostname". If you need the hostname, you'll have to build a C-extension that does just that. Or, use a third party procedural language, like perl
plperlu, that has that support (through
plv8 that has
Another method would be simply reading the file
It's a database, not a remote administration utility. You can't really fault it for not doing this.
PostgreSQL has 2 functions for getting server address information.
inet_server_port() which provide ip address and port information of the server.
However I don't know a direct way for getting hostname. So, you may try this;
For other system functions you can check System Information Functions section of the documentation.