Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e82oN-0002Dx-8p for pgsql-performance@arkaria.postgresql.org; Fri, 27 Oct 2017 11:28:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e82oM-000809-4o for pgsql-performance@arkaria.postgresql.org; Fri, 27 Oct 2017 11:28:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e82oK-0007zl-5j for pgsql-performance@postgresql.org; Fri, 27 Oct 2017 11:28:24 +0000 Received: from mail-bl2nam02on0044.outbound.protection.outlook.com ([104.47.38.44] helo=NAM02-BL2-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e82oF-0005EI-71 for pgsql-performance@postgresql.org; Fri, 27 Oct 2017 11:28:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tangoe.onmicrosoft.com; s=selector1-tangoe-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3UFhciUVGGAi9TkbvPQp9gXz+PRz27aDF6cBW4kf6kw=; b=HpVj5B4DYNlmNgryIfKlyfkOVF9KBQLt3n5xlLKcBHBdfjnWzphMAmNrEdA/jEwAQ074T68UuDOBIJUQyanxc1lxZuJ3f5TPV86kkEyRQ2dFpep+wMEuom3/SIziKYAGkgaAPfpxud+Y8twtyj4X6uICYnBGWzRchhNI58UoMbw= Received: from MWHPR12MB1904.namprd12.prod.outlook.com (10.175.56.10) by MWHPR12MB1903.namprd12.prod.outlook.com (10.175.56.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Fri, 27 Oct 2017 11:28:15 +0000 Received: from MWHPR12MB1904.namprd12.prod.outlook.com ([10.175.56.10]) by MWHPR12MB1904.namprd12.prod.outlook.com ([10.175.56.10]) with mapi id 15.20.0156.007; Fri, 27 Oct 2017 11:28:15 +0000 From: Stefan Petrea To: "pgsql-performance@postgresql.org" Subject: WAL still kept in pg_xlog even long after heavy workload is done Thread-Topic: WAL still kept in pg_xlog even long after heavy workload is done Thread-Index: AdNPFcPc6EOvtgrJSxqzA6ws6OfP7g== Date: Fri, 27 Oct 2017 11:28:15 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Stefan.Petrea@tangoe.com; x-originating-ip: [193.226.155.242] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MWHPR12MB1903;6:M3jTpnxRYXPdJ9sV4j2K1cu7b+Ef5zB/GLD16F6pzBE2nfrzuJ9FoJsnm3iobvCGMxm0PwDVfN9HpTrT2hwYSbgq4vII/ouGIXNu1zRbYcMT5gMXnPDjvqb3HwAZEKvR6/Y3SKEWSPncznUk/KN2NPm1vU6AGqm09Z2bdPNUGCy7HHfCGXzHLEuPZzRMj2UQvmurykfDV3WP8thCQszxLgJ4QJn1gOUONSPzOJabIIbQdEJHFhvyJP+6gX3VwJZ/T7ueDFck7YqfPAZiH7KcxkfvsqK4GuCtDmUacn1Oumu/UeTx/UBT+Le5M0uR4xoj67m9SYZKki1B2ilZ2k6+TnI3I/wwCpMiHrZABbh/ajs=;5:6/GilIRVN5LHgF4WPfu4g6VMd2k9ffv65PloTLQgoPgnlWSaj0Cdv0W8kth0CKpM04dM6ypahfiJ4xmsOn3M/metX3JeTb9+cTH0/e4CqIs6L9iAH++Z9zhiXcra0YrfeNqyxKjstSzMz8K5eCogpIkzeEh09myXNFF41YyV58s=;24:+zKAprqQSxu9XROlSwE3LuyK1n7ExbL3q1v5u3bT0LM+CkBvX5B9dBEUQzDuEijBuIN/b7/ThUt5S9EXJmWnpst674CYJRq0a5fRVXm4iq0=;7:R81N7C99+4JcmT5Nz68VhlVOJod0ox1Dm6lc/nwvl4CGsywrOBuGMFltmGpPbjkWhspSloQE012FzvEHiwHwFugebIr5/O01CWLqy4Mkbs4HdFvQqMRWb4ZGbXI+Z8/fxRw93ZVkeWbNFLZJU3lbMd5pHQo7CF1RzCQ6i78jjD2jCYZLDEiNqZPYW0vdNjEnDX9VAVDh/O/pxQ+fIMhOAzNrHp5BU3a9Jo3qtl16gDMUsbe2eNEdSJPwHbNsNZVp x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-correlation-id: ea99a169-3f07-4de2-926b-08d51d2dd0c6 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627075)(201703031133081)(201702281549075)(2017052603199);SRVR:MWHPR12MB1903; x-ms-traffictypediagnostic: MWHPR12MB1903: x-exchange-antispam-report-test: UriScan:(158342451672863)(166708455590820)(266475516327734)(101568727142576)(17755550239193); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(3231020)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123564025)(20161123558100)(20161123562025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR12MB1903;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR12MB1903; x-forefront-prvs: 0473A03F3F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(376002)(346002)(199003)(189002)(105586002)(7696004)(106356001)(2351001)(5660300001)(33656002)(25786009)(101416001)(81166006)(6916009)(77096006)(81156014)(66066001)(54356999)(6306002)(50986999)(8936002)(14454004)(8676002)(6506006)(316002)(7736002)(478600001)(97736004)(2900100001)(53936002)(189998001)(2501003)(99286003)(55016002)(6436002)(5640700003)(3846002)(9686003)(3280700002)(6116002)(2906002)(966005)(3660700001)(86362001)(575784001)(102836003)(68736007)(72206003)(305945005)(74316002);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1903;H:MWHPR12MB1904.namprd12.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: tangoe.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: tangoe.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea99a169-3f07-4de2-926b-08d51d2dd0c6 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Oct 2017 11:28:15.4639 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3ba13704-9b66-408a-9fb9-db51aba579e4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1903 List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hello, We're encountering some problems with WAL growth in production with PostgreSQL 9.6.3 and 9.6.2. From what I know a WAL file can either be recycled(and would be reused) or deleted. We'd like to have better control over the amount of WAL that is kept around. There were a few occasions where we had to resize partitions because pg_xlog grew as much as it did. According to the docs [1] there are some parameters in GUC (postgresql.conf= ) about this. The parameters I've been able to identify are the following: * wal_keep_segments * max_wal_size * min_wal_size=20 Our WAL grows a lot around the time of our product upgrades (that is, when we upgrade to a new version of our database, so not a Pg upgrade, just a newer version of our db schema, plpgsql code etc). As part of this upgrade, we add new columns or have some large UPDATEs on tables as big as 300M (but in one case we also have one with 1.5B rows). I am seeing the following int he docs [3] min_wal_size (integer) As long as WAL disk usage stays below this setting, old WAL files are=20 always recycled for future use at a checkpoint, rather than removed. This can be used to ensure that enough WAL space is reserved to handle spikes in WAL usage, for example when running large batch jobs. The def= ault is 80 MB. This parameter can only be set in the postgresql.conf file or on the server command line. This sounds very familiar because, that's essentially what we're doing. The= re are some large jobs that cause a lot of workload and changes and generate a= lot of WAL. So far, the way I interpret this is min_wal_size is the amount of WAL recycled (that is kept around to be reused) and max_wal_size is the total amount of WAL allowed to be kept on disk. I would also like to interpret the default values of min_wal_size and max_w= al_size. So if I run the following query: psql -c "select name, setting from pg_settings where name like '%wal_si= ze';" I get the following: max_wal_size|2097152 min_wal_size|1048576 Do these two values look ok? Both these values were generated by pgtune [4], but it seems like pgtune thinks they're expressed by default in KB. Looking at the PostgreSQL code, it seems to me that these two are expressed in MB, at least that's what I understand when I see GUC_UNIT_MB in the source code [6]. So maybe the pgtune fork we're using has a bug in the sense that it produces an incorrect value for those two parameters? (should be in MB but is expressed in KB, therefore much higher than what it should be). Another question is, how can I use any of the checkpoint settings to control the WAL that is kept around? * checkpoint_timeout=20 * checkpoint_completion_target=20 * checkpoint_flush_after=20 * checkpoint_warning=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D I actually tried something with these settings on a test environment. I've used the following settings: checkpoint_timeout =3D 40s min_wal_size =3D 600MB max_wal_size =3D 900MB Then I've created a db named x1 and ran this on it four or five times. pgbench -i -s 70 x1 The pg_xlog directory grew to 2.2G and after a few minutes, it decreased to= 2.0G After about 40 minutes it decreased to 1.4G and it's not going any lower. I was expecting pg_xlog's size to be 600MB after the first WAL removal had = run. Should I expect that the size will eventually drop to 600MB or will it just= sit there at 1.4G? =3D=3D=3D=3D=3D=3D=3D=3D=3D Other thoughts: I have looked a bit at Pg internals too, I'm seeing four functions there that are responsible for removing WAL: XLogArchiveIsReady, RemoveXlogFile, RemoveOldXlogFiles, XLOGfileslop. All of these belong to /src/backend/access/transam/xlog.c The only place in the code that seems to take a decision about how much WAL to recycle and how much to remove is the function XLOGfileslop [2]. It seems like XLOGfileslop is an estimate for the number of WAL to keep around(recycled WAL). Both max_wal_size and min_wal_size are used inside XLOGfileslop. As far as checkpoint_* GUC settings go, they seem to be involved as well. So far, the only thing I know about checkpoints is that between checkpoints, many WAL are created. The amount of WAL between checkpoints can vary. I don't have a good understanding about the interplay between checkpoints and WAL. I'd be grateful for any thoughts on how to improve this, and better control the amount of WAL kept in pg_xlog.=20 Thank you, Stefan [1] https://www.postgresql.org/docs/9.6/static/wal-configuration.html [2] https://github.com/postgres/postgres/blob/0c5803b450e0cc29b3527df3f352e= 6f18a038cc6/src/backend/access/transam/xlog.c#L2258 [3] https://www.postgresql.org/docs/9.6/static/runtime-config-wal.html#RUNT= IME-CONFIG-WAL-CHECKPOINTS [4] https://github.com/kmatt/pgtune [5] https://github.com/kmatt/pgtune/blob/master/pgtune#L560 [6] https://github.com/postgres/postgres/blob/f49842d1ee31b976c681322f76025= d7732e860f3/src/backend/utils/misc/guc.c#L2268 Stefan Petrea System Engineer stefan.petrea@tangoe.com=20 --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance