-- log out all sessions that were ununsed since 30 minutes

UPDATE
    wwwdb_state
SET
    key_value = '0'
WHERE
    key_name = 'ActualLogin' AND
    session_id IN (SELECT
                       t1.session_id
                   FROM
                       wwwdb_state t1, wwwdb_state t2
                   WHERE
                       t1.key_name    =  'last_access'              AND
                       t1.last_change <  now() - '1 mins'::reltime AND
                       t2.key_name    =  'ActualLogin'              AND
                       t2.key_value   != '0'                        AND
                       t1.session_id  =  t2.session_id);
