Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eli4W-0007gP-8C for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Feb 2018 21:25:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eli4T-0003K2-O4 for pgsql-bugs@arkaria.postgresql.org; Tue, 13 Feb 2018 21:25:01 +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 1eli4T-0003Jj-EQ for pgsql-bugs@lists.postgresql.org; Tue, 13 Feb 2018 21:25:01 +0000 Received: from d.mail.sonic.net ([64.142.111.50]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eli4P-0005xP-Er for pgsql-bugs@postgresql.org; Tue, 13 Feb 2018 21:24:59 +0000 Received: from engels (162-236-13-58.lightspeed.sntcca.sbcglobal.net [162.236.13.58]) (authenticated bits=0) by d.mail.sonic.net (8.15.1/8.15.1) with ESMTPSA id w1DLOm9L008916 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 13 Feb 2018 13:24:48 -0800 Date: Tue, 13 Feb 2018 13:24:47 -0800 From: David Gould To: Tom Lane Cc: =?UTF-8?B?55+z5YuH6JmO?= , pgsql-bugs@postgresql.org Subject: Re: response time is very long in PG9.5.5 using psql or jdbc Message-ID: <20180213132447.0a26f00c@engels> In-Reply-To: <30157.1518548280@sss.pgh.pa.us> References: <72aa8c39225549dd8c1d18f96df8b1e3@pingan.com.cn> <30153.1518488973@sss.pgh.pa.us> <30157.1518548280@sss.pgh.pa.us> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Sonic-CAuth: UmFuZG9tSVZxUcg5vIeKmts3caxJUdUaXdaSQL7JByUF/PdXVQRMFLpFwBYvc+EUljQ44lWkCBGpSA6L+JM09twbH3dBpuDX X-Sonic-ID: C;bq/mUQQR6BGfTCAFsE207w== M;IDESUgQR6BGfTCAFsE207w== X-Spam-Flag: No X-Sonic-Spam-Details: 0.0/5.0 by cerberusd List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 13 Feb 2018 13:58:00 -0500 Tom Lane wrote: > =?gb2312?B?yq/Twrui?= writes: > > Yes,we have more than 500 thousand of objects,and the total size of the database is almost 10TB.Just as you said,we may need to reduce the objects number,or you have any better solution? > > Hmph. I tried creating 500000 tables in a test database, and couldn't > detect any obvious performance problem in session startup. So there's > something very odd about your results. You might try looking at the > sizes of the system catalogs, e.g like > select pg_size_pretty(pg_total_relation_size('pg_attribute')); > (In my test database, pg_class is about 80MB and pg_attribute about > 800MB.) I see this problem fairly frequently. Typically the problem catalog is pg_attribute as it has the most rows. However the problem really arises when the catalogs become bloated. Once the total size of the catalogs that get read at start up approaches the size of shared buffers, and especially if several processes start at the same time, it becomes quite noticeable. Catalog bloat happens with large numbers of objects because autovacuum is ineffective when: - Catalog churn leading to dead rows - More than about 50,000 tables in one database, causes large stats file - Stats_temp_directory is not set to point to tmpfs so autovacuum stats requests flap the disks. Locally we also patch autovacuum to avoid this. - inflated reltuples prevents vacuum. See patches for bugs 14863 and 15005. Example from one of a clients production instances: # analyze verbose pg_attribute; INFO: analyzing "pg_catalog.pg_attribute" INFO: "pg_attribute": scanned 30000 of 24519424 pages, containing 6475 live rows and 83 dead rows; 6475 rows in sample, 800983035 estimated total rows. The reltuples estimate gets scaled by the bloat and once it gets large enough autovacuum won't look at it anymore as updated rows < 0.2 * reltuples. I have a fix into the next commitfest for the reltuples estimate which once it is reviewed I'd like to recommend for backpatching. -dg -- David Gould daveg@sonic.net If simplicity worked, the world would be overrun with insects.