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 1iU88m-0001bb-T1 for pgsql-general@arkaria.postgresql.org; Mon, 11 Nov 2019 11:45:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iU88l-0002Ca-Lt for pgsql-general@arkaria.postgresql.org; Mon, 11 Nov 2019 11:45:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iU88l-0002CT-CT for pgsql-general@lists.postgresql.org; Mon, 11 Nov 2019 11:45:51 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iU887-0003uA-Rn for pgsql-general@postgresql.org; Mon, 11 Nov 2019 11:45:50 +0000 Received: by mail-lf1-x132.google.com with SMTP id j14so1005723lfk.6 for ; Mon, 11 Nov 2019 03:45:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=+yNo0lN1KGXF9if5+Ot80JC2oxmLcePAeyGn2ot9giQ=; b=SUy+CqZgGpd7lizwaOd/SShYr9jReY6pWG47g3E9ujd5z3B+O9PJ+yAaqCSLBuHItm VJHPVCoNWYYyclRt5TqgQ/pb0VBcGi2wl0jsxCkVMtWBqzP2qcUYz6JvHbnhO7Ywt8Ke IDlacwC3XZi/q+QWZps19L5ftGla8PMW8ueVO+aOc0ALtyg3V7eYcUDNRScwd6d2d143 W4nZ37Lb1N0IXhNlq5ABGlD1uoz7efPMa8+i72MOpTzyjn2B91FfaCvprFz2KHny64uR et3ABMBYoraPGD2u6dOQvLBXfH4GBgcsY/3qa/l7JU67OPNbBvLOQLWAsGVTZthPaWjf gxag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=+yNo0lN1KGXF9if5+Ot80JC2oxmLcePAeyGn2ot9giQ=; b=VU6WQOSezHcFDF9+FRKbsBBf3RXz6UpT+ofNW2PIekgRsKH3HzDm1OokTeu4iRSRHB qX6+Y7g6Lcd0QV7gFzrTqDKzhCc271bCO/AMxVR0lV+zfVTwYA13y7LM7mtJcEZ3nXRi Q7gza9lKU1QW1QsaxWxK4kRBOwbsxICqhOGaLwfglIfT8cYHMFKApz06nnHSS7u83w7S cQDHtOofEkGAJQSI4+AidFlDRpv/uoGtoEKXMdsLgdB3SqoO5TjGEscnOQSaJpvKkIST 0MgfNTd9RSfHbknBRAh/IwyWjPW0KdgP7K7dEDOHQkO0/UKUCwQI+pPyMiwJcGkAWYwv r0cw== X-Gm-Message-State: APjAAAVxWh/QCCx5pAZjtJwQ2UGm+lEOxi5OVAqhWH2z+fk4VbzD/pjP gbWY2E9SlL5JdnNtl3zu80Biw3Xx X-Google-Smtp-Source: APXvYqxvF1SomXOFxCfkK729xCmtiQNoR4iitZ29UMH6/Y0gzfgvGZyO4Kk2/6c8M1I+CGxEBhrVMw== X-Received: by 2002:a19:6756:: with SMTP id e22mr7339440lfj.148.1573472710143; Mon, 11 Nov 2019 03:45:10 -0800 (PST) Received: from 127.0.0.1 ([77.89.245.35]) by smtp.googlemail.com with ESMTPSA id q189sm7043250ljq.79.2019.11.11.03.45.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Nov 2019 03:45:09 -0800 (PST) To: Postgresql-general From: Mimiko Subject: Partition, inheritance for storing syslog records. Message-ID: Date: Mon, 11 Nov 2019 13:45: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 Content-Type: text/plain; charset=koi8-r; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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.