Re: using a postgres table as a multi-writer multi-updater queue - Mailing list pgsql-general

From Alban Hertroys
Subject Re: using a postgres table as a multi-writer multi-updater queue
Date
Msg-id CAF-3MvPt-6ipqQgv-C=oi9DmESa65ArVc7uPLgPF=sS3GugN2Q@mail.gmail.com
Whole thread Raw
In response to Re: using a postgres table as a multi-writer multi-updater queue  ("Steve Petrie, P.Eng." <apetrie@aspetrie.net>)
List pgsql-general
> Before I start in to implement a DELETE / AUTOVACUUM / VACUUM approach, to
> recycling disk space used for a session management table, I would like to
> propose, for consideration by this forum, an idea for a different approach.
>
> A row in a session management table, represents a significant "sunk cost" in
> both computing time used to create the row, and in disk space allocated.
> Postgres has to use a lot of resources to create that row in the first
> place.
>
> When the session that originally caused that row to be allocated, eventually
> expires -- why delete the associated session managent row ??
>
> Instead of using a DELETE command to destroy the row (and a
> resource-intensive AUTOVACUUM / VACUUM process to reclaim the storage
> space), why not instead, simply mark that session management row as "free"
> (with an UPDATE command) ??

An UPDATE is a combination of an INSERT and a DELETE command.

However, rows marked as deleted will be reused at some point after
autovacuum (or manual VACUUM) has made sure they are no longer in use
by any DB session.

So your approach can still work, as long as you vacuum that table
frequently enough. The actual solution isn't the UPDATE instead of the
DELETE though, but rather the partial index and an increased
autovacuum frequency.

Alban.
--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.


pgsql-general by date:

Previous
From: "Steve Petrie, P.Eng."
Date:
Subject: Re: using a postgres table as a multi-writer multi-updater queue
Next
From: "Peter J. Holzer"
Date:
Subject: plperlu stored procedure seems to freeze for a minute