Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lEJMV-0008AP-0Z for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 22:07:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEJMT-0004PM-Vm for pgsql-general@arkaria.postgresql.org; Mon, 22 Feb 2021 22:07:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lEHrw-0000T3-LV for pgsql-general@lists.postgresql.org; Mon, 22 Feb 2021 20:31:48 +0000 Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lEHru-0004yR-3M for pgsql-general@postgresql.org; Mon, 22 Feb 2021 20:31:47 +0000 Received: by mail-qt1-x82f.google.com with SMTP id f17so10272915qth.7 for ; Mon, 22 Feb 2021 12:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=discourse.org; s=google; h=from:to:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=47H9wch6VwoC+mPL33TIILgnkqLLbEal8IaX8BCfbaU=; b=lVKuTH/M6UW/xg+AkVdh1KSrURBSYYngK/vvwsRlv9zz7SAaScwBln2uXpQ8iW8Q01 SvLmcxUeDoNrfrec6OyYlXiDBh74iQHAjLi7VK15fU9NG2tO3RCKmoVWo/MV4rO6hYBr Bz5NR3zYZsZLoes3CRYIVWYgJUUc8XUTSl50c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=47H9wch6VwoC+mPL33TIILgnkqLLbEal8IaX8BCfbaU=; b=b/pJqAlU89X8hamwd7WXROaFfkdl4Z02KbmXduSfBZWXtWkdv2F/mk2ktJKWWpTKyt NekcqEKXCMlL8iI9dlzbEqaTI5FfFO3SnJH1h9xhA8LUoYtB65fPExy1mzDS4NcWPXOT g0Q8Dykwa7cO6pd7y9tiAIOA2FKtFzQV5LvPLroh/w7oS+1VJnuJEdrnpcYSSt11K4p9 oKqxdzibBiMLN0FCZ7XkRCUmdVpVWItowVsUYfJT+0EBPSc5XFqi6euPTR4bafvzm8zm iqIVV5OFyqgF9MStpejqsvmoz6MTlJrhZkO6/CMYaHO12u87t8qbKypZ9RejJSWCyyDO v41g== X-Gm-Message-State: AOAM533LhmhEouaRBbYkL+64gtleOHy+J3S7+1MA8IHJ5W7owcNHH2zy coNZpZUXTOAxAwdUi+YAvfCbvCQFZaXmLKRJ X-Google-Smtp-Source: ABdhPJwksX2jx0ML60GxntUqkLLM5gc1P+mXDyRBvFE3gGbaUbedsZbsjbGabdilWsu1nC6mex5bZA== X-Received: by 2002:ac8:59c1:: with SMTP id f1mr21753881qtf.310.1614025904841; Mon, 22 Feb 2021 12:31:44 -0800 (PST) Received: from [192.168.1.216] (dhcp-24-53-242-66.cable.user.start.ca. [24.53.242.66]) by smtp.gmail.com with ESMTPSA id s9sm13652426qke.67.2021.02.22.12.31.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Feb 2021 12:31:44 -0800 (PST) From: Michael Brown To: pgsql-general@postgresql.org Subject: fdatasync performance problem with large number of DB files X-Clacks-Overhead: GNU Terry Pratchett Message-ID: <30a67c98-243e-eef4-eec7-780fabcaa43b@discourse.org> Date: Mon, 22 Feb 2021 15:31:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-CA List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk We've encountered a production performance problem with pg13 related to how it fsyncs the whole data directory in certain scenarios, related to what Paul (bcc'ed) described in a post to pgsql-hackers [1]. Background: We've observed the full recursive fsync is triggered when * pg_basebackup receives a streaming backup (via [2] fsync_dir_recurse or fsync_pgdata) unless --no-sync is specified * postgres starts up unclean (via [3] SyncDataDirectory) We run multiple postgres clusters and some of those clusters have many (~450) databases (one database-per-customer) meaning that the postgres data directory has around 700,000 files. On one of our less loaded servers this takes ~7 minutes to complete, but on another [4] this takes ~90 minutes. Obviously this is untenable risk. We've modified our process that bootstraps a replica via pg_basebackup to instead do "pg_basebackup --no-sync…" followed by a "sync", but we don't have any way to do the equivalent for the postgres startup. I presume the reason postgres doesn't blindly run a sync() is that we don't know what other I/O is on the system and it'd be rude to affect other services. That makes sense, except for our environment the work done by the recursive fsync is orders of magnitude more disruptive than a sync(). My questions are: * is there a knob missing we can configure? * can we get a knob to use a single sync() call instead of a recursive fsync()? * would you be open to merging a patch providing said knob? * is there something else we missed? Thanks! [1]: https://www.postgresql.org/message-id/flat/CAEET0ZHGnbXmi8yF3ywsDZvb3m9CbdsGZgfTXscQ6agcbzcZAw@mail.gmail.com [2]: https://github.com/postgres/postgres/blob/master/src/bin/pg_basebackup/pg_basebackup.c#L2181 [3]: https://github.com/postgres/postgres/blob/master/src/backend/access/transam/xlog.c#L6495 [4]: It should be identical config-wise. It isn't starved for IO but does have other regular write workloads -- Michael Brown Civilized Discourse Construction Kit, Inc. https://www.discourse.org/