Wednesday, June 13, 2018

[google-cloud-sql-discuss] Re: Without superuser, how can I terminate rogue sessions?

1- I attached a screenshot of running the following command that gives client hostname, query start time, etc which are all available on pg_stat_activity.

select client_hostname, client_addr, query_start from pg_stat_activity;

2- For zombie sessions, you don't need a 'super' user to do this. See this doc on (9.5) Loosen security checks for viewing queries in pg_stat_activity. As a result, here is a sample command to kill the connections: 

SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'your_database_name' AND pid <> pg_backend_pid() AND state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled') AND state_change < current_timestamp - INTERVAL '15' MINUTE;






--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/b5f48537-b7c3-4770-a7ae-b133cd7fced9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment