如果自己搞不定可以找诗檀软件专业PostgreSQL数据库修复团队成员帮您恢复!
诗檀软件专业数据库修复团队
服务热线 : 13764045638 QQ号:47079569 邮箱:service@parnassusdata.com
在postgreSQL中少量数据的删除时可以通过pg_filedump工具恢复被误删除的数据行的。
其原理是虽然数据被删除了,但在数据文件中其仅仅是被标记为删除,而并未被清空;只要在auto vaccum之前都可以通过pg_filedump工具恢复这部分数据。
下面是一个例子:
create database testa; \c testa create table novels (name varchar(200), id int); insert into novels values('三国演义',1); insert into novels values('水浒传',2); insert into novels values('西游记',3); insert into novels values('红楼梦',4); select oid from pg_database where datname='testa'; oid ------- 17420 select oid,relfilenode from pg_class where relname='novels'; oid | relfilenode -------+------------- 17421 | 17421 (1 row) testa=# delete from novels; DELETE 4 testa=# select * from novels; name | id ------+---- (0 rows) postgres@vultr:~$ ls -l /var/lib/postgresql/10/main/base/17420/17421 -rw------- 1 postgres postgres 8192 Nov 25 05:11 /var/lib/postgresql/10/main/base/17420/17421 root@vultr:~# chmod 700 pg_filedump_rc root@vultr:~# ./pg_filedump_rc -D charn,int /var/lib/postgresql/10/main/base/17420/17421 ******************************************************************* * PostgreSQL File/Block Formatted Dump Utility - Version 11.0 * * File: /var/lib/postgresql/10/main/base/17420/17421 * Options used: -D charn,int * * Dump created on: Mon Nov 25 05:17:40 2019 ******************************************************************* Block 0 ********************************************************----- Block Offset: 0x00000000 Offsets: Lower 40 (0x0028) Block: Size 8192 Version 4 Upper 8024 (0x1f58) LSN: logid 0 recoff 0x07db2630 Special 8192 (0x2000) Items: 4 Free Space: 7984 Checksum: 0xd24c Prune XID: 0x0000037b Flags: 0x0000 () Length (including item array): 40 ------ Item 1 -- Length: 44 Offset: 8144 (0x1fd0) Flags: NORMAL COPY: 三国演义 1 Item 2 -- Length: 40 Offset: 8104 (0x1fa8) Flags: NORMAL COPY: 水浒传 2 Item 3 -- Length: 40 Offset: 8064 (0x1f80) Flags: NORMAL COPY: 西游记 3 Item 4 -- Length: 40 Offset: 8024 (0x1f58) Flags: NORMAL COPY: 红楼梦 4 *** End of File Encountered. Last Block Read: 0 *** root@vultr:~# ./pg_filedump_rc -D charn,int /var/lib/postgresql/10/main/base/17420/17421|grep COPY COPY: 三国演义 1 COPY: 水浒传 2 COPY: 西游记 3 COPY: 红楼梦 4