{"id":13671,"date":"2020-03-18T07:20:21","date_gmt":"2020-03-18T06:20:21","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/"},"modified":"2020-03-18T07:20:21","modified_gmt":"2020-03-18T06:20:21","slug":"can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/","title":{"rendered":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?"},"content":{"rendered":"<p>The short answer to the title of this blog post is: yes, of course you can. The more important question is: should you? The <a href=\"https:\/\/www.postgresql.org\/docs\/current\/manage-ag-tablespaces.html\" target=\"_blank\" rel=\"noopener noreferrer\">PostgreSQL documentation about tablespaces<\/a> contains an explicit warning: &#8220;Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster&#8221;. This is for sure true for tablespaces containing persistent data, but what about objects\/files that are created in a temporary tablespace like temporary tables or sorts that are going to disk? Does the warning from the documentation apply to these as well? You can check <a href=\"https:\/\/www.dbi-services.com\/blog\/about-temp_tablespaces-in-postgresql\/\" target=\"_blank\" rel=\"noopener noreferrer\">the last blog about temporary tablespaces<\/a> for getting an idea what actually goes to temporary tablespaces in PostgreSQL. <\/p>\n<p>On Linux a RAM disk can be created quite easily:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mkfs  \/dev\/my_ram_disk 81920\nmke2fs 1.44.6 (5-Mar-2019)\nCreating regular file \/dev\/my_ram_disk\nCreating filesystem with 81920 1k blocks and 20480 inodes\nFilesystem UUID: ecc6d90e-2d59-47f8-a598-7726c309c389\nSuperblock backups stored on blocks: \n        8193, 24577, 40961, 57345, 73729\n\nAllocating group tables: done                            \nWriting inode tables: done                            \nWriting superblocks and filesystem accounting information: done \n<\/pre>\n<p>Of course that needs to be mounted somewhere so that we can put a temporary tablespace on it:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mkdir \/my_ram_disk\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mount \/dev\/my_ram_disk \/my_ram_disk\/\npostgres@centos8pg:\/home\/postgres\/ [pgdev] df -h | grep my_ram\n\/dev\/loop0            78M  1.6M   72M   3% \/my_ram_disk\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo chown postgres:postgres \/my_ram_disk\n<\/pre>\n<p>I am going to create a new PostgreSQL cluster from scratch:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] initdb -D \/var\/tmp\/pg\npostgres@centos8pg:\/home\/postgres\/ [pgdev] export PGPORT=8888\npostgres@centos8pg:\/home\/postgres\/ [pgdev] pg_ctl -D \/var\/tmp\/pg\/ start -l \/dev\/null\n<\/pre>\n<p>Preparing the temporary tablespace and setting it as the default:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] psql -X -p 8888 postgres\npsql (13devel)\nType \"help\" for help.\n\npostgres=# ! mkdir \/my_ram_disk\/tbs\/\npostgres=# create tablespace my_temp_tbs location '\/my_ram_disk\/tbs\/';\nCREATE TABLESPACE\npostgres=# db+\n                                       List of tablespaces\n    Name     |  Owner   |     Location     | Access privileges | Options |  Size   | Description \n-------------+----------+------------------+-------------------+---------+---------+-------------\n my_temp_tbs | postgres | \/my_ram_disk\/tbs |                   |         | 0 bytes | \n pg_default  | postgres |                  |                   |         | 22 MB   | \n pg_global   | postgres |                  |                   |         | 559 kB  | \n(3 rows)\n\npostgres=# alter system set temp_tablespaces = 'my_temp_tbs';\nALTER SYSTEM\npostgres=# select pg_reload_conf();\n pg_reload_conf \n----------------\n t\n(1 row)\n\npostgres=# show temp_tablespaces ;\n temp_tablespaces \n------------------\n my_temp_tbs\n(1 row)\n<\/pre>\n<p>Creating a new temporary table should now create the underlying file on the RAM disk:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres=# create temporary table tmp1 ( a int, b date );\nCREATE TABLE\npostgres=# select pg_relation_filepath('tmp1');\n              pg_relation_filepath              \n------------------------------------------------\n pg_tblspc\/16384\/PG_13_202003051\/12732\/t3_16387\n(1 row)\npostgres-# ! ls -la \/var\/tmp\/pg\/pg_tblspc\/\ntotal 4\ndrwx------.  2 postgres postgres   19 Mar 16 21:32 .\ndrwx------. 19 postgres postgres 4096 Mar 16 21:32 ..\nlrwxrwxrwx.  1 postgres postgres   16 Mar 16 21:32 16384 -&gt; \/my_ram_disk\/tbs\n<\/pre>\n<p>Everything as expected. What could possibly go wrong with that? Will PostgreSQL start just fine if we put data in that table and then crash the postmaster?<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres=# insert into tmp1 select * from generate_series(1,10000);\nINSERT 0 10000\npostgres=# ! ps -ef | grep postgres | grep \"var\/tmp\"\npostgres 25900     1  0 21:31 ?        00:00:00 \/u01\/app\/postgres\/product\/DEV\/db_1\/bin\/postgres -D \/var\/tmp\/pg\npostgres 25992 25911  0 21:47 pts\/0    00:00:00 sh -c ps -ef | grep postgres | grep \"var\/tmp\"\npostgres 25995 25992  0 21:47 pts\/0    00:00:00 grep var\/tmp\npostgres=# ! kill -9 25900\npostgres=# select 1;\nFATAL:  terminating connection due to unexpected postmaster exit\nserver closed the connection unexpectedly\n        This probably means the server terminated abnormally\n        before or while processing the request.\nThe connection to the server was lost. Attempting reset: Failed.\n!?&gt; select 1;\nYou are currently not connected to a database.\n!?&gt; \n<\/pre>\n<p>Can we start normally from here on?<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] pg_ctl -D \/var\/tmp\/pg\/ start\npg_ctl: another server might be running; trying to start server anyway\nwaiting for server to start....2020-03-16 21:49:33.034 CET [26010] LOG:  starting PostgreSQL 13devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4), 64-bit\n2020-03-16 21:49:33.035 CET [26010] LOG:  listening on IPv6 address \"::1\", port 8888\n2020-03-16 21:49:33.035 CET [26010] LOG:  listening on IPv4 address \"127.0.0.1\", port 8888\n2020-03-16 21:49:33.037 CET [26010] LOG:  listening on Unix socket \"\/tmp\/.s.PGSQL.8888\"\n2020-03-16 21:49:33.041 CET [26011] LOG:  database system was interrupted; last known up at 2020-03-16 21:36:18 CET\n2020-03-16 21:49:33.263 CET [26011] LOG:  database system was not properly shut down; automatic recovery in progress\n2020-03-16 21:49:33.264 CET [26011] LOG:  redo starts at 0\/156D588\n2020-03-16 21:49:33.264 CET [26011] LOG:  invalid record length at 0\/1574240: wanted 24, got 0\n2020-03-16 21:49:33.264 CET [26011] LOG:  redo done at 0\/1574068\n2020-03-16 21:49:33.277 CET [26010] LOG:  database system is ready to accept connections\n done\nserver started\n<\/pre>\n<p>All is fine. Of course the temporary table is gone but that would also have been the case if we just ended our session instead of killing the postmaster:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] psql -X -p 8888 postgres\npsql (13devel)\nType \"help\" for help.\n\npostgres=# d tmp1\nDid not find any relation named \"tmp1\".\npostgres=# db+\n                                        List of tablespaces\n    Name     |  Owner   |     Location     | Access privileges | Options |    Size    | Description \n-------------+----------+------------------+-------------------+---------+------------+-------------\n my_temp_tbs | postgres | \/my_ram_disk\/tbs |                   |         | 1024 bytes | \n pg_default  | postgres |                  |                   |         | 22 MB      | \n pg_global   | postgres |                  |                   |         | 559 kB     | \n(3 rows)\n\npostgres=# \n<\/pre>\n<p>Sort operations will just work fine on that tablespace as well:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres=# select * from generate_series(1,1000000) order by random();\n generate_series \n-----------------\n          943370\n          301661\n...\n<\/pre>\n<p>&#8230; but you need to be careful with the size of the RAM disk:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres=# select * from generate_series(1,5000000) order by random();\n2020-03-16 22:04:47.738 CET [26026] ERROR:  could not write block 629 of temporary file: No space left on device\n2020-03-16 22:04:47.738 CET [26026] STATEMENT:  select * from generate_series(1,5000000) order by random();\nERROR:  could not write block 629 of temporary file: No space left on device\n<\/pre>\n<p>So actually you can put a temporary tablespace on a RAM disk and I am not aware of serious issues, even if you lose the RAM disk that can easily be fixed:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo umount \/my_ram_disk \npostgres@centos8pg:\/home\/postgres\/ [pgdev] pg_ctl -D \/var\/tmp\/pg\/ restart\nwaiting for server to shut down....2020-03-16 22:06:23.118 CET [26010] LOG:  received fast shutdown request\n2020-03-16 22:06:23.124 CET [26010] LOG:  aborting any active transactions\n2020-03-16 22:06:23.133 CET [26010] LOG:  background worker \"logical replication launcher\" (PID 26017) exited with exit code 1\n2020-03-16 22:06:23.133 CET [26012] LOG:  shutting down\n2020-03-16 22:06:23.148 CET [26010] LOG:  database system is shut down\n done\nserver stopped\nwaiting for server to start....2020-03-16 22:06:23.281 CET [26236] LOG:  starting PostgreSQL 13devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4), 64-bit\n2020-03-16 22:06:23.282 CET [26236] LOG:  listening on IPv6 address \"::1\", port 8888\n2020-03-16 22:06:23.282 CET [26236] LOG:  listening on IPv4 address \"127.0.0.1\", port 8888\n2020-03-16 22:06:23.286 CET [26236] LOG:  listening on Unix socket \"\/tmp\/.s.PGSQL.8888\"\n2020-03-16 22:06:23.289 CET [26236] LOG:  could not open directory \"pg_tblspc\/16384\/PG_13_202003051\": No such file or directory\n2020-03-16 22:06:23.293 CET [26237] LOG:  database system was shut down at 2020-03-16 22:06:23 CET\n2020-03-16 22:06:23.293 CET [26237] LOG:  could not open directory \"pg_tblspc\/16384\/PG_13_202003051\": No such file or directory\n2020-03-16 22:06:23.299 CET [26236] LOG:  database system is ready to accept connections\n done\nserver started\n<\/pre>\n<p>PostreSQL will complain but it will start and once the RAM disk is avaialble again there is business as usual:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mount \/dev\/my_ram_disk \/my_ram_disk\/\n22:07:33 postgres@centos8pg:\/home\/postgres\/ [pgdev] psql -X -p 8888 postgres\npsql (13devel)\nType \"help\" for help.\n\npostgres=# create temporary table tmp1 ( a int );\nCREATE TABLE\npostgres=# ! ls -la \/my_ram_disk\/\ntotal 19\ndrwxr-xr-x.  4 postgres postgres  1024 Mar 16 21:31 .\ndr-xr-xr-x. 23 root     root      4096 Mar 16 21:28 ..\ndrwx------.  2 root     root     12288 Mar 16 21:27 lost+found\ndrwx------.  3 postgres postgres  1024 Mar 16 21:32 tbs\npostgres=# ! ls -la \/my_ram_disk\/tbs\/\ntotal 5\ndrwx------. 3 postgres postgres 1024 Mar 16 21:32 .\ndrwxr-xr-x. 4 postgres postgres 1024 Mar 16 21:31 ..\ndrwx------. 4 postgres postgres 1024 Mar 16 22:02 PG_13_202003051\npostgres=# \n<\/pre>\n<p>If you know any issues with that or have any comments I would be happy if you can share your thoughts. <\/p>\n<p>Another option would by to use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Tmpfs\" target=\"_blank\" rel=\"noopener noreferrer\">tmpfs<\/a>:<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mkdir \/my_ram_disk_2\/\npostgres@centos8pg:\/home\/postgres\/ [pgdev] sudo mount -t tmpfs -o size=2G tmpfs \/my_ram_disk_2\/\npostgres@centos8pg:\/home\/postgres\/ [pgdev] df -h | grep disk_2\ntmpfs                2.0G     0  2.0G   0% \/my_ram_disk_2\n<\/pre>\n<p>This can be used for temporary tablespaces as well:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] psql -X -p 8888 postgres\npsql (13devel)\nType \"help\" for help.\n\npostgres=# ! sudo chown postgres:postgres \/my_ram_disk_2\/\npostgres=# ! mkdir \/my_ram_disk_2\/tbs2\npostgres=# create tablespace my_temp_tbs2 location '\/my_ram_disk_2\/tbs2';\nCREATE TABLESPACE\npostgres=# db+\n                                          List of tablespaces\n     Name     |  Owner   |      Location       | Access privileges | Options |    Size    | Description \n--------------+----------+---------------------+-------------------+---------+------------+-------------\n my_temp_tbs  | postgres | \/my_ram_disk\/tbs    |                   |         | 2048 bytes | \n my_temp_tbs2 | postgres | \/my_ram_disk_2\/tbs2 |                   |         | 0 bytes    | \n pg_default   | postgres |                     |                   |         | 22 MB      | \n pg_global    | postgres |                     |                   |         | 559 kB     | \n(4 rows)\n\npostgres=# alter system set temp_tablespaces = 'my_temp_tbs2';\nALTER SYSTEM\npostgres=# select pg_reload_conf();\n pg_reload_conf \n----------------\n t\n(1 row)\n\npostgres=# show temp_tablespaces ;\n temp_tablespaces \n------------------\n my_temp_tbs2\n(1 row)\n<\/pre>\n<p>Same test as above:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres=# create temporary table tmp3 ( a int );\nCREATE TABLE\npostgres=# insert into tmp3 select * from generate_series(1,10000);\nINSERT 0 10000\npostgres=# select pg_relation_filepath('tmp3');\n              pg_relation_filepath              \n------------------------------------------------\n pg_tblspc\/24583\/PG_13_202003051\/12732\/t3_24587\n(1 row)\n\npostgres=# ! ls -la \/var\/tmp\/pg\/pg_tblspc\/\ntotal 4\ndrwx------.  2 postgres postgres   32 Mar 16 22:31 .\ndrwx------. 19 postgres postgres 4096 Mar 16 22:32 ..\nlrwxrwxrwx.  1 postgres postgres   16 Mar 16 21:32 16384 -&gt; \/my_ram_disk\/tbs\nlrwxrwxrwx.  1 postgres postgres   19 Mar 16 22:31 24583 -&gt; \/my_ram_disk_2\/tbs2\npostgres=# ! ps -ef | grep postgres | grep \"var\/tmp\"\npostgres 26236     1  0 22:06 ?        00:00:00 \/u01\/app\/postgres\/product\/DEV\/db_1\/bin\/postgres -D \/var\/tmp\/pg\npostgres 26412 26379  0 22:35 pts\/0    00:00:00 sh -c ps -ef | grep postgres | grep \"var\/tmp\"\npostgres 26415 26412  0 22:35 pts\/0    00:00:00 grep var\/tmp\npostgres=# ! kill -9 26236\npostgres=# select 1;\nFATAL:  terminating connection due to unexpected postmaster exit\nserver closed the connection unexpectedly\n        This probably means the server terminated abnormally\n        before or while processing the request.\nThe connection to the server was lost. Attempting reset: Failed.\n!?&gt; select 1;\nYou are currently not connected to a database.\n!?&gt; \n<\/pre>\n<p>PostgreSQL will start just fine:<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">\npostgres@centos8pg:\/home\/postgres\/ [pgdev] pg_ctl -D \/var\/tmp\/pg\/ start\npg_ctl: another server might be running; trying to start server anyway\nwaiting for server to start....2020-03-16 22:37:44.903 CET [26431] LOG:  starting PostgreSQL 13devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4), 64-bit\n2020-03-16 22:37:44.903 CET [26431] LOG:  listening on IPv6 address \"::1\", port 8888\n2020-03-16 22:37:44.903 CET [26431] LOG:  listening on IPv4 address \"127.0.0.1\", port 8888\n2020-03-16 22:37:44.906 CET [26431] LOG:  listening on Unix socket \"\/tmp\/.s.PGSQL.8888\"\n2020-03-16 22:37:44.910 CET [26432] LOG:  database system was interrupted; last known up at 2020-03-16 22:31:24 CET\n2020-03-16 22:37:45.172 CET [26432] LOG:  database system was not properly shut down; automatic recovery in progress\n2020-03-16 22:37:45.173 CET [26432] LOG:  redo starts at 0\/15A1EC8\n2020-03-16 22:37:45.174 CET [26432] LOG:  invalid record length at 0\/15B9E88: wanted 24, got 0\n2020-03-16 22:37:45.174 CET [26432] LOG:  redo done at 0\/15B9CD0\n2020-03-16 22:37:45.195 CET [26431] LOG:  database system is ready to accept connections\n done\nserver started\n<\/pre>\n<p>To conclude: I am not sure if I would do this in real life but it seems to work quite well. As long as no persistent objects go into these tablespaces all should be fine. I&#8217;ve asked the mailing list for any experience with this, you can <a href=\"https:\/\/www.postgresql.org\/message-id\/flat\/ZR0P278MB0028A89FAA3E31E7F1514EF6D2F60%40ZR0P278MB0028.CHEP278.PROD.OUTLOOK.COM\" target=\"_blank\" rel=\"noopener noreferrer\">follow that here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The short answer to the title of this blog post is: yes, of course you can. The more important question is: should you? The PostgreSQL documentation about tablespaces contains an explicit warning: &#8220;Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster&#8221;. This is for sure&hellip;&nbsp;<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","neve_meta_reading_time":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[4133],"tags":[],"class_list":["post-13671","post","type-post","status-publish","format-standard","category-database"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Can I put my temporary tablespaces on a RAM disk with PostgreSQL? - dbi services Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?\" \/>\n<meta property=\"og:description\" content=\"The short answer to the title of this blog post is: yes, of course you can. The more important question is: should you? The PostgreSQL documentation about tablespaces contains an explicit warning: &#8220;Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster&#8221;. This is for sure&hellip;&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi services Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dbiservices\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-18T06:20:21+00:00\" \/>\n<meta name=\"author\" content=\"Open source Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:site\" content=\"@dbiservices\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Open source Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/\"},\"author\":{\"name\":\"Open source Team\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0b4548362cac3eeff8b3eaf329e3530a\"},\"headline\":\"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?\",\"datePublished\":\"2020-03-18T06:20:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/\"},\"wordCount\":427,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"articleSection\":[\"Database\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/\",\"name\":\"Can I put my temporary tablespaces on a RAM disk with PostgreSQL? - dbi services Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\"},\"datePublished\":\"2020-03-18T06:20:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/\",\"name\":\"dbi services Blog\",\"description\":\"#BeSharing\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/#organization\",\"name\":\"dbi services\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/dbi-services-logo.png\",\"width\":512,\"height\":512,\"caption\":\"dbi services\"},\"image\":{\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/dbiservices\\\/\",\"https:\\\/\\\/x.com\\\/dbiservices\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/dbi-services\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/dbiservices\"],\"description\":\"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.\",\"email\":\"info@dbi-services.com\",\"telephone\":\"+41 32 422 96 00\",\"legalName\":\"dbi services SA\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/#\\\/schema\\\/person\\\/0b4548362cac3eeff8b3eaf329e3530a\",\"name\":\"Open source Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"contentUrl\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/open-source-author.png\",\"caption\":\"Open source Team\"},\"description\":\"Posts published under the Open source Team account are collective contributions by the dbi services open infrastructure consultants. The practice covers open-source databases and platforms, PostgreSQL first of all, along with MySQL, MariaDB, and Linux, from architecture, replication, and high availability to performance tuning and operations under service level agreements, and contributes actively to the PostgreSQL community.\",\"url\":\"https:\\\/\\\/www.dbi-services.com\\\/blog\\\/author\\\/open-source-team\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL? - dbi services Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/","og_locale":"en_US","og_type":"article","og_title":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?","og_description":"The short answer to the title of this blog post is: yes, of course you can. The more important question is: should you? The PostgreSQL documentation about tablespaces contains an explicit warning: &#8220;Placing a tablespace on a temporary file system like a RAM disk risks the reliability of the entire cluster&#8221;. This is for sure&hellip;&nbsp;","og_url":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/","og_site_name":"dbi services Blog","article_publisher":"https:\/\/www.facebook.com\/dbiservices\/","article_published_time":"2020-03-18T06:20:21+00:00","author":"Open source Team","twitter_card":"summary_large_image","twitter_creator":"@dbiservices","twitter_site":"@dbiservices","twitter_misc":{"Written by":"Open source Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/"},"author":{"name":"Open source Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0b4548362cac3eeff8b3eaf329e3530a"},"headline":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?","datePublished":"2020-03-18T06:20:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/"},"wordCount":427,"commentCount":0,"publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"articleSection":["Database"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/","url":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/","name":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL? - dbi services Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2020-03-18T06:20:21+00:00","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/can-i-put-my-temporary-tablespaces-on-a-ram-disk-with-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Can I put my temporary tablespaces on a RAM disk with PostgreSQL?"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi services Blog","description":"#BeSharing","publisher":{"@id":"https:\/\/www.dbi-services.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.dbi-services.com\/#organization","name":"dbi services","url":"https:\/\/www.dbi-services.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2026\/09\/dbi-services-logo.png","width":512,"height":512,"caption":"dbi services"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/dbiservices\/","https:\/\/x.com\/dbiservices","https:\/\/www.linkedin.com\/company\/dbi-services\/","https:\/\/www.youtube.com\/user\/dbiservices"],"description":"Swiss IT consulting and services company specialized in efficient data infrastructures and platforms: databases, application servers, cloud, DevOps, digitalization, analytics, data quality and monitoring. Headquartered in Del\u00e9mont with offices in Nyon, Basel, Bern and Zurich.","email":"info@dbi-services.com","telephone":"+41 32 422 96 00","legalName":"dbi services SA"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0b4548362cac3eeff8b3eaf329e3530a","name":"Open source Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/2022\/05\/open-source-author.png","caption":"Open source Team"},"description":"Posts published under the Open source Team account are collective contributions by the dbi services open infrastructure consultants. The practice covers open-source databases and platforms, PostgreSQL first of all, along with MySQL, MariaDB, and Linux, from architecture, replication, and high availability to performance tuning and operations under service level agreements, and contributes actively to the PostgreSQL community.","url":"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/13671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=13671"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/13671\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=13671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=13671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=13671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}