Hi There
Just created a .sql script and executes fine, it comes back with two lines of results, I was wondering is there a way of adding up the two results to get a round number. I tired wc -l but that didn't work.
Many Thanks for your help
psql -t -f /opt/ca/SAP_Tooling/sql/self_monitoring/check_number_of_open_connections_database.sql
The result is:
Is there any way of adding those two numbers to get a whole round number of users as in 35.
Can you post the content of /opt/ca/SAP_Tooling/sql/self_monitoring/check_number_of_open_connections_database.sql If we can adjust that, then for sure you can get a total. If not, then if we can decipher it then we can write another bit to count them all.
Robin
Hi Robin
Thanks for the reply, yes I can.
select count(*), state from pg_stat_activity group by state;
\q
Cheers
Alex
You have two main choices:-
Adding another line into your SQL, you could try
select count(*), state from pg_stat_activity group by state;
select count(*) from pg_stat_activity;
\q
If you need to get the value into the script, you could have a follow up script with just the one line like this
select count(*) from pg_stat_activity;
then call it as a subshell so the output ends up in a variable, e.g.
total_recs=$(psql ............)
I hope that this helps,
Robin
1 Like