Is there any error handling in there? I remember seeing performance issues if you put in any code to catch exceptions.
pgsql-performance by date:
Соглашаюсь с условиями обработки персональных данных