Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iWweZ-0008I7-3x for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2019 06:06:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iWweX-0003dJ-BI for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2019 06:06:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iWweW-0003dB-Ru for pgsql-general@lists.postgresql.org; Tue, 19 Nov 2019 06:06:17 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iWweS-0001c6-OY for pgsql-general@postgresql.org; Tue, 19 Nov 2019 06:06:15 +0000 Received: by mail-wm1-x332.google.com with SMTP id z19so2007356wmk.3 for ; Mon, 18 Nov 2019 22:06:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=lmoSmzOr3DmIebXcdcWNc2t4tAlZ74zSFaIo2H23ZAY=; b=Ztatc5N38dX1Vmv5BdeaAhyQ9KOywZGBxaZByD6Qad6y/mp+k/L7Sb4aeG43RQM3pG +7xgjf5BwzYxoHrKqezo40XihaooZ6YlCicWfRbkByzwLZVF5XjBc7mIEJz8t1UPLCfI PaVAy0+O06d3ACoSY65ZAVsfeMr/1s3hx3GFn802siR+UNbnAXvNiY7nXr5zBNMjfahN Ng6ZUyVlMILmpj1tG4FBzg7ywq7HPJGeGmp8i3j1I5E4iV1FtIjD3asyRU6xfiGQSvD+ bN2148Jtqfs66lfwuI4L+oJ0GpA8IDXAqJVGViOhhSIqnubPhZYZfwSz5scdFrRACZ8I sD0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lmoSmzOr3DmIebXcdcWNc2t4tAlZ74zSFaIo2H23ZAY=; b=HIAxFQ/o41KFdVXZAKv3E0vLaEi6I3+/Wh6QAi6RBHIaDJrPK2qTNSuDwYfWOugdpS u78A33fADClRR3IuY6mN0VvITozBdIxJKMPdGEUBpRLOHHVB1Wz6P14k5TAybS5uddXb khzxi6r3YSOuVgTkily3XvRD+8nOeeXr+FmSF8BCMxgx6JAMVsc2SFmIGGEIWL9+cQQT oVcQA4pCmvfSGJuPVVjkDtljaj96rvvBRbH8tp5wY27hsDe7THFcPBo+YCJG3vdprV1y 1d7QPSJg+Ar4Q7gClK/vnjZ4Do5eMX48aYMdf5B3swLgtZmduZ/PQkRaYmNuqNRv2IkU lGhQ== X-Gm-Message-State: APjAAAXJrOY2CeUmVXG+Sni/oCdNRs7ZisTBS27XyvstZ8Uu7qBdKteM Ete+Ga5wc4JjW0Txc6vOkOltvbZH X-Google-Smtp-Source: APXvYqxkoBuCgEjCyj+FsGf2rYmx5u+MxvQSjQiIs9xDI0u629ihr7LLuMaEmJuZSLUbl7h61BKKuw== X-Received: by 2002:a7b:c055:: with SMTP id u21mr3520505wmc.55.1574143570511; Mon, 18 Nov 2019 22:06:10 -0800 (PST) Received: from 127.0.0.1 ([77.89.245.35]) by smtp.googlemail.com with ESMTPSA id q15sm25890746wrs.91.2019.11.18.22.06.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Nov 2019 22:06:09 -0800 (PST) Subject: Re: Partition, inheritance for storing syslog records. From: Mimiko To: Postgresql-general References: Message-ID: Date: Tue, 19 Nov 2019 08:06:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=koi8-r; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Any one can give some advice? On 11.11.2019 13:45, Mimiko wrote: > 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. > -- Mimiko desu.