> And may be someone have such script or other ideas how to log long-running > statements in order to optimize them? I suggest you to take a look at pgFouine: http://pgfouine.projects.postgresql.org/