1、PolarDB-PG 企业级特性Global Cache吴辉静(花名:午光)阿里云PolarDB数据库技术专家PostgreSQL 的 CacheCatalogBuffer PoolBackend ProcessRelCachePlanCacheSys/CatCachePostmaster ProcessWalsender ProcessParallel WorkerAutoVacuum ProcessData CacheBuffer Pool共享内存Meta CacheRelCache,Sys/CatCache,Plan Cache,Type Cache 等进程私有内存PostgreSQL
2、的 Data Cache:Buffer PoolKey:BufferTag容量管理:预分配所有进程共享Shared Memory ManagementHuge PageBuffer ManagerDatabase ClusterShared Buffer PoolBackend ProcessBackend ProcessBackend ProcessPostgreSQL 的 Data Cache:Buffer Pool并发控制buffer table lock,buffer descriptor lockpin/unpin淘汰算法Clock SweepRing Buffer刷脏Postgre
3、SQL 的 Meta Cache:Sys/CatCache用于快速查询系统表里的某个字段本质上缓存的是系统表里的 Tuple绝大多数模块都会使用,访问频率非常高SysCache 基于 CatCache 构建进程私有,无淘汰基于 SINVAL 机制失效内存管理使用 Memory Context,可观测性不强CatCacheSysCachepg_classParserOptimizerExecutorpg_typepg_attributeCatalogPostgreSQL 的 Meta Cache:RelCacheRelCache 中缓存了和表相关的所有元数据,加载多个系统表的数据组成了一个庞杂的
4、结构体绝大多数模块都会使用,访问比较高频进程私有,无淘汰基于 SINVAL 机制失效内存管理使用 Memory Context,可观测性不强RelCachetable1ParserOptimizerExecutortable2view1Catalogpg_classpg_indexpg_attributePostgreSQL 的 Meta Cache 失效机制:SINVALSINVAL 支持所有的 Cache 和 Catalog Snapshot 的失效事务提交时广播 SINVAL message随时检查 SINVAL QueueSINVAL Queue 如果溢出,通知所有 Process 执
5、行 Flush CacheSharedSINVALQueueProcess1(DDL)beginalter tablecommitLocal Queue语句结束执行 Local Queue 中的 sinval msgpushsinval msgpushsinval msgProcess2(DML)beginselectcommitacceptsinval msgacceptsinval msgPostgreSQL 的 Meta Cache 总结SINVAL 机制保证正确性进程私有大量冗余副本,OOM内存管理基于 Memory Context可观测性问题强生命周期管理&长连接只加载不淘汰Back
6、end ProcessBackend ProcessShared MemoryBuffer PoolCatalogGlibcMemory ContextSys/CatCacheRelCacheSINVALPolarDB-PG 的 Global Cache 架构Global Cache(L2)CatalogShared Memory ManagerSys/CatCacheRelationCachePlanCacheGeneric Global Cache LayerGlobal Cache Component ManagerGlobal CacheInva