Skip to content

Analyse user activity in Netezza server

This script will find all the sessions made by any specific user in current pg.log directory.
It pulls the session id as well as all the activities done in that session. Expected output will be pretty long if user have made too many connections and/or ran too many queries.

Script:

#save as analyze_user_activity.sh
USR=$1
PGLOG=/nz/kit/log/postgres/pg.log

for SESSION in `grep -i $USR $PGLOG | awk '/\[/{print $4}'`
do
echo $SESSION
S=`echo $SESSION | sed 's/\[//;s/\]//'`
grep \\[$S\\] $PGLOG
done

How to Run:
Run this script with one parameter, which will be the user id for which you want to monitor the activity.

analyze_user_activity.sh user123