1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Use "transient" files for blind writes

"Blind writes" are a mechanism to push buffers down to disk when
evicting them; since they may belong to different databases than the one
a backend is connected to, the backend does not necessarily have a
relation to link them to, and thus no way to blow them away.  We were
keeping those files open indefinitely, which would cause a problem if
the underlying table was deleted, because the operating system would not
be able to reclaim the disk space used by those files.

To fix, have bufmgr mark such files as transient to smgr; the lower
layer is allowed to close the file descriptor when the current
transaction ends.  We must be careful to have any other access of the
file to remove the transient markings, to prevent unnecessary expensive
system calls when evicting buffers belonging to our own database (which
files we're likely to require again soon.)
This commit is contained in:
Alvaro Herrera
2011-06-09 13:41:12 -04:00
parent 74b1d29dd1
commit 54d9e8c6c1
6 changed files with 119 additions and 28 deletions

View File

@ -1834,7 +1834,10 @@ BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum,
* written.)
*
* If the caller has an smgr reference for the buffer's relation, pass it
* as the second parameter. If not, pass NULL.
* as the second parameter. If not, pass NULL. In the latter case, the
* relation will be marked as "transient" so that the corresponding
* kernel-level file descriptors are closed when the current transaction ends,
* if any.
*/
static void
FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
@ -1856,9 +1859,12 @@ FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln)
errcontext.previous = error_context_stack;
error_context_stack = &errcontext;
/* Find smgr relation for buffer */
/* Find smgr relation for buffer, and mark it as transient */
if (reln == NULL)
{
reln = smgropen(buf->tag.rnode, InvalidBackendId);
smgrsettransient(reln);
}
TRACE_POSTGRESQL_BUFFER_FLUSH_START(buf->tag.forkNum,
buf->tag.blockNum,