Вы находитесь на странице: 1из 4

PostgreSQL

PITR (Point-in-time
recovery)
1.
1)
2)
3) RAID- (
)
4)
C
SCSI - SYNCHRONIZE CACHE
ATAPI-6 - FLUSH CACHE EXT
(zfs,ext4)
UFS2 SU
,
sysctl hw.ata.wc 0
# atacontrol cap ad4
Protocol
SATA revision 2.x
device model
ST3500630AS
serial number
9QG6LEWZ
firmware revision 3.AAD
cylinders
16383
heads
16
sectors/track
63
lba supported
268435455 sectors
lba48 supported
976773168 sectors
dma supported
ooverlap not supported
Feature
Support Enable Value
Vendor
write cache
yes yes
read ahead
yes yes
Native Command Queuing (NCQ) yes
31/0x1F
Tagged Command Queuing (TCQ) no
no
31/0x1F
SMART
yes yes
microcode download
yes
yes
security
yes
no
power management
yes
yes
advanced power management no no
65278/0xFEFE
automatic acoustic management no no
0/0x00 208/0xD0
1.1 :
1) fsync

2) wal_sync_method
WAL-

1. open_datasync ( WAL-
(open())
O_DSYNC )
2. fdatasync ( fdatasync()
)
3. fsync_writethrough (
fsync() ,

)
4. fsync ( fsync()
)
5. open_sync (WAL-
(open())
O_SYNC )
2.
WAL-

1)
.
2)


3)

(
)
4)



3.
1)
COMMIT

WAL- (
, , DROP TABLE)
2)

synchronous_commit
.
3)

wal_writer_delay*3 (
wal writer
wal_writer_delay ,

(8K))
4)
fsync=off
(

).
5)
commit_delay
, fsync

(10 ^-6 )
4. (checkpoints)
- ,

WAL-.
.
3)

1) WAL-
(


2) template1).

4)

( global/pg_control)
(,
3) checkpoint' ).
5)

(
- .

6)

).

4) checkpoint'
WAL- -
(
.
checkpoint_warning
) 6.1 WAL.

4.1
1) archive_mode on.

writer

2) archive_command.
checkpoint'
(
,
checkpoint_segments ( archive_command='cp -i %p
- 16 ) /var/backups/postgresql/wal/%f </dev/null'
checkpoint_timeout ( - 5 %p - , %f )). .
, //
). pgsql
full_page_writes 3) archive_timeout ( ) , ,
.
WAL- (
).
5. WAL-
,
1)
pg_xlog/ WAL- checkpoint.
2)
,
- .
000000010000000000000001
4) wal_level: archive
3)
16
hot_standby. minimum WAL4)

(2 + checkpoint_completion_target) *
.
checkpoint_segments + 1
checkpoint_segments + wal_keep_segments + 6.2
1
1)
WAL5)
pg_xlog/
//RAID10
2)
SELECT pg_start_backup('label');
6)
log-
checkpoint'
pg_switch_xlog().
3)
(, tar
cp). pg_xlog
6. Point in time recovery
.
1)
(REDO) 4)
SELECT pg_stop_backup();
WAL-
/*
checkpoint'

2)

, () 0000000100001234000055CD.007C9330.backup

, .
WAL-,

. */

recovery_target_timeline = 'latest' -

7. WAL
pgtest# vi /pgdata/postgresql.conf
/* : */
wal_level = archive
archive_mode = on
archive_command = '/bin/cp -i %p
/var/backups/postgresql/wal/%f < /dev/null'
archive_timeout = 600

6.3
1) .
2)
.
3)
.
4)
.
5) pg_xlog
pgtest# /usr/local/etc/rc.d/postgresql restart
6) WAL-,
pg_xlog
template1=# select now();
7) recovery.conf.
now

----------------------------- pg_hba.conf.
2010-11-13 16:41:52.55941+03
8) .
(1 row)
recovery.conf
template1=# SELECT pg_start_backup('2010-11 recovery.done
13 16:41');
.
9)
pgtest# su - pgsql
pg_hba.conf
$ tar -cjvf /var/backups/postgresql/base-2010-1113\ 16:41 -C /pgdata .
6.4

(timeline)
template1=# SELECT pg_stop_backup();
1.09.10 -
3.09.10 - .
// . ...
2.09.10
4.09.10 - , 3 alp=> create table my_new_table as select * from
. pg_class;
"" (
).
/*, wal- */
template1=# SELECT pg_switch_xlog();
6.5 recovery.conf
/* /* */
/usr/local/share/postgresql/recovery.conf */
pgtest# rm -fr /pgdata/*
restore_command = 'cp /mnt/server/archivedir/ pgtest# pkill postgres
%f "%p"'
archive_cleanup_command - ,
/* :
restore point
*/
wal-
pgtest# tar -C /pgdata -xjvf
recovery_end_command - ,
/var/backups/postgresql/base-2010-11-13\ 16:41

pgtest# rm -fr /pgdata/pg_xlog/*
recovery_target_time -
pgtest# chown -R pgsql /pgdata

recovery_target_xid -
/* */

pgtest# vi /pgdata/pg_hba.conf
recovery_target_inclusive = 'true' -

/* recovery.conf */
pgtest# cp
/usr/local/share/postgresql/recovery.conf.sample
/pgdata/recovery.conf
pgtest# chown pgsql:pgsql /pgdata/recovery.conf
pgtest# vi /pgdata/recovery.conf
/* */
restore_command='/bin/cp
/var/backups/postgresql/wal/%f "%p"'
/* */
pgtest# /usr/local/etc/rc.d/postgresql start
/* , */
pgtest# ls /pgdata/recovery.*
/pgdata/recovery.done
pgtest# su pgsql -c 'psql -d alp'
alp=# select * from my_new_table;
/*
*
/* - */
pgtest# cat
/var/backups/postgresql/wal/00000002.history
1
000000010000000000000004
no
recovery target specified
/* */
pgtest# vi /pgdata/pg_hba.conf
pgtest# /usr/local/etc/rc.d/postgresql reload

Вам также может понравиться