Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4aNB-000430-61 for pgsql-performance@arkaria.postgresql.org; Mon, 24 Sep 2018 23:34:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g4aN8-0000ga-FY for pgsql-performance@arkaria.postgresql.org; Mon, 24 Sep 2018 23:34:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4aN8-0000gS-57 for pgsql-performance@lists.postgresql.org; Mon, 24 Sep 2018 23:34:34 +0000 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g4aN3-0001Q6-50 for pgsql-performance@lists.postgresql.org; Mon, 24 Sep 2018 23:34:33 +0000 Received: by mail-it1-x142.google.com with SMTP id h3-v6so13050348ita.2 for ; Mon, 24 Sep 2018 16:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=7i5mqAEQ5vQLRNMsA7lz1FChwSHUjzGC/a5WsU8FRlQ=; b=x9mqqR/Qqk7y8/jcnydt8NlmXyNSbnF7bCjj6k679aYuPceWOloqn/c+4fem3iB2lQ tZ8gJPXuMukH2YwX34OI1yuiqdnfRef1j7/fyCdSOvzjeQtbUrySrLQeQa8ezsAY4eSv RM3866Y2TuNmvbbOowN0Mg6Kfrj1d4Ks/11vifORTZCPImd/zTYgWCUiZkeeFu1U8/y9 ZI2mmLXqNYwoAD8dgwWs3K27sKML6nwUeZoM1K07FqW9xIS8Ya1UpARdo6N88QLzvJdP 2FX4u8dnqq0KCRL9VmwvHABo0dgPa2ZV2p83G4JIdRf86inDMJrJ13vSJNIsqcwUZoXA LR/w== 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:user-agent; bh=7i5mqAEQ5vQLRNMsA7lz1FChwSHUjzGC/a5WsU8FRlQ=; b=iP7RCoby33E3aPqEM4/rJHdMgPYIJ+GAbbpjh+Gs1chkcMWD2506GueVXOjZ9fshGH Sib5SD6j4xtgivHmu/a48BadmQPy5OXio91kI+ZnOBll4c4pZWt30XW/2CuHQkQD73YW X6NQO8PXG661TTcL3Wm29XbNmOveaqkyJatcajKwOXU8wRweD6GTxSPvL3gd15R623Jx hweUVQekwUmMILbqK090vnnarckgA0it2h0LSa/rM0pWTUgaMsK4e3R7aH4OQoNYCB+/ 2K9blsWjlFwCrIg58FKEGWRlwJLRJfVVsfoiTQefxfCwsaGzDl6XiHA4vtdI2XfNrHpH xJzg== X-Gm-Message-State: ABuFfoj4LnoK6C2LwbXAeWds5uuBob8C3PXBDsaIrsJMd8G2hIlbJaUU UoE9BNj7KWmF9y2dJEoQR3p7mw== X-Google-Smtp-Source: ACcGV62luaUdpvWNA5Mm8Umkpf+p3D79xP8gaYXXQ7LONHxcF+foybu2PQsv62qIRvzZ5HxlaHdaYg== X-Received: by 2002:a02:97c5:: with SMTP id v5-v6mr1170790jaj.72.1537832065967; Mon, 24 Sep 2018 16:34:25 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id v137-v6sm439693itb.11.2018.09.24.16.34.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 16:34:25 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 07DAC8025FB; Mon, 24 Sep 2018 18:34:23 -0500 (CDT) Date: Mon, 24 Sep 2018 18:34:23 -0500 From: Justin Pryzby To: Vladimir Ryabtsev Cc: f.pardi@portavita.eu, pgsql-performance@lists.postgresql.org Subject: Re: Why could different data in a table be processed with different performance? Message-ID: <20180924233423.GV2471@telsasoft.com> References: <4dbb8bea-bea3-74d8-a537-36bb9864cb9f@portavita.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Sep 24, 2018 at 03:28:15PM -0700, Vladimir Ryabtsev wrote: > > it is not unusual to have 1GB cache or more... and do not forget to drop > the cache between tests + do a sync > I also reviewed import scripts and found the import was done in DESCENDING > order of IDs. This seems significant..it means the heap was probably written in backwards order relative to the IDs, and the OS readahead is ineffective when index scanning across a range of IDs. From memory, linux since (at least) 2.6.32 can optimize this. You mentioned you're using 4.4. Does your LVM have readahead ramped up ? Try lvchange -r 65536 data/postgres (or similar). Also..these might be an impractical solution for several reasons, but did you try either 1) forcing a bitmap scan (of only one index), to force the heap reads to be ordered, if not sequential? SET enable_indexscan=off (and maybe SET enable_seqscan=off and others as needed). Or, 2) Using a brin index (scanning of which always results in bitmap heap scan). > > - how big is the table? > pg_table_size('articles') = 427 GB > pg_table_size('pg_toast.pg_toast_221558') = 359 GB Ouch .. if it were me, I would definitely want to make that a partitioned table.. Or perhaps two unioned together with a view? One each for the sparse and dense range? > > You can make use of pg_buffercache in order to see what is actually > cached. > It seems that there is no such a view in my DB, could it be that the module > is not installed? Right, it's in the postgresql -contrib package. And you have to "CREATE EXTENSION pg_buffercache". > > - As Laurenz suggested (VACUUM FULL), you might want to move data around. > You can try also a dump + restore to narrow the problem to data or disk > I launched VACUUM FULL, but it ran very slowly, according to my calculation > it might take 17 hours. I will try to do copy data into another table with > the same structure or spin up another server, and let you know. I *suspect* VACUUM FULL won't help, since (AIUI) it copies all "visible" tuples from the source table into a new table (and updates indices as necessary). It can resolve bloat due to historic DELETEs, but since I think your table was written in reverse order of pkey, I think it'll also copy it in reverse order. CLUSTER will fix that. You can use pg_repack to do so online...but it's going to be painful for a table+toast 1TiB in size: it'll take all day, and also require an additional 1TB while running (same as VAC FULL). Justin