pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mimiko <vbvbrj@gmail.com>
To: Postgresql-general <pgsql-general@postgresql.org>
Subject: Partition, inheritance for storing syslog records.
Date: Mon, 11 Nov 2019 13:45:07 +0200
Message-ID: <fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com> (raw)

Hello.

I beg for the community ideas on how to do in the best way.

I use centrally storing syslog messages in Postgres. All devices send syslog messages to a server (or could be several in fault tolerance) which use 
rsyslog to store the logs in the DB (currently I'm using mysql and postgre storing same entries).

In time obvious the table grows. While now I have about 50GB of data, I want to plan for future storing and retrieving logs when needed to investigate 
something.

I would not explain the columns of the syslog table as it is standard from the rsyslog provided info.

A while I ago on Postgre 8.4 (I know it old and planning to move to latest release) I implemented inheritance, when creating main table and make 
inheritable tables using checks on syslogtag column to store logs from some specific applications (like dhcpd, smbd, tftpd) in separate tables. And 
created table rules on main table to place the incoming entries in respective table.

CREATE TABLE syslog_dhcpd
(
   CONSTRAINT syslog_dhcpd_pkey PRIMARY KEY (id),
   CONSTRAINT syslog_dhcpd_message_unique UNIQUE (devicereportedtime, facility, priority, fromhost, message, syslogtag),
   CONSTRAINT syslog_dhcpd_syslogtag_check CHECK (syslogtag::text ~~ 'dhcpd%'::text)
)
INHERITS (syslog);

CREATE OR REPLACE RULE syslog_dhcpd_insert_rule AS
     ON INSERT TO syslog
    WHERE new.syslogtag::text ~~ 'dhcpd%'::text DO INSTEAD  INSERT INTO syslog_dhcpd (customerid, receivedat, devicereportedtime, facility, priority, 
fromhost, message, ntseverity, importance, eventsource, eventuser, eventcategory, eventid, eventbinarydata, maxavailable, currusage, minusage, 
maxusage, infounitid, syslogtag, eventlogtype, genericfilename, systemid)
   VALUES (new.customerid, new.receivedat, new.devicereportedtime, new.facility, new.priority, new.fromhost, new.message, new.ntseverity, 
new.importance, new.eventsource, new.eventuser, new.eventcategory, new.eventid, new.eventbinarydata, new.maxavailable, new.currusage, new.minusage, 
new.maxusage, new.infounitid, new.syslogtag, new.eventlogtype, new.genericfilename, new.systemid);


As this is was the only way to make partitioning on the version 8.4 (alternatively is using triggers), but it is not quite good on expanding.

My goal is to make partitioning in such way:

Partition by syslogtag so every application will go to separate partition.
Then sub-partition each partition by fromhost (there will be about 10 different hosts that I want to be separate, others should go on main).
Then sub-sub-partition by year.

There could be not sub-partition by fromhost. Only by syslogtag, then by year.

So how could be this accomplished both in version 8.4 and in version 12. Other ideas are welcome.

The main goal is to be able to quickly investigate logs from some applications and some host searching regex in `message` column.






view thread (3+ messages)  latest in thread

Message-ID: <fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com>
Permalink:  ../fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com/
Also on:    postgresql.org/message-id/fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: vbvbrj@gmail.com
  Subject: Re: Partition, inheritance for storing syslog records.
  In-Reply-To: <fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com>
  References: <fce028d3-02df-362d-06b7-e6c388c78e8e@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox