Postgresql - 100% 确定使用 SSL 连接服务器?

bla*_*oon 2 postgresql ssl psql

是否可以检查(作为非 root 用户/SQL 问题)来检查我从客户端到服务器的连接是否使用 SSL(我的目标服务器 cas 使用安全和非安全连接)?

Vao*_*sun 7

从 9.5 开始:

https://www.postgresql.org/docs/current/static/monitoring-stats.html#PG-STAT-SSL-VIEW

pg_stat_ssl 视图将包含每个后端或 WAL 发送方进程的一行,显示有关此连接上 SSL 使用情况的统计信息。它可以连接到 pid 列上的 pg_stat_activity 或 pg_stat_replication 以获取有关连接的更多详细信息。

t=# set role notsu ;
SET
Time: 9.289 ms
t=> select * from pg_stat_ssl where pid = pg_backend_pid();
  pid  | ssl | version | cipher | bits | compression | clientdn
-------+-----+---------+--------+------+-------------+----------
 43767 | f   |         |        |      |             |
(1 row)

Time: 10.846 ms
t=> \du+ notsu
                  List of roles
 Role name | Attributes | Member of | Description
-----------+------------+-----------+-------------
 notsu     |            | {}        |
Run Code Online (Sandbox Code Playgroud)

以上显示我的连接不是 SSL