Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaaa3dfd

Browse files
committed
Fix bgwriter's failure to release buffer pins and open files after an
error. This probably explains bug #2099 and could also account formysterious VACUUM hangups.
1 parent96e1fbe commitaaa3dfd

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

‎src/backend/postmaster/bgwriter.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.21 2005/10/15 02:49:23 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.22 2005/12/08 19:19:22 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -51,13 +51,15 @@
5151
#include"miscadmin.h"
5252
#include"postmaster/bgwriter.h"
5353
#include"storage/bufmgr.h"
54+
#include"storage/fd.h"
5455
#include"storage/freespace.h"
5556
#include"storage/ipc.h"
5657
#include"storage/pmsignal.h"
5758
#include"storage/smgr.h"
5859
#include"tcop/tcopprot.h"
5960
#include"utils/guc.h"
6061
#include"utils/memutils.h"
62+
#include"utils/resowner.h"
6163

6264

6365
/*----------
@@ -208,6 +210,12 @@ BackgroundWriterMain(void)
208210
*/
209211
last_checkpoint_time=time(NULL);
210212

213+
/*
214+
* Create a resource owner to keep track of our resources (currently
215+
* only buffer pins).
216+
*/
217+
CurrentResourceOwner=ResourceOwnerCreate(NULL,"Background Writer");
218+
211219
/*
212220
* Create a memory context that we will do all our work in. We do this so
213221
* that we can reset the context during error recovery and thereby avoid
@@ -240,11 +248,18 @@ BackgroundWriterMain(void)
240248
/*
241249
* These operations are really just a minimal subset of
242250
* AbortTransaction().We don't have very many resources to worry
243-
* about in bgwriter, but we do have LWLocksandbuffers.
251+
* about in bgwriter, but we do have LWLocks, buffers,andtemp files.
244252
*/
245253
LWLockReleaseAll();
246254
AbortBufferIO();
247255
UnlockBuffers();
256+
/* buffer pins are released here: */
257+
ResourceOwnerRelease(CurrentResourceOwner,
258+
RESOURCE_RELEASE_BEFORE_LOCKS,
259+
false, true);
260+
/* we needn't bother with the other ResourceOwnerRelease phases */
261+
AtEOXact_Buffers(false);
262+
AtEOXact_Files();
248263

249264
/* Warn any waiting backends that the checkpoint failed. */
250265
if (ckpt_active)

‎src/backend/utils/resowner/resowner.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.16 2005/11/22 18:17:27 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/resowner/resowner.c,v 1.17 2005/12/08 19:19:22 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -437,7 +437,7 @@ UnregisterResourceReleaseCallback(ResourceReleaseCallback callback, void *arg)
437437
* of memory, it's critical to do so *before* acquiring the resource.
438438
*
439439
* We allow the case owner == NULL because the bufmgr is sometimes invoked
440-
* outside any transaction (for example,in the bgwriter).
440+
* outside any transaction (for example,during WAL recovery).
441441
*/
442442
void
443443
ResourceOwnerEnlargeBuffers(ResourceOwnerowner)
@@ -470,7 +470,7 @@ ResourceOwnerEnlargeBuffers(ResourceOwner owner)
470470
* Caller must have previously done ResourceOwnerEnlargeBuffers()
471471
*
472472
* We allow the case owner == NULL because the bufmgr is sometimes invoked
473-
* outside any transaction (for example,in the bgwriter).
473+
* outside any transaction (for example,during WAL recovery).
474474
*/
475475
void
476476
ResourceOwnerRememberBuffer(ResourceOwnerowner,Bufferbuffer)
@@ -487,7 +487,7 @@ ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
487487
* Forget that a buffer pin is owned by a ResourceOwner
488488
*
489489
* We allow the case owner == NULL because the bufmgr is sometimes invoked
490-
* outside any transaction (for example,in the bgwriter).
490+
* outside any transaction (for example,during WAL recovery).
491491
*/
492492
void
493493
ResourceOwnerForgetBuffer(ResourceOwnerowner,Bufferbuffer)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp