PostgreSQL 9.3:查询以获取主机名、端口号和用户名
PostgreSQL 9.3: Query to get hostname,port number and username
我想编写一个查询,它应该会得到以下详细信息:
- 主持人,
- 端口,
- 用户名。
就像我们进入PgAdmin如下图所示:
根据 a_horse_with_no_name 在 this answer 中所说只给我端口号。
SELECT CURRENT_USER usr
,inet_server_addr() host -- use inet_client_addr() to get address of the remote connection
,inet_server_port() port -- use inet_client_port() to get port of the remote connection
试试主机名
select *
from pg_settings
where name = 'listen_addresses'
基于上面 w͏̢in̡͢g͘̕ed̨p̢͟a͞n͏͏t̡͜͝he̸r̴ 的回答;
SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;
这使用 psql 的内置 HOST 变量,已记录 here
我想编写一个查询,它应该会得到以下详细信息:
- 主持人,
- 端口,
- 用户名。
就像我们进入PgAdmin如下图所示:
根据 a_horse_with_no_name 在 this answer 中所说只给我端口号。
SELECT CURRENT_USER usr
,inet_server_addr() host -- use inet_client_addr() to get address of the remote connection
,inet_server_port() port -- use inet_client_port() to get port of the remote connection
试试主机名
select *
from pg_settings
where name = 'listen_addresses'
基于上面 w͏̢in̡͢g͘̕ed̨p̢͟a͞n͏͏t̡͜͝he̸r̴ 的回答;
SELECT CURRENT_USER usr, :'HOST' host, inet_server_port() port;
这使用 psql 的内置 HOST 变量,已记录 here