From: Ole Streicher <ole-usenet-spam@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Cleaning up large objects
Date: Tue, 10 Aug 2004 17:13:00 +0200 (MEST)
Message-ID: <4890.1092150780@www53.gmx.net> (raw)
Hi,
I have a problem with the cleanup of large objects.
My database consists of (mainly) one table that holds a date and an
associated large object id. The large object can be as big as 2 megabytes.
Every hour, I have a small method that removes all entries that are older
than a certain date:
private void cleanup(Connection dbConn, Date deleteTo) throws SQLException
{
try {
dbConn.setAutoCommit(false);
dbConn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
LargeObjectManager lobj = ((PGConnection)dbConn).getLargeObjectAPI();
PreparedStatement queryStmt = dbConn.prepareStatement(
"SELECT Values FROM MyTable WHERE From_Date < ?");
queryStmt.setTimestamp(0, new Timestamp(deleteTo.getTime()));
ResultSet rs = queryStmt.executeQuery();
try {
while (rs.next()) {
int oid = rs.getInt(1);
try {
lobj.delete(oid);
} catch (SQLException e) {e.printStackTrace();}
}
} finally {
rs.close();
}
PreparedStatement deleteStmt
= dbConn.prepareStatement("DELETE FROM MyTable WHERE From_Date < ?");
deleteStmt.setTimestamp(1, new Timestamp(deleteTo.getTime()));
deleteStmt.executeUpdate();
dbConn.commit();
} catch (SQLException e) {
dbConn.rollback();
throw e;
}
This program also seems to work, that means that I dont get any exceptions
from it.
Also, every night I run the "vacuum" command:
/usr/bin/vacuumdb -a -z
But: the data base keeps growing. The table MyTable seems to successfully
remove the entries, but the disk usage keeps high.
I am quit sure that the disk usage mainly comes from the LOBs since the disk
usage shrinks with exactly the speed I expect from the LOBs I put in.
What is wrong with my approach that it does not free the disk space?
Regards
Ole
--
NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler!
GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: ole-usenet-spam@gmx.net
Subject: Re: Cleaning up large objects
In-Reply-To: <4890.1092150780@www53.gmx.net>
References: <4890.1092150780@www53.gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox