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 1jgTvh-0000gv-EY for pgsql-general@arkaria.postgresql.org; Wed, 03 Jun 2020 13:59:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgTvg-0002FP-9c for pgsql-general@arkaria.postgresql.org; Wed, 03 Jun 2020 13:59:40 +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 1jgTvg-0002FH-1M for pgsql-general@lists.postgresql.org; Wed, 03 Jun 2020 13:59:40 +0000 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgTvZ-0000g7-3G for pgsql-general@lists.postgresql.org; Wed, 03 Jun 2020 13:59:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1591192774; x=1622728774; h=subject:to:references:from:message-id:date:mime-version: in-reply-to:content-transfer-encoding; bh=lpukm/jRPjLWx2CGNwTysRiCMNxLKT2rplW7c+3Zv0E=; b=cKWfLEkCOvxj6bYaeQmTmEQZwXT4rQQkS9yo0uJ3v25bO+m4Fqa2fszB +qGtsse5EPSA9GAW0P/eEv1tG8G6kSiDPCLHiLJmCdg4XHli9KMgW0M9Y CbYv/zUIeToM89/Eq9orO3B/iCu3RlA1lwBLqpKQGpPccO50aDtTbmgGQ M=; IronPort-SDR: fxw4q5oGj91eG0n7ZFaTjvi7/yAAmI26O/zk3AJxl0C8o/1RNPcQWI6FfiChAK9+iSlqyIbNWp bCLl1HANk3PQ== X-IronPort-AV: E=Sophos;i="5.73,467,1583193600"; d="scan'208";a="34140937" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 03 Jun 2020 13:59:18 +0000 Received: from EX13MTAUWA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id 95EA9A26B6; Wed, 3 Jun 2020 13:59:17 +0000 (UTC) Received: from EX13D18UWA002.ant.amazon.com (10.43.160.199) by EX13MTAUWA001.ant.amazon.com (10.43.160.58) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 3 Jun 2020 13:59:17 +0000 Received: from 186590ce269b.ant.amazon.com (10.43.161.82) by EX13D18UWA002.ant.amazon.com (10.43.160.199) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 3 Jun 2020 13:59:17 +0000 Subject: Re: select count(id) on RDS replica causing high CPU load on RDS master To: Azul , References: From: Jeremy Schneider Message-ID: Date: Wed, 3 Jun 2020 06:59:16 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.43.161.82] X-ClientProxiedBy: EX13D19UWA003.ant.amazon.com (10.43.160.170) To EX13D18UWA002.ant.amazon.com (10.43.160.199) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/3/20 04:04, Azul wrote: > so I have a RDS 9.5 master 16vcpu/64GB RAM/5000 IOPS which is RDS > replicating to a replica with the same specs. If you're not already making plans to upgrade this, many people would strongly urge you start now. The final release for 9.5 is less than a year away, after which you will no longer be able to get security updates or bug fixes. https://www.postgresql.org/support/versioning/ Please consider moving in the direction of v12. Just for posterity in case someone googles this email thread in the future, an RDS "read replica" is a "hot standby" in PostgreSQL terminology. https://www.postgresql.org/docs/9.5/high-availability.html > I am running the above on the replica to avoid causing an extra load on > the master, that query takes a long time (lets ignore the fact that it > badly needs an analyse to finish), roughly an hour or so. Just curious, did you happen to enable the hot_standby_feedback parameter? Looks to me like it's off by default in 9.4. > Now what is baffling me is the CPU load on the master goes  up steadily  > all the way to 100% while this select count is running on the slave. > Worth mentioning that CPU on the slave increases by about 10% of so. Which PIDs/processes are using the CPU? (Vacuum? App connections running queries?) For people who manage PostgreSQL themselves, they'd use normal unix utilities like top, ps, etc. On RDS you want to enabled "Enhanced Monitoring" and check the "process list". (In the web console, as of last time I checked: go to the database, choose the "Monitoring" tab, click the dropdown box at the top right that says "Monitoring" and choose "OS Process List".) If you see that it's user sessions, then you can connect with psql at the same time as the high activity and query the contents of pg_stat_activity to get a little more information about what the particular process is doing. -- Jeremy Schneider Database Engineer Amazon Web Services