Dovecot v.2.2.32 and I have configured two imap post-login scripts and it seems like after successfully login scripts are not closed
(dovecot_node/imap imap-postlogin : multiple processes are running still)  and after some times there are too many processes
and the limit is reached (imap proces_limit 1500):

1)
#!/bin/sh

case $IP in
    10.10.1[1-2][0-7].*) exec "$@" ;;
    10.11.2.4[0-9]) exec "$@" ;;
esac

CHECK_USER=`PGPASSWORD="password" /usr/local/pg952/bin/psql -h 10.11.1.3 -q -t -U postfixuser -d mail -c "select imap_allowed from users where name = '$USER' LIMIT 1"`

if [ $CHECK_USER == "t" ] ; then
exec "$@"
fi

if [ $CHECK_USER == "f" ] ; then
exit 0
fi

2)
PGPASSWORD="password" /usr/local/pg952/bin/psql -U postfixuser -d mail2 -h 10.11.1.3 -c "select last_auth('$USER','$RIP2','1')" > /dev/null
exec "$@"

Regards,
Jack