回答:
このSQLはあなたを助けます
select max_conn,used,res_for_super,max_conn-used-res_for_super res_for_normal
from
(select count(*) used from pg_stat_activity) t1,
(select setting::int res_for_super from pg_settings where name=$$superuser_reserved_connections$$) t2,
(select setting::int max_conn from pg_settings where name=$$max_connections$$) t3
結果:
max_conn | used | res_for_super | res_for_normal
---------+------+---------------+----------------
100 | 2 | 3 | 95
(1 row)
これをシェルに入れることができます:
#!/bin/bash
for (( c=1; c<=3600; c++ ))
do
gsql -U pgdba -W pgdba -p 6432 -c "sql" >> /home/pgdba/res_data.log
sleep 1 # once per second
done
または、結果をテーブルに記録してから実行できます
postgres=# copy restbl to '/home/pgdba/res.csv' csv header;
結果のcsvファイルを取得します。