Skip to content

Instantly share code, notes, and snippets.

@linuxmalaysia
Last active October 9, 2024 05:06
Show Gist options
  • Save linuxmalaysia/1edd671311f3f7d75af110198279d791 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/1edd671311f3f7d75af110198279d791 to your computer and use it in GitHub Desktop.
Idle In Transaction Problem - Postgresql
#!/bin/bash
# Harisfazillah Jamel - 20211216
# Part of script from https://wiki.lyrasis.org/display/DSPACE/Idle+In+Transaction+Problem
# Idle In Transaction Problem
pgprocess_array=( $( /usr/bin/pgrep -f 'idle in transaction' ) )
/usr/bin/pgrep -f 'idle in transaction' | wc -l | logger
for r in "${pgprocess_array[@]}"; do
/usr/bin/test `/usr/bin/pgrep -f 'idle in transaction' | /usr/bin/wc \-l ` \-gt 0 && /usr/bin/pkill \-o \-f 'idle in transaction'
### /usr/bin/test `/usr/bin/pgrep -f 'idle in transaction' | /usr/bin/wc \-l ` \-gt 20 && /usr/bin/pkill \-o \-f 'idle in transaction'
### /usr/bin/pgrep -f 'idle in transaction' | wc -l
echo "PG $r"
done
/usr/bin/pgrep -f 'idle in transaction' | wc -l | logger
exit
@linuxmalaysia
Copy link
Author

To check

SELECT count(*),state FROM pg_stat_activity GROUP BY 2;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment