PostgreSQL 9.5归档

PgArch预写日志归档进程

       PostgreSQL从8.x版本开始提出了PITR(Point-In-Time_recovery)技术,支持将数据库恢复到其运行历史中任意一个有记录的时间点。除WalWrite外,PITR的另一个重要的基础就是对WAL文件的归档功能。PgArch辅助进程的目标就是对WAL日志在磁盘上的存储形式(Xlog文件)进行归档备份。

       PostgreSQL在数据库集簇的pg_xlog子目录中始终只使用一个WAL日志文件,这个日志文件记录数据库中数据文件的每个改变。从逻辑上来看,PostgreSQL数据库会产生一个无限长的顺序的WAL记录序列。PostgreSQL在物理上把这个WAL记录序列分割成多个WAL文件(每个WAL文件为一个WAL段),通常每个段的大小为16MB(在编译PostgreSQL时可以通过编译选项改变这个大小)。每个段文件的名字是一个数字,用来反映它们在WAL序列中的位置。即使不进行WAL归档,PostgreSQL也会创建一些WAL段文件,但是只会使用其中一个来记录WAL日志,如果当前使用的WAL段文件超过了大小限制,则会关闭当前段文件,然后把另外一个可重复使用的段文件作为当前段文件来使用。能够被重复使用的段文件必须保证其中的内容都在最后一次检查点之前产生并保证其中的内容都写入磁盘中。在这种情况下,被保存下来的将只有部分WAL日志,因此也不能实现任意历史时间点的恢复。为实现PITR,需要在WAL段文件被重用前进行归档备份操作,把将被重用的WAL段中的日志记录保存到其他位置。这样归档日志加上当前日志就可以形成连续的WAL日志记录。为了给数据库管理员提供最大的灵活性,PostgreSQL不对如何归档做任何假设,而是让管理员提供一个shell命令来拷贝一个完整的WAL段文件到备份存储位置。该命令可以就是一个cp命令,或者是一个复杂的shell脚本,所有的操作都由管理员决定。

PgArch预写日志归档进程处理流程

      PgArch进程的启动由函数pgarch_start负责。在该函数中执行fork操作创建Postmaster的子进程PgArch,在新创建的子进程中关闭从Postmaster进程中复制的网络连接端口,同时关闭与父进程的共享内存之间的联系,最后进入PgArch的工作函数PgArchiverMain,其处理流程如下:

                      165737_je0Y_3308173.png

归档相关的属性及参数

在postgresql.conf中与预写式日志归档相关的属性有:

  • archive_mode:表示是否进行归档操作,默认值为off(关闭)。
  • archive_command:由管理员设置的用于归档WAL日志的命令。
  • archive_time:表示归档周期,在超过该参数设定的时间时强制切换WAL段,默认值为0(表示禁用该功能)。

      为允许归档,需要把postgresql.conf配置文件中的wal_level参数设置为“archive”或“hot_standby”,archive_mode参数设置为“on”,并为archive_command命令指定一个shell命令。在用于归档的命令中,预定义变量“%p”用来指代需要归档的WAL全路径文件名,“%f”表示不带路径的文件名(这里的路径都是相对于当前工作目录的路径), 如果你需要在命令里嵌入一个真正的%字符,那么必须双写(%%)。每个WAL段文件归档时将调用archive_command所指定的命令。当归档命令返回0时,PostgreSQL就会认为文件被成功归档,然后就会删除或循环使用该WAL段文件。否则,如果返回一个非零值,PostgreSQL会认为文件没有被成功归档,便会周期性地重试直到成功。

在postgresql.conf文件中,archive_command的注释如下:

#archive_command = ''      # command to use to archive a logfile segment

                                            # placeholders: %p = path of file to archive

                                            #               %f = file name only

                                # e.g. 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'

根据注释内容我们可以设置archive_command如下:

archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/server/archivedir/%f'

其中test ! -f /mnt/server/archivedir/%f是测试你准备使用的归档命令,以保证它不会覆盖现有的文件,并且在这种情况下它返回非零状态。

在一些Unix平台上,cp 使用参数-i可以实现同上所描述的功能,如下:

archive_command = 'cp -i %p /mnt/server/archivedir/%f'

或者我们可以设置archive_command如下:

archive_command = 'test ! -f ../standalone/archiving_active || cp -i %p ../standalone/archive/%f'

针对上述命令,改变archive_mode需要重启数据库服务,所以这里通过一个小技巧,在开启关闭归档的时候避免重启:archive_command是否被启用取决于一个名为archiving_active的文件是否存在,它的出现能控制启用或禁用归档过程。

一次备份恢复实验

(一)备份

1.创建一个归档目录,如果目录不存在,则按照以下方法创建:

[postgres@localhost ~]$ cd /usr/local/pgsql/data

[postgres@localhost data]$ mkdir -p ../standalone

2.设置archive_command。在postgresql.conf文件中,你需要添加以下行的内容并重启服务,或者至少确认它们已经被设置好了:

archive_mode = on   

archive_command = 'test ! -f ../standalone/archiving_active || cp -i %p ../standalone/archive/%f'  

你还必须确保wal_level被设置为不是minimal的值,例如:

wal_level = archive

3.按以下方法开启归档:

[postgres@localhost data]$ mkdir ../standalone/archive

[postgres@localhost data]$ touch ../standalone/archiving_active

4.开始备份,如下所示:

[postgres@localhost data]$ psql -c "select pg_start_backup('standalone')"

pg_start_backup 

-----------------

 0/2000028

(1 row)

5.基础备份——备份数据文件(排除pg_xlog目录),如下所示:

[postgres@localhost data]$ tar -cv --exclude="pg_xlog/*" -f ../standalone/baseline.tar.bz2 /usr/local/pgsql/data

6.停止备份,如下所示:

[postgres@localhost data]$ psql -c "select pg_stop_backup(),current_timestamp"                                                                                        
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived                                                                                        
 pg_stop_backup |             now                                                                                                      
----------------+------------------------------                                                                                        
 0/20000C0      | 2017-02-13 13:46:08.05277+08                                                                                        
(1 row)           

7.停止归档,如下所示:

[postgres@localhost data]$ rm ../standalone/archiving_active 

8.将文件移到archive子目录,为恢复做好准备,如下所示:      

[postgres@localhost data]$ mv ../standalone/archive/ archive/

           

9.将归档文件加入独立的备份中:             

[postgres@localhost data]$ tar -rf ../standalone/baseline.tar.bz2 archive/   

10.编写用于恢复的recovery.conf文件。注意,这里提及的归档路径必须与第8步中归档文件复制的位置相匹配:

[postgres@localhost data]$ echo "restore_command = 'cp archive/%f %p'" > recovery.conf

[postgres@localhost data]$ echo "recovery_end_command = 'rm -R archive'" >> recovery.conf

11.将recovery.conf文件添加到备份包中:

[postgres@localhost data]$ tar -rf ../standalone/baseline.tar.bz2 recovery.conf

12.保存../standalone/$BACHUPNAME到安全的地方。很明显,安全的地方肯定不在这台机器上。

上述过程以在standalone目录中产生名为$BACKUPNAME的文件为完结。所以你需要记得将它复制到其他安全的地方。这个文件包含恢复所要的一切东西,包括一个恢复用的参数文件。

(二)恢复

1.将备份文件解压到新的data目录

2.在进行恢复前,确认你使用的是正确的备份:

[postgres@localhost data]$ cat backup_label                                                                 
START WAL LOCATION: 0/2000028 (file 000000010000000000000002)        
CHECKPOINT LOCATION: 0/2000028                                                                
BACKUP METHOD: pg_start_backup                                                                
BACKUP FROM: master                                                                
START TIME: 2017-02-13 13:34:43 CST                                                                
LABEL: standalone

3.确认所有的文件权限和属主都正确,文件连接符都有效。如果你在所有地方都是使用相同ID的postgres用户,则应该都是符合条件的,这也是推荐的做法。

4.启动服务

[postgres@localhost bin]$ ./pg_ctl -D ../data start                                                            
pg_ctl: another server might be running; trying to start server anyway                                                    
server starting                                                                                
[postgres@localhost bin]$ LOG:  database system was interrupted; last known up at 2017-02-13 13:34:43 CST                                
LOG:  creating missing WAL directory "pg_xlog/archive_status"                                                        
LOG:  starting archive recovery                                                                        
LOG:  restored log file "000000010000000000000002" from archive                                             
LOG:  redo starts at 0/2000098                                                                        
LOG:  consistent recovery state reached at 0/20000C0                                                            
cp: 无法获取"archive/000000010000000000000003" 的文件状态(stat): 没有那个文件或目录              
LOG:  redo done at 0/20000C0                                                                        
LOG:  restored log file "000000010000000000000002" from archive                                             
cp: 无法获取"archive/00000002.history" 的文件状态(stat): 没有那个文件或目录                                     
LOG:  selected new timeline ID: 2                                                                    
cp: 无法获取"archive/00000001.history" 的文件状态(stat): 没有那个文件或目录                                      
LOG:  archive recovery complete                                                                        
LOG:  MultiXact member wraparound protections are now enabled                                         
LOG:  database system is ready to accept connections                                                            
LOG:  autovacuum launcher started  

至此,数据库恢复成功。

模拟归档失败

场景一:归档目录损坏

       为了标识各个段文件的状态,PostgreSQL在数据库集簇的pg_xlog/archive_status目录下记录了每一个WAL段文件的状态文件,状态文件的前缀与段文件同名,以表示时间顺序的整数形式命名。状态文件后缀为.ready或者.done,代表段文件的归档状态,分别代表“就绪”和“已完成”两种模式。PgArch进程会找到所有状态为“就绪”的段文件,找到状态文件后,若用户设置了归档命令,PgArch进程将归档命令解析后交由系统的shell函数system(3)执行。文件归档成功后会把pg_xlog/archive_status目录下相应的状态文件后缀修改为.done。

1)postgresql安装完成后,开启归档;

2)利用tpch工具往数据库插入1G数据;

3)插入完成前,将归档文件名改为另一个文件名:mv archive/ archive-test

4)此时查看归档目录下归档完成的文件:

[postgres@localhost archive-test]$ ll								
total 393216								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000001								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000002								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000003								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000004								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000005								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000006								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000007								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000008								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000009								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000A								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000B								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000C								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000D								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000E								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000F								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000010								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000011								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000012								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000013								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000014								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000015								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000016								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000017								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000018								

5)数据导入完成后,查看pg_xlog下的文件:

[postgres@localhost pg_xlog]$ ll								
total 1605644								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000019								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001A								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001B								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001C								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001D								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001E								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000001F								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000020								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000021								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000022								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000023								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000024								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000025								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000026								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000027								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000028								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000029								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002A								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002B								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002C								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002D								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002E								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000002F								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000030								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000031								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000032								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000033								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000034								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000035								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000036								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000037								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000038								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000039								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003A								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003B								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003C								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003D								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003E								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000003F								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000040								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000041								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000042								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000043								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000044								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000045								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000046								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000047								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000048								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 000000010000000000000049								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000004A								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000004B								
-rw-------. 1 postgres root 16777216 Mar 22 14:25 00000001000000000000004C								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 00000001000000000000004D								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 00000001000000000000004E								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 00000001000000000000004F								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000050								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000051								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000052								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000053								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000054								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000055								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000056								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000057								
-rw-------. 1 postgres root 16777216 Mar 22 14:26 000000010000000000000058								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 000000010000000000000059								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005A								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005B								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005C								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005D								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005E								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 00000001000000000000005F								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 000000010000000000000060								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 000000010000000000000061								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 000000010000000000000062								
-rw-------. 1 postgres root 16777216 Mar 22 14:27 000000010000000000000063								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000064								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000065								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000066								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000067								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000068								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000069								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006A								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006B								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006C								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006D								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006E								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 00000001000000000000006F								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000070								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000071								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000072								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000073								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000074								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000075								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000076								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000077								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000078								
-rw-------. 1 postgres root 16777216 Mar 22 14:28 000000010000000000000079								
-rw-------. 1 postgres root 16777216 Mar 22 14:29 00000001000000000000007A								
drwx------. 2 postgres root     8192 Mar 22 14:28 archive_status								

此时,pg_xlog目录下的archive_status文件下:

[postgres@localhost archive_status]$ ll				
total 0				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000019.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000020.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000021.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000022.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000023.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000024.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000025.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000026.ready				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000027.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000028.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000029.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000030.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000031.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000032.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000033.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000034.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000035.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000036.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000037.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000038.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000039.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000040.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000041.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000042.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000043.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000044.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000045.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000046.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000047.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000048.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000049.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000004A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000004B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000050.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000051.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000052.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000053.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000054.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000055.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000056.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000057.ready				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000058.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000059.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000060.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000061.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000062.ready				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000063.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000064.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000065.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000066.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000067.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000068.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000069.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006A.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006B.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006C.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006D.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006E.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006F.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000070.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000071.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000072.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000073.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000074.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000075.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000076.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000077.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000078.ready				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000079.ready				

6)将归档目录更改回原来的文件名:

mv archive-test/ archive

7)查看归档目录下的文件:

[postgres@localhost archive]$ ll								
total 1982464								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000001								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000002								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000003								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000004								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000005								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000006								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000007								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000008								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000009								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000A								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000B								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000C								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000D								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000E								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 00000001000000000000000F								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000010								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000011								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000012								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000013								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000014								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000015								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000016								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000017								
-rw-------. 1 postgres root 16777216 Mar 22 14:24 000000010000000000000018								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000019								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000001F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000020								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000021								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000022								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000023								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000024								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000025								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000026								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000027								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000028								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000029								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000002F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000030								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000031								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000032								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000033								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000034								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000035								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000036								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000037								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000038								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000039								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000003F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000040								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000041								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000042								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000043								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000044								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000045								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000046								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000047								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000048								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000049								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000004F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000050								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000051								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000052								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000053								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000054								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000055								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000056								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000057								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000058								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000059								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000005F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000060								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000061								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000062								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000063								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000064								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000065								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000066								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000067								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000068								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000069								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006A								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006B								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006C								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006D								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006E								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 00000001000000000000006F								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000070								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000071								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000072								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000073								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000074								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000075								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000076								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000077								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000078								
-rw-------. 1 postgres root 16777216 Mar 22 14:38 000000010000000000000079								

此时,pg_xlog目录下的archive_status文件下:

[postgres@localhost archive_status]$ ll				
total 0				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000019.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001A.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001B.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001C.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001D.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001E.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 00000001000000000000001F.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000020.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000021.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000022.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000023.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000024.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000025.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000026.done				
-rw-------. 1 postgres root 0 Mar 22 14:24 000000010000000000000027.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000028.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000029.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002A.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002B.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002C.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002D.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002E.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000002F.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000030.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000031.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000032.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000033.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000034.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000035.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000036.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000037.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000038.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000039.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003A.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003B.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003C.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003D.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003E.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000003F.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000040.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000041.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000042.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000043.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000044.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000045.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000046.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000047.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000048.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 000000010000000000000049.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000004A.done				
-rw-------. 1 postgres root 0 Mar 22 14:25 00000001000000000000004B.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004C.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004D.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004E.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 00000001000000000000004F.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000050.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000051.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000052.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000053.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000054.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000055.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000056.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000057.done				
-rw-------. 1 postgres root 0 Mar 22 14:26 000000010000000000000058.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000059.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005A.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005B.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005C.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005D.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005E.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 00000001000000000000005F.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000060.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000061.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000062.done				
-rw-------. 1 postgres root 0 Mar 22 14:27 000000010000000000000063.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000064.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000065.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000066.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000067.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000068.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000069.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006A.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006B.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006C.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006D.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006E.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 00000001000000000000006F.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000070.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000071.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000072.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000073.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000074.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000075.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000076.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000077.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000078.done				
-rw-------. 1 postgres root 0 Mar 22 14:28 000000010000000000000079.done				

综上,开启归档后,如果数据库在执行更新操作生成pg_xlog文件过程中归档失败,pg_xlog目录下会一直保留未归档成功的文件且不会被覆盖,archive_status文件下也会存在未归档成功文件的状态。当归档进程恢复正常后,此前归档失败的文件会重新归档到归档目录。


场景二:pg_xlog目录所在磁盘空间满   

1.将日志文件和数据文件分别存储在不同的磁盘上, 分一块70MB大小的磁盘,挂载到目录/usr/local/pgsql/data/pg_xlog下:

[root@localhost local]# mount /dev/centos/lvname /usr/local/pgsql/data/pg_xlog/

注意,挂载时需要将pg_xlog目录下的文件移到其他位置,挂载后再将文件移回到pg_xlog。否则文件会在挂载后被覆盖,导致数据库无法启动。

2.启动数据库后开启归档,对数据库进行插入数据的操作,由于pg_xlog中的文件大小为16MB,当磁盘剩余12M空间时,如下:

/dev/mapper/centos-lvname ext4       66M   50M   12M  82% /usr/local/pgsql/data/pg_xlog

pg_xlog无法继续写入,数据库中执行操作会报错如下:

postgres=# \dt
WARNING:  57P02: terminating connection because of crash of another server process
DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
HINT:  In a moment you should be able to reconnect to the database and repeat your command.
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

重新连接数据库时无法连接:

[postgres@localhost bin]$ psql
psql: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

其中pg_log中的报错信息如下:

[postgres@localhost pg_log]$ cat postgresql-2017-03-28_173754.log 
LOG:  database system was shut down at 2017-03-28 17:37:54 CST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
PANIC:  could not write to file "pg_xlog/xlogtemp.21517": No space left on device

综上,如果px_xlog目录所在的文件系统满了,PostgreSQL将会做一个PANIC停机。未提交的事务将会丢失,一直到你释放空间之前数据库都会一直处于离线状态。

                                                                                                                             
                                

转载于:https://my.oschina.net/u/3308173/blog/853490

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值