妇科炎症小腹坠痛吃什么药| 肾阳虚喝什么泡水最好| tdi是什么意思| 铁皮石斛有什么作用| 宝宝吃什么鱼比较好| 低钾是什么原因造成的| 奔头是什么意思| 腋臭是什么原因引起的| 白塞病是什么病| 好是什么意思| a型血的人容易得什么病| 姑姑的儿子叫什么| 大学生当兵有什么好处| 什么菜最好吃| 慢性肠胃炎吃什么药| 走路脚心疼是什么原因| 脚气用什么药膏最好| 嗳是什么意思| 左室舒张功能减低吃什么药| 油性记号笔用什么能擦掉| 属猴男和什么属相最配| 五行属土缺命里缺什么| 断桥铝是什么意思| 三个女人一台戏什么意思| 2000年什么年| 炖牛肉放什么调料好吃| 孩子走路晚是什么原因| 气胸什么症状| 炎性结节是什么意思| 无字五行属什么| 肠息肉是什么| 吃东西就吐是什么原因| 夏季什么时候最热| 与其让你在我怀中枯萎是什么歌| 3.5是什么星座| he是什么气体| 咳嗽有黄痰是什么原因| 脉搏是什么意思| 什么什么多腔| 鬼火是什么| 胃酸是什么酸| 腹泻肚子疼吃什么药| 社保缴费基数什么意思| 为什么生理期过后最容易掉秤| 什么湖什么海| 神经官能症有什么症状表现| 18号来月经什么时候是排卵期| 女生肚脐眼下面疼是什么原因| 生殖疱疹用什么药效果好| 脾虚湿盛吃什么药| 超度是什么意思| 拉屎有泡沫是什么原因| 尿常规隐血弱阳性什么意思| 蒟蒻是什么| 黄鼠狼最怕什么| 低压高什么原因导致的| 柔情似水是什么意思| 为什么射不出来| 掉头发多是什么原因| 到底为什么| 平身是什么意思| 神的国和神的义指的是什么| 小腿酸什么原因| 1.28什么星座| 家里有蚂蚁是什么原因| sids是什么意思| 感情洁癖什么意思| 神经内科看什么病的| 牙结石用什么牙膏最好| 南瓜皮可以吃吗有什么作用| 尿酸盐结晶是什么意思| 什么品牌补水效果好| 皮脂腺囊肿挂什么科| 属牛配什么属相最好| 破涕为笑什么意思| 七嘴八舌是什么生肖| 花痴病是什么症状| 翊什么意思| 吃什么升血压最快| 4月出生是什么星座| cu是什么元素| 什么药治脂肪肝| 10.28什么星座| 史迪仔是什么动物| o2o模式是什么意思| 什么叫裸眼视力| 青字五行属什么| 舌面有裂纹是什么原因| 备孕什么意思| led灯是什么| 禳是什么意思| 白发缺少什么维生素| 胃癌是什么原因引起的| 女性经常手淫有什么危害| 手上的月牙代表什么意思| 一个口一个塞念什么| 古驰属于什么档次| 常规是什么意思| 回阳救逆什么意思| 818是什么星座| 梦见前男友是什么意思| 人为什么要工作| 个人简历籍贯填什么| 12年义务教育什么时候实行| 护照免签是什么意思| 处女座和什么星座最配| 没有润滑油用什么代替| 嗓子不舒服做什么检查| 高密度脂蛋白胆固醇高是什么意思| 十二月二号是什么星座| 准生证需要什么材料| 分泌物多是什么原因| 怀孕两天会有什么反应| 水杨酸是什么| 味极鲜是什么| 梦见自己的衣服丢了是什么意思| 做了胃镜多久可以吃东西吃些什么| 终年是什么意思| 社保缴纳基数是什么意思| ad是什么| 梦到很多蛇是什么意思| 二黑是什么意思| 世界上最小的花是什么花| 黑长直是什么意思| 白羊座是什么性格| 春的五行属性是什么| 自主神经功能紊乱吃什么药| 三朵玫瑰花代表什么意思| 海参不能和什么一起吃| 蛇的天敌是什么动物| 夹页念什么| 什么人容易得类风湿| 血红蛋白偏低是什么意思| 观音菩萨是保佑什么的| 肝肾衰竭有什么症状| 月经三个月没来是什么原因| 消纳是什么意思| 牙疼吃什么食物能缓解| 黄体不足吃什么| 2月9号什么星座| 小孩脚麻是什么原因| 切片是什么| 鸡痘用什么药效果好| 97年是属什么的| 芒硝是什么| 感冒发烧吃什么水果好| 村居是什么意思| 青云志是什么意思| 儒字五行属什么| 背疼挂什么科| 营卫是什么意思| deep是什么意思| 腮腺炎不能吃什么东西| 烧钱是什么意思| 四什么八什么| 耳朵后面疼是什么原因| 黑豆熟地水功效是什么| 宝宝不爱喝水有什么好的办法吗| 马镫什么时候发明的| 92年是什么命| 木瓜是什么味道| 74年属什么生肖| 人参和什么泡酒最好| 耳洞发炎流脓用什么药| 兹禧属什么生肖| 吃什么去湿气最快最有效| 牛蛋是什么| 为什么精液是流出来的| 低烧是什么原因引起的| 大黄是什么药材| 右肩膀和胳膊疼痛是什么原因| 普萘洛尔是什么药| 梦见钱包丢了是什么意思| 时至今日是什么意思| 制片人是做什么的| 花生死苗烂根用什么药| 为什么医者不自医| 睡觉做梦多是什么原因| 盐酸利多卡因注射作用是什么| 肾结石可以喝什么饮料| 鼻子出血吃什么药| 脂肪肝吃什么药最好| 炖汤用什么锅比较好| 补料是什么意思| 女人的胸部长什么样| 目瞪口呆是什么生肖| 什么叫生理盐水| 黄历修造是什么意思| 筋膜炎是什么症状| 教师资格证有什么用| 内热是什么意思| 无赖不还钱最怕什么| 跖疣用什么药膏能治好| 为什么都开头孢不开阿莫西林| 女人为什么会患得患失| 2018年属什么生肖| 把脉能看出什么隐私| 梦见大白菜是什么意思| 鬼迷心窍什么意思| 大大是什么意思| 广东属于什么地区| 芒果有什么营养| 黑苦荞茶有什么功效| 树欲静而风不止是什么意思| 口腔苔藓用什么药| 女性尿酸高有什么症状表现| 糜烂性胃炎吃什么药| 嘴唇发乌是什么原因| 难免流产什么意思| 97年属什么的生肖| 为什么要穿内裤| 月经期间吃什么补气血| 孕中期宫缩是什么感觉| 幽默是什么意思| c02是什么意思| 爬虫什么意思| 什么药治尿酸高最有效| 忌日是什么意思| 劲仔小鱼是什么鱼做的| 夏天的诗句有什么| 什么是刷酸| 圭是什么意思| 铀是什么| 得性病有什么症状| 类风湿阳性是什么意思| 心阴虚吃什么中成药| 查乙肝挂什么科| 急性肠炎吃什么食物好| 什么补血快| 妈妈的妈妈叫什么| 晚上难入睡是什么原因| 一个月大的小狗吃什么| 危险是什么意思| 跑酷是什么运动| 囊性占位是什么意思| 扫把和什么是一套的| 黑科技是什么意思| puma是什么品牌| 小鹿乱撞是什么意思| 嘈杂纳减是什么意思| 肾痛吃什么药| 清白是什么意思| 早上起床眼屎多是什么原因| 大惊小怪是什么生肖| 日光性皮炎用什么药| hmg是什么药| 晚生是什么意思| 衣锦还乡是什么意思| 考护师需要什么条件| 尿检白细胞阳性是什么意思| 脚底脱皮是什么原因| 口了又一是什么字| 什么东西补气血| 抚触是什么意思| 安全期什么时候| 室间隔增厚是什么意思| 景德镇有什么好玩的| 什么是变应性鼻炎| 醋酸生育酚是什么东西| 冒冷汗是什么原因| 口腔疱疹吃什么药| 喝咖啡有什么坏处| 房颤与早搏有什么区别| 随性是什么意思| 百度

Sunday, February 15, 2015

Running with scissors mode

DBAs Running with Scissors

Based on some comments in my post about "in-memory" databases, I realized that my post about running Postgres without disk sync was no longer available on Database Soup.  So I'm reposting the instructions here.

This blog post version has corrections and clarifications thanks to Andres Freund, since it first went up yesterday.  Thanks, Andres.

Running PostgreSQL this way was christened "running with scissors mode" by Gavin Roy, because you're operating completely without crash-safety; if something happens to the server, even a power fluctuation, your database contents are untrustworthy and may be corrupt.  However, it can be a useful way to run Postgres for extra, read-only replicas used strictly for load-balancing, or if what you're loading into Postgres is completely disposable/replaceable.

Note that these settings do not, in fact, disable all disk writes.  What they do instead is minimize disk writes, and make all disk writes asynchronous, dependant entirely on the OS's own memory swapping and dirty block flushing for any disk writes.  This is what you want; you don't want the database to halt because, for example, you simply ran out of space in memory.

So, without further ado, here's the settings:

    work_mem =  (RAM - DBsize - shared_buffers)*2 / max_connections
    temp_buffers = (RAM - DBsize - shared_buffers)*4 / max_connections
    temp_file_limit = 0

On the one hand, we want to set work_mem high in order to avoid on-disk sorts. On the other hand, having pinned RAM for sorts push the database out of memory would be counterproductive.  As such, you want to set up work memory to use available RAM you don't need for database caching.  The above assumes that max_connections is set to something sensible for the number of connections you actually need.  You should really be using pgbouncer as well with this setup.


Set temp_file_limit = 0 to cause queries to be cancelled instead of doing disk sorts.

     bgwriter_lru_maxpages = 0
     wal_level = minimal
     fsync = off
     synchronous_commit = off
     full_page_writes = off

     wal_log_hints = off
     wal_buffers = 64MB


Here we're minimizing the amount of writing we do to the transaction log, and making said writing completely asynchronous.  We're also disabling background writing.

     checkpoint_segments = 8 to 64
   checkpoint_timeout = 60min
     checkpoint_completion_target = 0.9

Checkpoint segments is a bit trickier.  On the one hand, you want it to be large enough that it's not cycling a lot and triggering extra disk flushes. On the other hand, you want all the segments to stay cached in RAM.  So something moderate, 256MB to 2GB, depending on how much RAM you have.  Don't set it to more than 1/32nd of RAM.  Ideally, we'd be able to disable checkpoints entirely, but currently there's no reasonable way to do that.

   stats_temp_directory = '/pgramdisk/stats_tmp'

You will also want to move the stats file to a ramdisk so that it's not being written out.  This is a good optimization in general, even outside of running with scissors mode.


Finally, we need to ensure that PostgreSQL will not restart if the system crashes; at that point, you assume your database is corrupt and proceed to recover it from another source.  The first part of doing this is to disable any autostart in your init system configuration.  Secondly, after starting up Postgres, add a line like this to the beginning of postgresql.conf:

     DO_NOT_RESTART=True

The exact parameter you use doesn't matter; what matters is that it's not a recognized parameter, so that Postgres will error out instead of  restarting.  This does mean extra steps when you want to manually restart this node for configuration changes, but there isn't a really good way around that.

Next up, we'll run some performance tests to see how much this benefits us.

Continued in Part II.

Photo of "DBAs running with scissors" taken by Gavin Roy.

2 comments:

  1. This sounds fun. Can you re-post part II if you have it?

    ReplyDelete
  2. I'd love to see the performance tests results.

    ReplyDelete

nos是什么意思 智齿一般长在什么位置 拉肚子吃什么药最有效 八七年属什么生肖 凤尾菜又叫什么菜
痢疾是什么症状 椎间盘变性是什么意思 脸肿是什么病 为什么说有钱难买孕妇B 5.13是什么星座
mdz0.2是什么药 人为什么会有胎记 阳瘘的最佳治疗方法是什么 抽搐是什么意思 老二是什么意思
扁桃体长什么样子 edd什么意思 章鱼是什么动物 三天没有大便是什么原因 大姨妈量少什么原因
为什么牙齿晚上痛白天不痛hcv9jop8ns3r.cn 怀孕了有什么症状hcv9jop0ns5r.cn ca什么意思hcv7jop9ns3r.cn 锦囊妙计是什么意思sanhestory.com c8是什么意思hcv9jop6ns5r.cn
血小板高是什么原因hcv9jop4ns7r.cn 胸膜牵拉是什么意思zsyouku.com 吃什么东西排酸最快hcv8jop9ns7r.cn g6pd是检查什么的hcv7jop6ns4r.cn dl是什么意思mmeoe.com
股骨头坏死挂什么科hcv8jop7ns8r.cn 女性分泌物像豆腐渣用什么药hcv9jop6ns1r.cn 分差是什么意思sscsqa.com 痛风吃什么食物好hcv8jop2ns0r.cn 腺肌症是什么意思hcv8jop4ns2r.cn
桑黄有什么药用价值hcv9jop5ns0r.cn 大夫古代指什么hcv8jop0ns1r.cn 阴道镜活检是什么意思wuhaiwuya.com 什么是不饱和脂肪酸hcv8jop6ns2r.cn 林俊杰为什么不结婚gangsutong.com
百度