Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 Postgres 表中有一个列,它将存储连接到数据库的用户的远程 IP 地址。我正在考虑具有某种默认约束的数据类型“inet”。有任何想法吗?
谢谢。
适合您的功能是inet_client_addr().
inet_client_addr()
你能再具体一点吗?你的意思是记录每一个连接到 psql 命令行的用户的 IP,还是你有一个在后端使用 Postgres 数据库构建的网站?如果您从网站登录,那么 inet 数据类型应该可以很好地工作。
查询以获取所有连接到数据库的 ip 客户端
SELECT client_addr FROM pg_stat_activity