Re: using a postgres table as a multi-writer multi-updater queue

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: "Steve Petrie, P(dot)Eng(dot)" <apetrie(at)aspetrie(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>, George Neuner <gneuner2(at)comcast(dot)net>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Subject: Re: using a postgres table as a multi-writer multi-updater queue
Date: 2015-12-01 08:56:07
Message-ID: CAF-3MvPt-6ipqQgv-C=oi9DmESa65ArVc7uPLgPF=sS3GugN2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter J. Holzer 2015-12-01 14:51:46 plperlu stored procedure seems to freeze for a minute
Previous Message Steve Petrie, P.Eng. 2015-12-01 04:07:36 Re: using a postgres table as a multi-writer multi-updater queue