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=# 

 

posted @ 2013-08-02 09:57  健哥的数据花园  阅读(745)  评论(0编辑  收藏  举报