Skip site navigation (1) Skip section navigation (2)

Major problem in PostgreSQL JDBC driver that will cause OutOfMemoryErrors

From: Gerald Gutierrez <gutz(at)kalador(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Major problem in PostgreSQL JDBC driver that will cause OutOfMemoryErrors
Date: 2001-04-10 22:23:53
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
The PostgreSQL JDBC ( bundled with 7.1 RC3 at least) driver makes use of Java's ThreadLocal class in the .../jdbc2/ class to hold onto DateFormat classes used during the setTImestamp() and 
setDate() calls. Sun's J2SE 1.3 has a major bug in the implementation of ThreadLocal in which progressive use leaks more and more memory.

This means that as more PreparedStatements are used, more and more memory is leaked, and at a high rate. Eventually, the Java VM runs out of memory and any applications running within it will crash and burn.

Our stress tests indicate that our application running on top of the Orion application server will crash with an hour after taking up all available memory when using this driver.

A solution is to NOT use ThreadLocal in the PreparedStatement class. This solution works because ThreadLocal is used as an "optimization" to avoid allocating the DateFormat classes multiple times. On our site, we 
patched the RC3 JDBC driver to not use the ThreadLocal object and everything is runnning fine with no perceivable performance loss.

Sun's bug report is here:


pgsql-bugs by date

Next:From: Gerald GutierrezDate: 2001-04-10 22:39:06
Subject: Major Memory Leak in PostgreSQL JDBC Driver
Previous:From: pgsql-bugsDate: 2001-04-10 16:11:37
Subject: Loss of significant digits on pg_dump

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group