Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get machine ip and machine name

Tags:

postgresql

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

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()
like image 462
Riya Bansal Avatar asked Mar 17 '17 16:03

Riya Bansal


Video Answer


1 Answers

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

SELECT inet_server_addr();

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

There is no function to figure out all IP 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.

like image 102
Laurenz Albe Avatar answered Nov 09 '22 15:11

Laurenz Albe