Обсуждение: Temporary tablespaces on a RAM disk

Поиск
Список
Период
Сортировка

Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
Hi,

is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

Thanks in advance
Daniel

RE: Temporary tablespaces on a RAM disk

От
Kevin Brannen
Дата:

Daniel Westermann wrote:

> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?

> I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

 

 

Well, we point our "stats_temp_directory" to a tmpfs partition, which is probably fairly common (or so I'd guess).

But a full tablespace with tables and everything? That sounds pretty risky for anything other than a place to store

data for transformation or summary of data that could be recreated by restarting a process if the server goes down

in the middle.

 

I think you'd be better off explaining what your goal is and then people could give you better comments.

 

HTH,

Kevin

 .

This e-mail transmission, and any documents, files or previous e-mail messages attached to it, may contain confidential information. If you are not the intended recipient, or a person responsible for delivering it to the intended recipient, you are hereby notified that any disclosure, distribution, review, copy or use of any of the information contained in or attached to this message is STRICTLY PROHIBITED. If you have received this transmission in error, please immediately notify us by reply e-mail, and destroy the original transmission and its attachments without reading them or saving them to disk. Thank you.

Re: Temporary tablespaces on a RAM disk

От
"David G. Johnston"
Дата:
On Tue, Mar 17, 2020 at 2:49 AM Daniel Westermann (DWE) <daniel.westermann@dbi-services.com> wrote:
is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

There is a nice big bold warning callout in the documentation that covers this explicitly.


David J.

Re: Temporary tablespaces on a RAM disk

От
Ron
Дата:


On 3/17/20 12:19 PM, David G. Johnston wrote:
On Tue, Mar 17, 2020 at 2:49 AM Daniel Westermann (DWE) <daniel.westermann@dbi-services.com> wrote:
is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

There is a nice big bold warning callout in the documentation that covers this explicitly.


Warning
Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster.

But aren't temporary files removed when you restart Postgres?  (I'm assuming that temp_tablespaces is treated "the same" as data/pgsql_tmp.  Is that a false assumption?)


--
Angular momentum makes the world go 'round.

Re: Temporary tablespaces on a RAM disk

От
Tom Lane
Дата:
Ron <ronljohnsonjr@gmail.com> writes:
> On 3/17/20 12:19 PM, David G. Johnston wrote:
>> There is a nice big bold warning callout in the documentation that covers
>> this explicitly.
>> https://www.postgresql.org/docs/12/manage-ag-tablespaces.html

>>> Warning
>>> Placing a tablespace on a temporary file system like a RAM disk risks the
>>> reliability of the entire cluster.

> But aren't temporary files removed when you restart Postgres?  (I'm assuming
> that temp_tablespaces is treated "the same" as data/pgsql_tmp.  Is that a
> false assumption?)

I think the main issue is that there's no mechanism preventing you from
putting regular (non-temp) tables into the "temporary" tablespace.
If you do, crash recovery will get very unhappy when it tries to replay
updates for those tables and they're not there.

There are probably additional issues having to do with the tablespace
directory(s) disappearing.  That, you could maybe finesse by having the
postmaster start script re-create any missing directories.

All in all, I wouldn't try it without careful pre-testing of what happens
after the RAM disk gets wiped.

People have asked about this before, so maybe it'd be an idea to make
an explicit concept of a temp tablespace that only accepts temp tables,
and do whatever is needful to make that robust.  But I've not heard of
any work towards that.

            regards, tom lane



Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
On Tue, Mar 17, 2020 at 2:49 AM Daniel Westermann (DWE) <daniel.westermann@dbi-services.com> wrote:
is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

>There is a nice big bold warning callout in the documentation that covers this explicitly.
>

I know, I am talking about temp_tablespaces only, so temporary objects like temporary tables, sorts, .etc.

Regards
Daniel

Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
Daniel Westermann wrote:

> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?

> I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

 

 

>Well, we point our "stats_temp_directory" to a tmpfs partition, which is probably fairly common (or so I'd guess).

>But a full tablespace with tables and everything? That sounds pretty risky for anything other than a place to store

>data for transformation or summary of data that could be recreated by restarting a process if the server goes down

>in the middle.

 

>I think you'd be better off explaining what your goal is and then people could give you better comments.

 


Thank you for the hint with stats_temp_directory. I am only talking about temp_tablespaces which are supposed for temporary objects only. It is pretty clear not to use that for persistent objects, I know.


Regards

Daniel

Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
Ron <ronljohnsonjr@gmail.com> writes:
> On 3/17/20 12:19 PM, David G. Johnston wrote:
>> There is a nice big bold warning callout in the documentation that covers
>> this explicitly.
>> https://www.postgresql.org/docs/12/manage-ag-tablespaces.html

>>> Warning
>>> Placing a tablespace on a temporary file system like a RAM disk risks the
>>> reliability of the entire cluster.

> But aren't temporary files removed when you restart Postgres?  (I'm assuming
> that temp_tablespaces is treated "the same" as data/pgsql_tmp.  Is that a
> false assumption?)

>I think the main issue is that there's no mechanism preventing you from
>putting regular (non-temp) tables into the "temporary" tablespace.
>If you do, crash recovery will get very unhappy when it tries to replay
>updates for those tables and they're not there.

Yes, that works and this is why I asked for temp_tablespaces which are supposed to hold temporary objects only, I believe.

>There are probably additional issues having to do with the tablespace
>directory(s) disappearing.  That, you could maybe finesse by having the
>postmaster start script re-create any missing directories.

Yes, but the server will start even if the tmpfs is gone, you just need to recreate it, which also can be handled with /etc/fstab for booting.

>All in all, I wouldn't try it without careful pre-testing of what happens
>after the RAM disk gets wiped.

Sure.

>People have asked about this before, so maybe it'd be an idea to make
>an explicit concept of a temp tablespace that only accepts temp tables,
>and do whatever is needful to make that robust.  But I've not heard of
>any work towards that.

That's what I thought temp_tablespaces are for ( plus sorts, temporary files getting created by materialized views ... )

Regards
Daniel


Re: Temporary tablespaces on a RAM disk

От
Tom Lane
Дата:
"Daniel Westermann (DWE)" <daniel.westermann@dbi-services.com> writes:
>> People have asked about this before, so maybe it'd be an idea to make
>> an explicit concept of a temp tablespace that only accepts temp tables,
>> and do whatever is needful to make that robust.  But I've not heard of
>> any work towards that.

> That's what I thought temp_tablespaces are for ( plus sorts, temporary files getting created by materialized views
...) 

No ... temp_tablespaces says it's okay to use any of the listed
tablespaces to keep temporary working files in, but it doesn't
say that those tablespaces can *only* be used for that.

The whole business of temp tables (as opposed to those invisible-to-SQL
working files) in such a tablespace is a separate issue, too.  I think
that the server would mostly survive having temp-table files disappear
during reboot, but it's not an officially supported or tested scenario.

            regards, tom lane



Re: Temporary tablespaces on a RAM disk

От
Laurenz Albe
Дата:
On Tue, 2020-03-17 at 09:49 +0000, Daniel Westermann (DWE) wrote:
> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
> I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad
ideanor the opposite.
 

Taking a step back, wouldn't it be better to increase "work_mem"
and "temp_buffers" and set "temp_file_limit", so that temporary
files are avoided whenever possible and temporary tables are cached?

Then essentially you are using the same memory for the same purposes,
but in a supported fashion.

Yours,
Laurenz Albe




Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
>"Daniel Westermann (DWE)" <daniel.westermann@dbi-services.com> writes:

>>> People have asked about this before, so maybe it'd be an idea to make
>>> an explicit concept of a temp tablespace that only accepts temp tables,
>>> and do whatever is needful to make that robust.  But I've not heard of
>>> any work towards that.

>> That's what I thought temp_tablespaces are for ( plus sorts, temporary files getting created by materialized views ... )

>No ... temp_tablespaces says it's okay to use any of the listed
>tablespaces to keep temporary working files in, but it doesn't
>say that those tablespaces can *only* be used for that.

Ok, understood. For me, at least, it sounds weird to put anything other than real temporary stuff in there.

>The whole business of temp tables (as opposed to those invisible-to-SQL
>working files) in such a tablespace is a separate issue, too.  I think
>that the server would mostly survive having temp-table files disappear
>during reboot, but it's not an officially supported or tested scenario.

Thank you, that is what I wanted to know. I works for all the cases I tested, but it is not officially supported.

Regards
Daniel

Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
Hi  Laurenz,

>From: Laurenz Albe <laurenz.albe@cybertec.at>
>Sent: Tuesday, March 17, 2020 20:50
>To: Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
>Subject: Re: Temporary tablespaces on a RAM disk
 
>On Tue, 2020-03-17 at 09:49 +0000, Daniel Westermann (DWE) wrote:
>> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
>> I did some quick tests and checked the archives but could not find any information that either confirmed it is a bad idea nor the opposite.

>Taking a step back, wouldn't it be better to increase "work_mem"
>and "temp_buffers" and set "temp_file_limit", so that temporary
>files are avoided whenever possible and temporary tables are cached?

I don't think you can avoid that for all cases, especially when working with large data sets. That was one of the reasons for my initial question.

>Then essentially you are using the same memory for the same purposes,
>but in a supported fashion.

Agreed.

Regards
Daniel

Re: Temporary tablespaces on a RAM disk

От
Laurenz Albe
Дата:
On Tue, 2020-03-17 at 19:57 +0000, Daniel Westermann (DWE) wrote:
> >> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
> >> I did some quick tests and checked the archives but could not find any
> >> information that either confirmed it is a bad idea nor the opposite.
> 
> >Taking a step back, wouldn't it be better to increase "work_mem"
> >and "temp_buffers" and set "temp_file_limit", so that temporary
> >files are avoided whenever possible and temporary tables are cached?
> 
> I don't think you can avoid that for all cases, especially when working
> with large data sets. That was one of the reasons for my initial question.

But with your proposed setup, any query that needs more temp space
than your RAM disk has will fail.  I don't think that is good for large
data sets.

Setting "work_mem" and "temp_buffers" high, you can use all the RAM
you have, and if it still is not enough, it spills to disk rather than die.

Yours,
Laurenz Albe




Re: Temporary tablespaces on a RAM disk

От
Jerry Sievers
Дата:
Laurenz Albe <laurenz.albe@cybertec.at> writes:

> On Tue, 2020-03-17 at 19:57 +0000, Daniel Westermann (DWE) wrote:
>
>> >> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
>> >> I did some quick tests and checked the archives but could not find any
>> >> information that either confirmed it is a bad idea nor the opposite.
>> 
>> >Taking a step back, wouldn't it be better to increase "work_mem"
>> >and "temp_buffers" and set "temp_file_limit", so that temporary
>> >files are avoided whenever possible and temporary tables are cached?
>> 
>> I don't think you can avoid that for all cases, especially when working
>> with large data sets. That was one of the reasons for my initial question.
>
> But with your proposed setup, any query that needs more temp space
> than your RAM disk has will fail.  I don't think that is good for large
> data sets.

Perhaps not, but disk filling on the same volume as WAL is also a
serious problem in case the process that eventually took the storage to
100% and got an ENoSpace was the WAL write :-)

Er, but any standard 1-tablespace configuration is at risk of that,
generally.

FWIW

>
> Setting "work_mem" and "temp_buffers" high, you can use all the RAM
> you have, and if it still is not enough, it spills to disk rather than die.
>
> Yours,
> Laurenz Albe
>
>
>
>

-- 
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres.consulting@comcast.net



Re: Temporary tablespaces on a RAM disk

От
"Daniel Westermann (DWE)"
Дата:
>Laurenz Albe <laurenz.albe@cybertec.at> writes:

>> On Tue, 2020-03-17 at 19:57 +0000, Daniel Westermann (DWE) wrote:
>>
>>> >> is someone using temporary tablespaces on a RAM disk ? Any experiences with that?
>>> >> I did some quick tests and checked the archives but could not find any
>>> >> information that either confirmed it is a bad idea nor the opposite.
>>>
>>> >Taking a step back, wouldn't it be better to increase "work_mem"
>>> >and "temp_buffers" and set "temp_file_limit", so that temporary
>>> >files are avoided whenever possible and temporary tables are cached?
>>>
>>> I don't think you can avoid that for all cases, especially when working
>>> with large data sets. That was one of the reasons for my initial question.
>>
>> But with your proposed setup, any query that needs more temp space
>> than your RAM disk has will fail.  I don't think that is good for large
>> data sets.

>Perhaps not, but disk filling on the same volume as WAL is also a
>serious problem in case the process that eventually took the storage to
>100% and got an ENoSpace was the WAL write :-)

>Er, but any standard 1-tablespace configuration is at risk of that,
>generally.

Thank you all for your input.

Regards
Daniel