Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bccoG-0003i1-I4 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Aug 2016 18:21:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bccoG-0007Cn-41 for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Aug 2016 18:21:56 +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.84_2) (envelope-from ) id 1bccoF-0007Ce-KV for pgsql-bugs@postgresql.org; Wed, 24 Aug 2016 18:21:55 +0000 Received: from mail.windfish.net ([2001:4801:7824:104:ca47:84ed:ff10:50ea]) by magus.postgresql.org with esmtps (TLS1.1:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bcco7-0004CZ-8z for pgsql-bugs@postgresql.org; Wed, 24 Aug 2016 18:21:54 +0000 Received: by mail.windfish.net (Postfix, from userid 33) id C89127697B; Wed, 24 Aug 2016 14:21:43 -0400 (EDT) To: Kevin Grittner Subject: Re: BUG #14290: materialized view refresh doesn't use =?UTF-8?Q?temp=5Ftablespace?= X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_3d5b0bfc406abbbeee67788f955235eb" Date: Wed, 24 Aug 2016 14:21:43 -0400 From: Rick Otten Cc: pgsql-bugs@postgresql.org In-Reply-To: References: <20160818190623.1529.12440@wrigleys.postgresql.org> Message-ID: <8879489a97315500562edd71edc5d1fa@www.windfish.net> X-Sender: rotten@windfish.net User-Agent: Roundcube Webmail/1.0.3 X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --=_3d5b0bfc406abbbeee67788f955235eb Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII The distinction between temporary objects that write to disk, and temporary files, never occurred to me before. I had always thought they were the same thing. I think it is a pretty confusing fine point. Yes, I do have the temporary tablespace on the fastest disk since I thought that when I spilled out of memory, I'd still want the best performance I could get during those operations. The temporary files generated during the refresh are several times larger than the final materialized view. This tells me they are probably doing much more I/O than the final (concurrent) write into the materialized view. It made sense to put those temporary writes onto the faster disk. Additionally, in a tiered storage environment, I might put my regular tablespace on a highly redundant (ie, expensive) disk array, and then put my temporary tablespace on a fast, but cheaper disk array because I don't really need the redundancy in the temporary tables the way I do with my regular tables. Another issue is a psychology of disk management. When I look at a 1000G "regular" tablespace that only has 200G of tables on it, I might think "oh, there is plenty of space there for more tables" or "oh, look at all the space I'm wasting, I should pare that back and save a few dollars". Whereas, when I see an 800G temp tablespace on the database, even if it isn't full _at_the_moment_, I think to myself "wow, there must be some big transient queries that need that space which must be why it is there". I now know that I need all that extra space in the "regular tablespace" to support refreshing the materialized views and that in general I should plan for lots of empty space in my regular tablespaces to support that. As I mentioned, I discovered this when a refresh view concurrently failed because it ran the regular tablespace out of disk, even though the disk was only at 40% capacity (when the refresh wasn't running) and I had a large temporary tablespace set up to support things like that. Fortunately I had everything on logical volume managers so it was easy to extend the regular tablespace on the fly once the issue became apparent. This could have been a much more painful thing to discover. Lastly, if I had several tablespaces with these sorts of materialized views in them, they could all share the same temporary tablespace for the refresh. Which means I wouldn't need so much extra space in every tablespace (as long as they didn't all refresh at the same time). On 2016-08-24 13:46, Kevin Grittner wrote: > You are confusing two completely different things: temporary > objects (created by statements starting with CREATE TEMPORARY) and > temporary files (created when data spills to disk during, for > example, a sort, hash, or materialization of data internal to > processing some statement). The former are placed based on > temp_tablespaces; the latter are normally placed in the > base/pgsql_tmp/ subdirectory. > > It would be possible to place them underneath a tablespace > specified by temp_tablespaces, and it might even be a good > enhancement to implement, but that is not the normal or default > location for temporary files. > > Out of curiosity, and to help justify this as a feature request > worth pursuing, can you explain why you want to do this? For > example, have you placed your temporary tablespace on a faster > medium? > > -- > Kevin Grittner > EDB: http://www.enterprisedb.com [1] > The Enterprise PostgreSQL Company Links: ------ [1] http://www.enterprisedb.com --=_3d5b0bfc406abbbeee67788f955235eb Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

The distinction between temporary objects that write to disk, and tempor= ary files, never occurred to me before.  I had always thought they wer= e the same thing.  I think it is a pretty confusing fine point.

Yes, I do have the temporary tablespace on the fastest disk since I thou= ght that when I spilled out of memory, I'd still want the best performance = I could get during those operations.

The temporary files generated during the refresh are several times large= r than the final materialized view.  This tells me they are probably d= oing much more I/O than the final (concurrent) write into the materialized = view.  It made sense to put those temporary writes onto the faster dis= k.

Additionally, in a tiered storage environment, I might put my regular ta= blespace on a highly redundant (ie, expensive) disk array, and then put my = temporary tablespace on a fast, but cheaper disk array because I don't real= ly need the redundancy in the temporary tables the way I do with my regular= tables.

Another issue is a psychology of disk m= anagement.   When I look at a 1000G "regular" tablespace that only has= 200G of tables on it, I might think "oh, there is plenty of space there fo= r more tables" or "oh, look at all the space I'm wasting, I should pare tha= t back and save a few dollars".

Whereas, when I see an 800G temp tablespace on the database, even if it = isn't full _at_the_moment_, I think to myself "wow, there must be some big = transient queries that need that space which must be why it is there".

I now know that I need all that extra s= pace in the "regular tablespace" to support refreshing the materialized vie= ws and that in general I should plan for lots of empty space in my regular = tablespaces to support that.  As I mentioned, I discovered this when a= refresh view concurrently failed because it ran the regular tablespace out= of disk, even though the disk was only at 40% capacity (when the refresh w= asn't running) and I had a large temporary tablespace set up to support thi= ngs like that.  Fortunately I = had everything on logical volume managers so it was easy to extend the regu= lar tablespace on the fly once the issue became apparent.   This could= have been a much more painful thing to discover.

Lastly, if I had several tablespaces wi= th these sorts of materialized views in them, they could all share the same= temporary tablespace for the refresh.  Which means I wouldn't need so= much extra space in every tablespace  (as long as they didn't a= ll refresh at the same time).

 

On 2016-08-24 13:46, Kevin Grittner wro= te:

You are confusing two completely different =
things: temporary
objects (created by statements starting with CREATE TEMPORARY) and
temporary files (created when data spills to disk during, for
example, a sort, hash, or materialization of data internal to
processing some statement).  The former are placed based on
temp_tablespaces; the latter are normally placed in the
base/pgsql_tmp/ subdirectory.

It would be possible to place them underneath a tablespace
specified by temp_tablespaces, and it might even be a good
enhancement to implement, but that is not the normal or default
location for temporary files.

Out of curiosity, and to help justify this as a feature request
worth pursuing, can you explain why you want to do this?  For
example, have you placed your temporary tablespace on a faster
medium?

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

 

--=_3d5b0bfc406abbbeee67788f955235eb--