postgresql 如何获取机器ip和机器名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42863126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:32:09  来源:igfitidea点击:

How to get machine ip and machine name

postgresql

提问by Riya Bansal

Below query gives server ip. But i need machine ip. Please suggest how to get machine ip and machine name.

下面的查询给出了服务器 ip。但我需要机器ip。请建议如何获取机器 ip 和机器名称。

select inet_client_addr();

I used below query to get machine name but did not work.

我使用下面的查询来获取机器名称,但没有用。

SELECT * FROM pg_stat_activity
WHERE client_addr = inet_client_addr()

回答by Laurenz Albe

Your question is not clear, but if you want the IP address of the database server you are connected to, you could try

你的问题不清楚,但是如果你想要你连接的数据库服务器的IP地址,你可以试试

SELECT inet_server_addr();

But remember that every computer has several IP addresses. If you connected to localhost, you will get 127.0.0.1or ::1, depending whether you use IPv4 or IPv6.

但请记住,每台计算机都有多个 IP 地址。如果您连接到localhost,您将获得127.0.0.1::1,具体取决于您使用的是 IPv4 还是 IPv6。

There is no function to figure out allIP addresses of the database server. If you need that, you'd have to write a function in a sufficiently powerful unrestricted language like PL/PerlU.

没有找出数据库服务器的所有IP 地址的功能。如果需要,则必须使用足够强大的不受限制的语言(如PL/PerlU )编写函数。