fsync体会

看这个链接:http://www.postgresql.org/docs/9.1/static/runtime-config-wal.html

是这样说的:

fsync (boolean)
If this parameter is on, the PostgreSQL server will try to make sure that updates are physically written to disk, by issuing fsync() system calls or various equivalent methods (see wal_sync_method). This ensures that the database cluster can recover to a consistent state after an operating system or hardware crash.

While turning off fsync is often a performance benefit, this can result in unrecoverable data corruption in the event of a power failure or system crash. Thus it is only advisable to turn off fsync if you can easily recreate your entire database from external data.

Examples of safe circumstances for turning off fsync include the initial loading of a new database cluster from a backup file, using a database cluster for processing a batch of data after which the database will be thrown away and recreated, or for a read-only database clone which gets recreated frequently and is not used for failover. High quality hardware alone is not a sufficient justification for turning off fsync.

In many situations, turning off synchronous_commit for noncritical transactions can provide much of the potential performance benefit of turning off fsync, without the attendant risks of data corruption.

fsync can only be set in the postgresql.conf file or on the server command line. If you turn this parameter off, also consider turning off full_page_writes.

我的实验:

把 postgresql.conf 中的 fsync 设置为off之后,再来看sql执行动作:

pgsql=# select * from test;
 textcol | intcol 
---------+--------
 a       |      1
 a       |      2
 b       |      5
 b       |      6
(4 rows)

pgsql=# 
pgsql=# show fsync;
 fsync 
-------
 off
(1 row)

pgsql=# 

执行操作:

begin;
insert into test values('aaaaa',12345);
commit;

然后直接关机,使得OS级别的缓存没有机会写入磁盘。

再次开机看数据,发现上述数据没有保存:

pgsql=# select * from test;
 textcol | intcol 
---------+--------
 a       |      1
 a       |      2
 b       |      5
 b       |      6
(4 rows)

pgsql=# 

 

转载于:https://www.cnblogs.com/gaojian/p/3230635.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值