summaryrefslogtreecommitdiff
path: root/src/include/storage/smgr.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-17 12:38:21 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-17 12:38:21 -0400
commitff3f9c8de5846be7709b7a87654631b4c309a68b (patch)
treebe3fc090819bb4878b2336744eac15d1372f0d5c /src/include/storage/smgr.h
parent9bacf0e3734f0b5dc821abf7cb312377876e22d3 (diff)
downloadpostgresql-ff3f9c8de5846be7709b7a87654631b4c309a68b.tar.gz
Close un-owned SMgrRelations at transaction end.
If an SMgrRelation is not "owned" by a relcache entry, don't allow it to live past transaction end. This design allows the same SMgrRelation to be used for blind writes of multiple blocks during a transaction, but ensures that we don't hold onto such an SMgrRelation indefinitely. Because an SMgrRelation typically corresponds to open file descriptors at the fd.c level, leaving it open when there's no corresponding relcache entry can mean that we prevent the kernel from reclaiming deleted disk space. (While CacheInvalidateSmgr messages usually fix that, there are cases where they're not issued, such as DROP DATABASE. We might want to add some more sinval messaging for that, but I'd be inclined to keep this type of logic anyway, since allowing VFDs to accumulate indefinitely for blind-written relations doesn't seem like a good idea.) This code replaces a previous attempt towards the same goal that proved to be unreliable. Back-patch to 9.1 where the previous patch was added.
Diffstat (limited to 'src/include/storage/smgr.h')
-rw-r--r--src/include/storage/smgr.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index 92b9198d54..9eccf7671e 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -33,6 +33,9 @@
* without having to make the smgr explicitly aware of relcache. There
* can't be more than one "owner" pointer per SMgrRelation, but that's
* all we need.
+ *
+ * SMgrRelations that do not have an "owner" are considered to be transient,
+ * and are deleted at end of transaction.
*/
typedef struct SMgrRelationData
{
@@ -63,6 +66,9 @@ typedef struct SMgrRelationData
/* for md.c; NULL for forks that are not open */
struct _MdfdVec *md_fd[MAX_FORKNUM + 1];
+
+ /* if unowned, list link in list of all unowned SMgrRelations */
+ struct SMgrRelationData *next_unowned_reln;
} SMgrRelationData;
typedef SMgrRelationData *SMgrRelation;
@@ -95,6 +101,7 @@ extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
extern void smgrpreckpt(void);
extern void smgrsync(void);
extern void smgrpostckpt(void);
+extern void AtEOXact_SMgr(void);
/* internals: move me elsewhere -- ay 7/94 */