cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Move TEMPDB to RAM - any theoretical improvements

Vlad
Product and Topic Expert
Product and Topic Expert
3,125

Hello everybody,

I have a question that came to my mind when I was thinking about the universe and how things are implemented in the DB servers. I know that SA has so-called temporary DB space that stores some temporary data. I think it should be TEMPORARY DB objects such as tables, stored procedures etc. There is a URL (ALTER DBSPACE statement) that says

Preallocating space to the temporary dbspace of a database can improve performance during execution complex queries that use large work tables.

Please correct me, if I am wrong, but it means, SA needs TEMP even for queries (not against temporary tables). So, here are the questions:

  • Would it be a good practice to use RAM-Drive to store temporary DB space there instead of the %TEMP% folder (Windows)? (I admit - it is my headache to foresee the disk size and what to do, when it is empty).
  • Since on *nix we have /tmp (that might be either stored in RAM or in the swap partition), can we surely tell that SA tries to allocate TEMPDB in RAM if it can?

Thank you for your answers, as always.

Thanks,
Vlad

Accepted Solutions (1)

Accepted Solutions (1)

MarkCulp
Participant

The temporary dbspace is used to hold:

  • Temporary table data that needs to be flushed out from the cache. I.e. it is only written to the temp dbspace when the cache page is needed for something else.
  • Intermediate query results. Like above, these pages will only be written to the temp dbspace when they do not completely fit into memory and/or the cache page is needed for something else (that is needing a cache page).
  • database server heap pages. The temp dbspace acts as a backing store for server internal data structures. If a server heap page is not in active use then the server can pitch it out to the temp dbspace if some other process needs a cache page.

So the "short" answer is: If you have "extra" RAM that you can spare then you are likely better off allocating the RAM to the database cache rather than making a RAM disk and putting your temp space on that disk. There are several reasons for saying this, and here are a few:

  • The database server can better utilize the memory when it is in cache: the extra pages can not only be used to store intermediate query results (as mentioned in the question) but can also be used to hold database pages; and access to a cache page only takes a few CPU cycles whereas access to a temp page takes milliseconds (due to all of the extra code required to do a disk read).
  • If the temp space is located in a RAM disk then it is likely limited to a smaller size (i.e. the amount of RAM allocated to the disk), and if your temp space gets full then the database server will not be happy!

HTH

Vlad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Your answer is interesting, and helpful. I appreciate this. If you don't mind, please take a look at my comment above. I think you have answered it already, but just in case if this will be helpful to complete this thread.

I will accept your answer, and I see that in my case I should increase the cache size (since I have ~ 20GB left) and better move the temporary DB space to SSD (if its size is relatively high. Probably SA uses it often).

MarkCulp
Participant

There will always be exceptions, but in general terms you are correct: add the memory to your cache and put your temp dbspace on an SSD (if you have an SSD on your system).

Vlad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you, once again!

Answers (0)