PostgreSQL13でクライアントのIPアドレスとポート番号を取得する

環境
PostgreSQL 13.2
Windows 10 Home 64bit

構文
inet_client_addr()
「inet_client_addr()」関数を利用して、クライアントのIPアドレスを取得します。

操作例
1.クライアントのIPアドレスを取得します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select inet_client_addr() result;
result
--------
::1
(1)
postgres=# select inet_client_addr() result; result -------- ::1 (1 行)
postgres=# select inet_client_addr() result;
 result
--------
 ::1
(1 行)

2.クライアントで使用しているポートを確認します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
postgres=# select inet_client_port() result;
result
--------
55985
(1)
postgres=# select inet_client_port() result; result -------- 55985 (1 行)
postgres=# select inet_client_port() result;
 result
--------
  55985
(1 行)

 

PostgreSQL

Posted by arkgame