When you connect to YugabyteDB using the ysqlsh client, you typically provide a host name using the -h switch.
Later you may want to know which host you specified when you connected to the database. For that information we can query the database using current_setting(‘listen_addresses’).
Example:
[yugabyte@ip-172-152-47-248 bin]$ ysqlsh -h 172.152.47.248 -c "SELECT host FROM yb_servers();"
host
----------------
172.152.23.56
172.152.47.248
172.151.27.161
(3 rows)
[yugabyte@ip-172-152-47-248 bin]$ ./ysqlsh -h 172.152.47.248 -c "SELECT * FROM current_setting('listen_addresses') listen_addresses;"
listen_addresses
------------------
172.152.47.248
(1 row)
[yugabyte@ip-172-152-47-248 bin]$ ./ysqlsh -h 172.152.23.56 -c "SELECT * FROM current_setting('listen_addresses') listen_addresses;"
listen_addresses
------------------
172.152.23.56
(1 row)
[yugabyte@ip-172-152-47-248 bin]$ ./ysqlsh -h 172.151.27.161 -c "SELECT * FROM current_setting('listen_addresses') listen_addresses;"
listen_addresses
------------------
172.151.27.161
(1 row)
Have Fun!