对bufmgr.c 继续研究

简介:

开始

首先log 相关的内容如下:

复制代码
#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------

# - Where to Log -

log_destination = 'csvlog'        # Valid values are combinations of
                    # stderr, csvlog, syslog, and eventlog,
                    # depending on platform.  csvlog
                    # requires logging_collector to be on.

# This is used when logging to stderr:
logging_collector = on        # Enable capturing of stderr and csvlog
                    # into log files. Required to be on for
                    # csvlogs.
                    # (change requires restart)

# These are only used if logging_collector is on:
log_directory = 'pg_log'        # directory where log files are written,
                    # can be absolute or relative to PGDATA
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'    # log file name pattern,
                    # can include strftime() escapes
log_file_mode = 0600            # creation mode for log files,
                    # begin with 0 to use octal notation
log_truncate_on_rotation = off        # If on, an existing log file with the
                    # same name as the new log file will be
                    # truncated rather than appended to.
                    # But such truncation only occurs on
                    # time-driven rotation, not on restarts
                    # or size-driven rotation.  Default is
                    # off, meaning append to existing files
                    # in all cases.
log_rotation_age = 1d            # Automatic rotation of logfiles will
                    # happen after that time.  0 disables.
log_rotation_size = 10MB        # Automatic rotation of logfiles will
                    # happen after that much log output.
                    # 0 disables.

# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'

# This is only relevant when logging to eventlog (win32):
#event_source = 'PostgreSQL'

# - When to Log -

#client_min_messages = notice        # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   log
                    #   notice
                    #   warning
                    #   error

log_min_messages = info        # values in order of decreasing detail:
                    #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                    #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic

log_min_error_statement = info    # values in order of decreasing detail:
                     #   debug5
                    #   debug4
                    #   debug3
                    #   debug2
                    #   debug1
                     #   info
                    #   notice
                    #   warning
                    #   error
                    #   log
                    #   fatal
                    #   panic (effectively off)

#log_min_duration_statement = -1    # -1 is disabled, 0 logs all statements
                    # and their durations, > 0 logs only
                    # statements running at least this number
                    # of milliseconds


# - What to Log -

#debug_print_parse = off
#debug_print_rewritten = off
#debug_print_plan = off
#debug_pretty_print = on
#log_checkpoints = off
#log_connections = off
#log_disconnections = off
#log_duration = off
#log_error_verbosity = default        # terse, default, or verbose messages
#log_hostname = off
#log_line_prefix = '%m'            # special values:
                    #   %a = application name
                    #   %u = user name
                    #   %d = database name
                    #   %r = remote host and port
                    #   %h = remote host
                    #   %p = process ID
                    #   %t = timestamp without milliseconds
                    #   %m = timestamp with milliseconds
                    #   %i = command tag
                    #   %e = SQL state
                    #   %c = session ID
                    #   %l = session line number
                    #   %s = session start timestamp
                    #   %v = virtual transaction ID
                    #   %x = transaction ID (0 if none)
                    #   %q = stop here in non-session
                    #        processes
                    #   %% = '%'
                    # e.g. '<%u%%%d> '
#log_lock_waits = off            # log lock waits >= deadlock_timeout
#log_statement = 'none'            # none, ddl, mod, all
#log_temp_files = -1            # log temporary files equal or larger
                    # than the specified size in kilobytes;
                    # -1 disables, 0 logs all temp files
log_timezone = 'PRC'
复制代码

为了了解 bufmgr 中对 BgBufferSync 的运作原理,对其进行 log 处理:

复制代码
static void                                                
BufferSync(int flags)                                                
{                                                
    ……                                            
    while (num_to_scan-- > 0)                                            
    {                                            
        volatile BufferDesc *bufHdr = &BufferDescriptors[buf_id];                                        
        ……                                        
        if (bufHdr->flags & BM_CHECKPOINT_NEEDED)                                        
        {                                        
                                                
                                //added by gaojian                                        
                                elog(LOG,"In BufferSync, Calling SyncOneBuffer for all dirty\n");                                        
                                                
            if (SyncOneBuffer(buf_id, false) & BUF_WRITTEN)                                    
            {                                    
                TRACE_POSTGRESQL_BUFFER_SYNC_WRITTEN(buf_id);                                
                BgWriterStats.m_buf_written_checkpoints++;                                
                num_written++;                                
                ……                                
                if (num_written >= num_to_write)                                
                    break;                            
                                                
                /*                                
                 * Sleep to throttle our I/O rate.                                
                 */                                
                CheckpointWriteDelay(flags, (double) num_written / num_to_write);                                
            }                                    
                                                
        }                                        
                                                
        if (++buf_id >= NBuffers)                                        
            buf_id = 0;                                    
    }                                            
    ……                                            
}                                                
                                                
bool                                                
BgBufferSync(void)                                                
{                                                
    ……                                            
    if (saved_info_valid)                                            
    {                                            
                                                
                    //added by gaojian                                            
                    elog(LOG,"strategy_passes is:%u  ",strategy_passes);                                            
                    elog(LOG,"....next_passes is:%u  \n",next_passes);                                            
                                                
                                                
        int32        passes_delta = strategy_passes - prev_strategy_passes;                                
                                                
        strategy_delta = strategy_buf_id - prev_strategy_buf_id;                                        
        strategy_delta += (long) passes_delta *NBuffers;                                        
                                                
        Assert(strategy_delta >= 0);                                        
                                                
        ……                                        
                                                
    }                                            
    else                                            
    {                                            
        ……                                        
    }                                            
                                                
    //added by gaojian                                            
    elog(LOG,"bgwriter ahead:bgw %u-%u strategy %u-%u delta=%ld lap=%d\n",next_passes, next_to_clean,strategy_passes, strategy_buf_id,strategy_delta, bufs_to_lap);                                            
    ……                                            
    /* Execute the LRU scan */                                            
    while (num_to_scan > 0 && reusable_buffers < upcoming_alloc_est)                                            
    {                                            
                          //added by gaojian                                            
                         elog(LOG,"In BgBufferSync,Calling SyncOneBuffer.\n");                                            
                                                
        int    buffer_state = SyncOneBuffer(next_to_clean, true);                                    
                                                
        if (++next_to_clean >= NBuffers)                                        
        {                                        
            next_to_clean = 0;                                    
                                                
                             elog(INFO,"------------------next_passes++.\n");                                        
            next_passes++;                                    
        }                                        
        ……                                        
    }                                            
    ……                                            
}                                                
复制代码

 

运行后的 log 是如下的样子,我只选取了一小段,可以发现,SyncOneBuffer是被频繁调用的:

复制代码
2012-11-01 15:56:46.061 CST,,,2987,,50922b3e.bab,1,,2012-11-01 15:56:46 CST,,0,LOG,00000,"database system was shut down at 2012-11-01 14:39:25 CST",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,1,,2012-11-01 15:56:46 CST,,0,LOG,00000,"bgwriter ahead:bgw 0-0 strategy 0-0 delta=0 lap=4096
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,2,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,3,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,4,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,5,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,6,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.146 CST,,,2989,,50922b3e.bad,7,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.147 CST,,,2991,,50922b3e.baf,1,,2012-11-01 15:56:46 CST,,0,LOG,00000,"autovacuum launcher started",,,,,,,,,""
2012-11-01 15:56:46.148 CST,,,2985,,50922b3d.ba9,1,,2012-11-01 15:56:45 CST,,0,LOG,00000,"database system is ready to accept connections",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,8,,2012-11-01 15:56:46 CST,,0,LOG,00000,"strategy_passes is:0  ",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,9,,2012-11-01 15:56:46 CST,,0,LOG,00000,"....next_passes is:0  
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,10,,2012-11-01 15:56:46 CST,,0,LOG,00000,"bgwriter ahead:bgw 0-6 strategy 0-0 delta=0 lap=4090
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,11,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,12,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,13,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,14,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,15,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.346 CST,,,2989,,50922b3e.bad,16,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,17,,2012-11-01 15:56:46 CST,,0,LOG,00000,"strategy_passes is:0  ",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,18,,2012-11-01 15:56:46 CST,,0,LOG,00000,"....next_passes is:0  
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,19,,2012-11-01 15:56:46 CST,,0,LOG,00000,"bgwriter ahead:bgw 0-12 strategy 0-0 delta=0 lap=4084
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,20,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,21,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,22,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,23,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,24,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.546 CST,,,2989,,50922b3e.bad,25,,2012-11-01 15:56:46 CST,,0,LOG,00000,"In BgBufferSync,Calling SyncOneBuffer.
",,,,,,,,,""
2012-11-01 15:56:46.746 CST,,,2989,,50922b3e.bad,26,,2012-11-01 15:56:46 CST,,0,LOG,00000,"strategy_passes is:0  ",,,,,,,,,""
2012-11-01 15:56:46.746 CST,,,2989,,50922b3e.bad,27,,2012-11-01 15:56:46 CST,,0,LOG,00000,"....next_passes is:0  
",,,,,,,,,""
2012-11-01 15:56:46.746 CST,,,2989,,50922b3e.bad,28,,2012-11-01 15:56:46 CST,,0,LOG,00000,"bgwriter ahead:bgw 0-18 strategy 0-0 delta=0 lap=4078
复制代码

这里需要明确的是:BgBufferSync 与 BufferSync 是两回事。

BufferSync 被 checkpoint 所调用。 BgBufferSync 被 bgwriter 所调用。它们被调用的频率是不一样的。

BgBufferSync 和 BufferSync 都需要调用 SyncOneBuffer。 

结束







本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/11/01/2749662.html,如需转载请自行联系原作者

目录
相关文章
|
23天前
|
安全 数据库连接 Linux
深入探索研究FileRun
【10月更文挑战第9天】
40 1
|
6月前
|
人工智能 UED
清华大学研究提出用大模型做心理测量
【2月更文挑战第24天】清华大学研究提出用大模型做心理测量
240 2
清华大学研究提出用大模型做心理测量
|
机器学习/深度学习 算法 数据可视化
上海交大团队使用联合深度学习优化代谢组学研究
上海交大团队使用联合深度学习优化代谢组学研究
217 0
|
JSON 监控 安全
idor相关研究
前言 本文主要阐述了挖掘IDOR的主要流程,以及挖掘的一般性思路(主要从六个角度展开),更多的还要靠读者去实践。
206 0
idor相关研究
|
SQL 存储 Go
AutoAudit研究学习
AutoAudit介绍   AutoAudit这个是Paul Nielsen写的一个开源的审计跟踪的脚本项目,项目位于https://autoaudit.codeplex.com/上,Paul Nielsen的一篇博客CodeGen to Create Fixed Audit Trail Triggers上也介绍了他创建这个项目的前因后果。
1312 0
神经影像学靶点研究取得进展
中国科学院自动化研究所面向脑科学与信息科学交叉前沿,发现了一组通用的多模态磁共振影像学靶点, 可实现精神分裂症多种认知能力的个体化预测,并成功在多中心验证推广,深入揭示了精神分裂症认知损伤所影响的多模态交互环路,为建立基于客观标记物的个体化治疗系统奠定基础。  
1566 0
自抗凝透析器研究取得系列进展
刘富研究员团队在膜微孔结构调控、膜表面抗凝分子修饰、自抗凝透析器方面取得系列进展,实现无肝素透析是血液透析发展趋势,为慢性肾病患者送来福音。
1768 0
下一篇
无影云桌面