[GENERAL] Why SyncOneBuffer does not called frequently?

2012-10-31 Thread 高健
Hi all:

I am trying to understand when the bgwriter is written.

I thought that the  bgwriter.c's calling turn is:

BackgroundWriterMain -BgBufferSync- SyncOneBuffer

And In my postgresql.conf , the bgwriter_delay=200ms.

I did the following:

postgres=# select * from testtab;
 id |  val
+---
  1 | 12345
(1 row)

postgres=# update testtab set val='54321' where id=1;
UPDATE 1
postgres=# select * from testtab;
 id |  val
+---
  1 | 54321
(1 row)

postgres=#

Now I can say the buffer is dirty ,right?

I wait for a few minutes, I can found bgwriter's BackgroundWriterMain
called BgBufferSync many times.

But I can't find BgBufferSync really call SyncOneBuffer to put the dirty
data todisk.

Untill I close the postgres process, I can find the SyncOneBuffer is called
for many times.

My question is:
Why even there are dirty buffer(s), the SyncOneBuffer is still not called?
Is it violating the background writer's purpose?

Or the flushing to disk will be done untill  the amount of block/buffer is
satisfied? If so , what is it?

Thanks in advance for any help


Re: [GENERAL] Why SyncOneBuffer does not called frequently?

2012-10-31 Thread Jeff Janes
On Wed, Oct 31, 2012 at 1:53 AM, 高健 luckyjack...@gmail.com wrote:
 Hi all:

 I am trying to understand when the bgwriter is written.

 I thought that the  bgwriter.c's calling turn is:

 BackgroundWriterMain -BgBufferSync- SyncOneBuffer

SyncOneBuffer is called with skip_recently_used true, so the buffer
will not get written by the background writer if it is was recently
used.


 And In my postgresql.conf , the bgwriter_delay=200ms.

 I did the following:

 postgres=# select * from testtab;
  id |  val
 +---
   1 | 12345
 (1 row)

 postgres=# update testtab set val='54321' where id=1;
 UPDATE 1
 postgres=# select * from testtab;
  id |  val
 +---
   1 | 54321
 (1 row)

 postgres=#

 Now I can say the buffer is dirty ,right?

It is dirty, but it also has a positive usagecount.

Are you sure it is that SyncOneBuffer is not getting called, rather
than it is getting called but returning before doing the write?

Cheers,

Jeff


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Why SyncOneBuffer does not called frequently?

2012-10-31 Thread Xiong He
HI, 

I just debug the code, find that the following stack will call the 
SyncOneBuffer.

postgres.exe!SyncOneBuffer(int buf_id=2, char skip_recently_used=0)  Line 
 1640C
 postgres.exe!BufferSync(int flags=64)  Line 1284 + 0xb bytesC
 postgres.exe!CheckPointBuffers(int flags=64)  Line 1801 + 0x9 bytesC
 postgres.exe!CheckPointGuts(XLogRecPtr checkPointRedo={...}, int flags=64) 
 Line 8129 + 0x9 bytesC
 postgres.exe!CreateCheckPoint(int flags=64)  Line 7977 + 0x11 bytesC
 postgres.exe!CheckpointerMain()  Line 505 + 0x9 bytesC
 postgres.exe!AuxiliaryProcessMain(int argc=2, char * * argv=0x002f6fb8)  
Line 429C
 postgres.exe!SubPostmasterMain(int argc=4, char * * argv=0x002f6fb0)  Line 
4136 + 0x13 bytesC
 postgres.exe!main(int argc=4, char * * argv=0x002f6fb0)  Line 176 + 0xd 
bytesC
 postgres.exe!__tmainCRTStartup()  Line 582 + 0x19 bytesC
 postgres.exe!mainCRTStartup()  Line 399C

This is the check point background process.



--
ThanksRegards,
Xiong He





 




-- Original --
From:  luckyjack...@gmail.com;
Date:  Wed, Oct 31, 2012 04:53 PM
To:  pgsql-generalpgsql-general@postgresql.org; 

Subject:  [GENERAL] Why SyncOneBuffer does not called frequently?



Hi all:


I am trying to understand when the bgwriter is written.


I thought that the  bgwriter.c's calling turn is:


BackgroundWriterMain -BgBufferSync- SyncOneBuffer
 

And In my postgresql.conf , the bgwriter_delay=200ms.


I did the following:


postgres=# select * from testtab;
 id |  val  
+---
   1 | 12345
(1 row)


postgres=# update testtab set val='54321' where id=1;
UPDATE 1
postgres=# select * from testtab;
 id |  val  
+---
   1 | 54321
(1 row)


postgres=# 


Now I can say the buffer is dirty ,right?


I wait for a few minutes, I can found bgwriter's BackgroundWriterMain called 
BgBufferSync many times.
 

But I can't find BgBufferSync really call SyncOneBuffer to put the dirty data 
todisk.


Untill I close the postgres process, I can find the SyncOneBuffer is called for 
many times.
 

My question is: 
Why even there are dirty buffer(s), the SyncOneBuffer is still not called?  
Is it violating the background writer's purpose? 


Or the flushing to disk will be done untill  the amount of block/buffer is 
satisfied? If so , what is it?
 

Thanks in advance for any help

Re: [GENERAL] Why SyncOneBuffer does not called frequently?

2012-10-31 Thread Xiong He
This perhaps proves that the bgwriter doesn't need to call the SyncOneBuffer again on the same buffer.--ThanksRegards,Xiong He--Original--From: "Xiong He"iih...@qq.com;Date: Thu, Nov 1, 2012 07:40 AMTo: "高健"luckyjack...@gmail.com; "pgsql-general"pgsql-general@postgresql.org; Subject: Re: [GENERAL] Why SyncOneBuffer does not called frequently?HI, I just debug the code, find that the following stack will call the SyncOneBuffer.  postgres.exe!SyncOneBuffer(int buf_id=2, char skip_recently_used=0) Line 1640  C  postgres.exe!BufferSync(int flags=64) Line 1284 + 0xb bytes  C  postgres.exe!CheckPointBuffers(int flags=64) Line 1801 + 0x9 bytes  C  postgres.exe!CheckPointGuts(XLogRecPtr checkPointRedo={...}, int flags=64) Line 8129 + 0x9 bytes  C  postgres.exe!CreateCheckPoint(int flags=64) Line 7977 + 0x11 bytes  C  postgres.exe!CheckpointerMain() Line 505 + 0x9 bytes  C  postgres.exe!AuxiliaryProcessMain(int argc=2, char * * argv=0x002f6fb8) Line 429  C  postgres.exe!SubPostmasterMain(int argc=4, char * * argv=0x002f6fb0) Line 4136 + 0x13 bytes  C  postgres.exe!main(int argc=4, char * * argv=0x002f6fb0) Line 176 + 0xd bytes  C  postgres.exe!__tmainCRTStartup() Line 582 + 0x19 bytes  C  postgres.exe!mainCRTStartup() Line 399  CThis is the check point background process.--ThanksRegards,Xiong He-- Original --From: "高健"luckyjack...@gmail.com;Date: Wed, Oct 31, 2012 04:53 PMTo: "pgsql-general"pgsql-general@postgresql.org; Subject: [GENERAL] Why SyncOneBuffer does not called frequently?Hi all:I am trying to understand when the bgwriter is written.I thought that the bgwriter.c's calling turn is:BackgroundWriterMain -BgBufferSync- SyncOneBuffer
And In my postgresql.conf , the bgwriter_delay=200ms.I did the following:postgres=# select * from testtab;id | val +---
 1 | 12345(1 row)postgres=# update testtab set val='54321' where id=1;UPDATE 1postgres=# select * from testtab;id | val +---
 1 | 54321(1 row)postgres=# Now I can say the buffer is dirty ,right?I wait for a few minutes, I can found bgwriter's BackgroundWriterMain called BgBufferSync many times.
But I can't find BgBufferSync really call SyncOneBuffer to put the dirty data todisk.Untill I close the postgres process, I can find the SyncOneBuffer is called for many times.
My question is: Why even there are dirty buffer(s), the SyncOneBuffer is still not called? Is it violating the background writer's purpose? Or the flushing to disk will be done untill the amount of block/buffer is satisfied? If so , what is it?
Thanks in advance for any help