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 1lvezu-0000QE-20 for pgsql-admin@arkaria.postgresql.org; Tue, 22 Jun 2021 11:55:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvezt-000258-18 for pgsql-admin@arkaria.postgresql.org; Tue, 22 Jun 2021 11:55:17 +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 1lvezs-000250-OM for pgsql-admin@lists.postgresql.org; Tue, 22 Jun 2021 11:55:16 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lvezm-0003VQ-Cx for pgsql-admin@lists.postgresql.org; Tue, 22 Jun 2021 11:55:15 +0000 Received: by mail-pf1-x433.google.com with SMTP id a127so5663342pfa.10 for ; Tue, 22 Jun 2021 04:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cFdPabd3fQh/5rNa04vVGCfh0vuMKEE5ARbnufQkaJ8=; b=re2WJNkqsBf+T0XRWrdXdcWkB4K5R5ENnxiHXuOw/esIgDbl6CDbxQCrJojkvP/79W OAPBkhq6DifaZPou8xuZOm/TSCck39UuBL+WuZWU2/fIA0ZrUo85jJZKFsyFCQ2aJGuJ KRuWdGpgGg+DieoMSVZQlL1dSUe0gXUW2nKrpyCv1UmqB+yDsD7roIW7rdgX80hUv8es HotwEzBSMv9590sGmqdMY4s3N0w11PolGHD896aiKVVNK8rcenwUJlbK35o966/Kwdh7 gHuyTnbRoLiuk9/fCkCRALJoMGvsqyxkSqJ/bBSMJ5g5WTcTgH/EsJxxcQuLb2l8HMqv qZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cFdPabd3fQh/5rNa04vVGCfh0vuMKEE5ARbnufQkaJ8=; b=RCti5QcfjJ0upY+Fg+xxLac77PiAJ9MKYinocAYFZMr8P/lT1u+axemC+11VQztbvh AElNh8yCKECVYo90LNrDUNUslcCPL1fvtjUhB61dtBDeQXVUYjZD1jh/1rJPMmRRTbXE arwN3h7rz1J5CDn0B/wmEfIRHw00cLt6cQwXDmqaFklNkH0rtsroJb+SfAqMoJ7LS2cu I8O6qf6ithuiiIJzzYaA1HTqfQ+7b5IDU/wpZsBEAt/4Jw0AVA3bBMAGITiiyVx8N7+X 05rYPfJFAtA9kbqR9FZFk0/FUWYXYt2LjmhM5e/LqzUX/x9fLDXE3IhhTl9fGz4BLMG5 ZGJg== X-Gm-Message-State: AOAM531k/fQmXMFLnqrx0ygDk8Jh7JPO/Vwo5549qwmFm5Sp+obMU0op O4XZLqpjKs4LO3YRUfFnhOw= X-Google-Smtp-Source: ABdhPJxw2oDhZ3udqw9mZ9uAugBcSOxlfkxTybJ5lCsOjtPFEH1VLjCFfEDk5zhEbpqc9DCDkl5z5w== X-Received: by 2002:a05:6a00:852:b029:2f9:e608:e10d with SMTP id q18-20020a056a000852b02902f9e608e10dmr3272092pfk.71.1624362908921; Tue, 22 Jun 2021 04:55:08 -0700 (PDT) Received: from nol (2001-b011-000a-92b6-4cbd-3547-2266-39f9.dynamic-ip6.hinet.net. [2001:b011:a:92b6:4cbd:3547:2266:39f9]) by smtp.gmail.com with ESMTPSA id e1sm1042877pfd.16.2021.06.22.04.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Jun 2021 04:55:08 -0700 (PDT) Date: Tue, 22 Jun 2021 19:55:06 +0800 From: Julien Rouhaud To: "Radoulov, Dimitre" Cc: pgsql-admin@lists.postgresql.org Subject: Re: Temp files for simple queries Message-ID: <20210622115506.o2u4u5krplxxc54k@nol> References: <45cc44dd-b830-5df5-1f09-171e9874bbc0@gmail.com> <16aa733d-bcaf-0aa6-f3f0-5206de695e92@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16aa733d-bcaf-0aa6-f3f0-5206de695e92@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jun 22, 2021 at 01:51:55PM +0200, Radoulov, Dimitre wrote: > Just to clarify: the size of the temp file is 7MB and with work_mem of 4MB > it clearly doesn't fit. > > But why an "order by" of a 440kB of data would require 7MB. > > One possible reason is that that the number of records in that table varies > significantly during the day, That would be the logical explanation. You could configure auto_explain to make sure of that (https://www.postgresql.org/docs/current/auto-explain.html). > but - if that's the case - I would expect that > the table would be much bigger than 440kB (size taken using \dt+). Not necessarily. autovacuum can truncate the file if all the trailing blocks are empty (and if it can acquire an exclusive lock fast enough), so if some client inserts a lot of rows, process them and remove them all, and later on slowly start to insert new rows you will get that behavior.