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 1ltPD6-0007jH-JY for pgsql-general@arkaria.postgresql.org; Wed, 16 Jun 2021 06:39:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ltPD5-0003qB-DK for pgsql-general@arkaria.postgresql.org; Wed, 16 Jun 2021 06:39:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltPD5-0003q1-2W for pgsql-general@lists.postgresql.org; Wed, 16 Jun 2021 06:39:35 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ltPD2-00038M-J1 for pgsql-general@lists.postgresql.org; Wed, 16 Jun 2021 06:39:34 +0000 Received: by mail-pj1-x102e.google.com with SMTP id i11-20020a17090a2acbb029016f0cce7c3fso936607pjg.3 for ; Tue, 15 Jun 2021 23:39:32 -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=qsGMEwc/DGCxRUXp+w2CPQYY1TZq9PrCZdoekMlY5xs=; b=sTHTZ8AsNMu3kolrqK9llImm08HXmOzBlFvGHGuvHC2dvWCCWVhLj58sJNAQsIu7KV PKZNkmcNnBpTJnu+33sdwAtj+Wl7AdjPlQ/RLVEkbZ/8w00X42iyvZe4wRUz/5IFNk2t zYrpnj+sNZWFi553BJslYJ7p3UZDSQ9dqrE3kdgXOAO1Z377pVzdly0A+ybg2pEjQD72 u1eD+rs8NWTjsrh7xjLL5YqLmlaLJI+rAzyIb/YwhnYZ5VshNxr3VFY0WuEf6uCJMK0k kDR1jMNd7PAVgFmne38tOKAvwDGDXuIxVxhiV4XpRquK2ZPbFi9BDaeciAscu2E+KcE4 YcCQ== 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=qsGMEwc/DGCxRUXp+w2CPQYY1TZq9PrCZdoekMlY5xs=; b=OaSBSgydnym4M7L64cALJf5NfBauakL92lSWn9Zgbp83e589szTU1uKYoqoh0Vssmg to2RfXe4NdlFwqGicEl/jFZtC8AYqA4tt7dn015BXSYjHTt+6GXaaVg7NlmMrnzTk1tv LFv2NhQZgKNLKFW4Lsdwc3+22dPByQP5WsX3u2N4SWapteaXBSTZoHpw1qHLWPnRZgwQ 4A//D3FKDJcdigDJ/ZjNkEcT/JszusdKIW0EidB1g7tE92PlC8TRAj3NcAozDDeG/Sr0 +J82YlHfhR5dYIkF1P2AOykPlcc3fdVztCvVy3sX772JjhUvxX1m1r1d7Mx/G/hbe0Bo WZEw== X-Gm-Message-State: AOAM532BrmezMWD5IuqEcdd7MdkHFkhZ4ypgbeoWZPkTHKORuQMTXwM5 tyec1TiX4r0TQpJQvz4ZsKI= X-Google-Smtp-Source: ABdhPJz0e1xJew9gZh6EbLY/F/UnacTvRC2uYn7RDQpy+QofiiSxojTrdLb7amucxmTBtt7PMqhpwg== X-Received: by 2002:a17:90a:e98f:: with SMTP id v15mr9089128pjy.235.1623825570330; Tue, 15 Jun 2021 23:39:30 -0700 (PDT) Received: from nol (2001-b011-0008-f025-d963-d051-e6ec-9ba6.dynamic-ip6.hinet.net. [2001:b011:8:f025:d963:d051:e6ec:9ba6]) by smtp.gmail.com with ESMTPSA id u9sm4221270pjy.33.2021.06.15.23.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 23:39:29 -0700 (PDT) Date: Wed, 16 Jun 2021 14:39:19 +0800 From: Julien Rouhaud To: Atul Kumar Cc: pgsql-general Subject: Re: clear cache in postgresql Message-ID: <20210616063919.hrysiixqgr2wcyrx@nol> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jun 16, 2021 at 12:02:52PM +0530, Atul Kumar wrote: > > Sometimes I run a Postgres query it takes 30 seconds. Then, I > immediately run the same query and it takes 2 seconds. It appears that > Postgres has some sort of caching. Can I somehow see what that cache > is holding? You can use pgbuffercache for that: https://www.postgresql.org/docs/current/pgbuffercache.html > Can I force all caches to be cleared for tuning purposes? > So I need to clear the cache without restarting/rebooting the postgres > server to check the correct execution plan of my query. No, cleaning postgres cache can only be done with a service restart. That being said, tuning shouldn't be done assuming that there's no cache. On the opposite maybe what you should do is use pg_prewarm (https://www.postgresql.org/docs/current/pgprewarm.html) to make sure that your cache isn't empty after a restart. Note that you also have the operating system cache. It can be cleared without restarting the OS, but I have no idea if this is possible with RDS.