class | text | hostname | text | ip_address | text | promise_handle | text | promiser | text | promisee | text | policy_server | text | rowId | integer | \ not null default nextval('"agent_log_rowId_seq"'::regclass) timestamp | timestamp with time zone | promise_outcome | text | Indexes: "primary_key" PRIMARY KEY, btree ("rowId") "client_by_timestamp" btree ("timestamp", class) #### 2014-01-22T13:44:00 any 192.168.0.1 moon.example.com ... 2014-01-22T14:44:00 any 192.168.0.1 moon.example.com ... KEEP 2014-01-22T14:44:00 any 192.168.0.2 mars.example.com ... KEEP 2014-01-22T13:44:00 any 192.168.0.2 mars.example.com ... 2014-01-23T13:44:00 any 192.168.0.1 moon.example.com ... 2014-01-23T14:44:00 any 192.168.0.1 moon.example.com ... KEEP 2014-01-23T14:44:00 any 192.168.0.2 mars.example.com ... KEEP 2014-01-23T13:44:00 any 192.168.0.2 mars.example.com ... 2014-01-22T13:44:00 cpu_1 192.168.0.1 moon.example.com ... 2014-01-22T14:44:00 cpu_1 192.168.0.1 moon.example.com ... KEEP 2014-01-22T14:44:00 cpu_1 192.168.0.2 mars.example.com ... KEEP 2014-01-22T13:44:00 cpu_1 192.168.0.2 mars.example.com ... 2014-01-23T13:44:00 cpu_1 192.168.0.1 moon.example.com ... 2014-01-23T14:44:00 cpu_1 192.168.0.1 moon.example.com ... KEEP 2014-01-23T14:44:00 cpu_1 192.168.0.2 mars.example.com ... KEEP 2014-01-23T13:44:00 cpu_1 192.168.0.2 mars.example.com ... #### SELECT class, max(timestamp) as timestamp, hostname, ip_address, promise_handle, promiser, promisee, policy_server, promise_outcome FROM agent_log WHERE timestamp < now() - interval '7 days' GROUP BY class, DATE_TRUNC( 'day', timestamp), hostname, ip_address, promise_handle, promiser, promisee, policy_server, promise_outcome