On one of my servers (Windows 2008 Server), creating connection in Java to PostgreSQL server takes from 1,5 to 4 seconds! I have no clue how to start checking what can be wrong. I tried different database on this server, different user. Still the same. If I work with backup of database on my computer, it's 150ms. I would be grateful for any tip where to start.

  • How long it is when you try to connect to PostgreSQL by psql or telnet? – dezso Nov 21 '12 at 18:48
  • 1
    I answer myself - it was SSL set to on. – Michal Nov 22 '12 at 8:04
  • 1
    SSL is on by default on major linux distros like ubuntu and debian. It does not generally add several seconds to the connection time. As an example, I connect to PG/SSL in 0.08s locally and 0.2s remotely through a WAN. – Daniel Vérité Nov 22 '12 at 12:49
  • It's Windows 2008, not linux. You can believe or not, turning off SSL resulted in shortening acquiring connection time and general SQL queries time :) Weird, but I am happy I am through it already. – Michal Nov 23 '12 at 8:28
  • 3
    I've seen similar problem when you don't have a working DNS config. This is often a problem if the server tries to resolve the hostname of better logging or authentication. – Trygve Laugstøl Nov 23 '12 at 14:06

I answer myself - it was SSL set to on. Setting ssl to off in postgresql.conf solved the problem.

  • Turning off SSL - but how? Where? Only for that connection in Java or globally on the Windows server? Or in PostgreSQL? – dezso Nov 26 '12 at 9:03
  • in PostgreSQL .conf file. It's disabled by default. – Michal Nov 26 '12 at 12:19
  • Several seconds delay is not explainable by SSL alone (unless the system is really really badly loaded). Is this a linux DB server? I suspect most likely due to a slow /dev/random on this machine. This is very typical for login slowdown (alas normally on the client). SSL does need extra random numbers. – eckes Nov 16 '14 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.