Correct/optimal DML query for application session management ?

From: Tim Smith <randomdev4+postgres(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Correct/optimal DML query for application session management ?
Date: 2015-01-06 18:02:27
Message-ID: CA+HuS5HAwGt5NkAYkTQpoZbsD-xErWX0pUkP50EjGcHjFvc2fA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I'm probably being incredibly stupid and missing something incredibly
simple but I've got a bit of query-writers block here !

create table app_sessions(
session_id char(64) unique not null,
user_id char(32) unique not null,
session_start bigint not null,
session_lastactive bigint not null
);

The rules are :
Enforced session timeout after 86400 seconds (1 day)
Last active less than 1 hour ago.

My idea to clean out stale sessions :
delete from app_sessions where extract (epoch from
now())-session_start>86400 or session_lastactive<=extract (epoch from
now())-3600;

But of course that's going to be a nasty query, so that's why I think
I'm missing something and need a fresh pair of eyes (or a whole
mailing list's worth of eyes !!).

Thanks guys !

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andy Colson 2015-01-06 18:35:45 Re: Correct/optimal DML query for application session management ?
Previous Message Rob Sargent 2015-01-06 17:57:32 Re: Advice for using integer arrays?