Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLtWC-000511-9p for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 16:55:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLtWA-0001ai-PW for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 16:55:10 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLtWA-0001aU-Bz for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 16:55:10 +0000 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fLtW3-00030D-3p for pgsql-general@postgresql.org; Thu, 24 May 2018 16:55:09 +0000 Received: by mail-pg0-x22a.google.com with SMTP id u7-v6so1055352pgp.3 for ; Thu, 24 May 2018 09:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=D0fkaeYqkwGTUJ8sko5mYGZ2eixxqDmwKsIdefz5v6Q=; b=WIT6OPRZZyZF6Zf1iiXE3kiufzlOXColnRugnBnR7zBpjhvIorvLy/SpFc18hvQb52 WsWeyY6lY+D3djz7T8IRRIYfF9vF0dnP+Ai1CnpQz7GBEYsmRP50GLiLQC9jYwTirh2x BO6pVf5bk682/dKx22AlCmrZ1R2/GMl0pWNPoLOboBwEi4jWLppFLbWFQelA0/dEYdFc tJFi4gOnjD4iPbWKK8lqJR8KVLpbxKqZoDnwEJ5eCYj3GmwEmYPUf38nP2bz8V8YXqkY fdNinL72dNbl45TgpQJ7rph6pziY1XZO9TP5Crla5m2OzbHug/7LxU6m45xF8qMEMH9e oUZg== 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=D0fkaeYqkwGTUJ8sko5mYGZ2eixxqDmwKsIdefz5v6Q=; b=NMRAnpGOGAiYcos6C3/0qpkDKRYgI+ase52+TR4F1ciIwwlo/rGRu03OxKqYQHA4MS Hdx8DEsS+23wqvurmlEZ5fkG7ilnqwOIpGcWlbffctQmTsyVEeQSotPMg3XTKgdEHOID YDVvQxYdgfvpFaERUaQ/ud3NhnqV/roJRgbany08JC3FTonW+5nlxDYtt52BK3tSIxYT heUwa1yeNuyBZLJTpoz6oepkA/uEobCS+DhSxhHwA9D8oPoF+sTPtuhH6QpP5eNnssy7 GT3dVEfu/y6zaFlnpyzS/eqbCSfgWZlqpS41zpgbMOCodzTG6d3Jcaz2E4i2vpJcSXRq u7/A== X-Gm-Message-State: ALKqPwfVJHAq5mZks/y713vDY5xJMQfWoPnp8lbtbuYlu2gYcljTBi5Y wYL/Fyq8GEfBc6tYuPAP9T8zT5TC X-Google-Smtp-Source: AB8JxZr/fy0hQmuzDGq9cmGtkdA+XwqUv0Td8Ugb8EhCvBgci4cwDRNS9VpUpiKGqLv0031/SmHRpA== X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr6564691pgc.353.1527180900194; Thu, 24 May 2018 09:55:00 -0700 (PDT) Received: from [192.168.2.201] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id c83-v6sm43610586pfc.111.2018.05.24.09.54.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 09:54:59 -0700 (PDT) To: "pgsql-general@postgresql.org" From: Paul Jungwirth Subject: Performance opportunities for write-only audit tables? Message-ID: <95b6c0b4-b73d-01b1-a432-7c8cebe0bde9@illuminatedcomputing.com> Date: Thu, 24 May 2018 09:54:58 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, A project of mine uses a trigger-based approach to record changes to an audit table. The audit table is partitioned by month (pg 9.5, so old-fashioned partitioning). These tables are write-heavy but append-only and practically write-only: we never UPDATE or DELETE, and we seem to consult them only a few times a year. But they are enormous: bigger than the rest of the database in fact. They slow down our backups, they increase WAL size and streaming replication, they add to recovery time, they make upgrades more time-consuming, and I suppose they compete for RAM. This is all on an AWS EC2 instance with EBS storage. We also run a warm standby with streaming replication. Since these tables are so different from everything else, I'm wondering what opportunities we have to reduce their performance cost. I'm interested both in practical high-bang-for-buck changes, but also in harder just-interesting-to-think-about last-resort approaches. Here are a few ideas of my own, but I'm curious what others think: We already have no indexes or foreign keys on these tables, so at least there's no cost there. Since they are already partitioned, we could move old data to offline storage and drop those tables. This feels like the biggest, easiest win, and something we should have done a long time ago. Probably it's all we need. Put them on a different tablespace. This one is also pretty obvious, but aside from using a separate disk, I'm curious what other crazy things we could do. Is there any per-tablespace tuning possible? (I think the answer within Postgres is no, but I wish we could change the settings for wal_level, or exclude them from replication, or something, so I'm wondering if we could achieve the same effect by exploiting being on a separate filesystem.) Maybe put the tablespace on some FUSE filesystem to get async writes? Or just pick different mount options, e.g. on ext4 lazytime,dealloc,data=writeback? I don't know. Or at a different level: change the triggers so they call a custom function that uses a new thread to store the audit records elsewhere. Maybe these ideas are all too risky, but I think the organization is fine with slightly relaxed durability guarantees for this data, and anyway I'm just curious to have a list of possibilities before I categorize anything as too crazy or not. :-) If we upgraded to pg 10 we could use logical replication and leave out the audit tables. That is appealing. Even without upgrading, I guess we could replace those tables with postgres_fdw ones, so that they are not replicated? Has anyone else used that trick? Thanks! -- Paul ~{:-) pj@illuminatedcomputing.com