暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片
PostgreSQL12通过pg_resetwal误删恢复.pdf
120
8页
7次
2024-05-09
10墨值下载
PostgreSQL12通过 pg_resetwal 误删恢复
1pg_resetwal
pg_resetwal 主要的工作的目的是为了在系统数据损坏的时候,通过pg_resetwal来重新标志日志的位
置,让系统可以重启运行并且重置pg_control文件等
注意点:
1、这个是整个库进行了回滚,回滚到指定的事务LSN 号的位置,所以生产环境不会使用这个方法
进行恢复。
2pg_resetwal恢复之后,WAL日志整体被清理,原有的日志(单机)会被归并,原有的日志都
没有了。
3truncate无法进行恢复,因为truncate之后表对应的物理文件发生改变,回滚之后会报错
ERROR: could not open file "base/13593/24761": No such file or directory ,且这样回滚之
后,就只能通过备份恢复数据库了。
1.1pg_resetwal 语法解析
[postgres@smzq-dsj2 bin]$ pg_resetwal --help
pg_resetwal resets the PostgreSQL write-ahead log.
Usage:
pg_resetwal [OPTION]... DATADIR
Options:
-c, --commit-timestamp-ids=XID,XID
                 set oldest and newest transactions bearing
                 commit timestamp (zero means no change)
[-D, --pgdata=]DATADIR      data directory
-e, --epoch=XIDEPOCH       set next transaction ID epoch
-f, --force           force update to be done
-l, --next-wal-file=WALFILE   set minimum starting location for new WAL
-m, --multixact-ids=MXID,MXID  set next and oldest multitransaction ID
-n, --dry-run          no update, just show what would be done
-o, --next-oid=OID        set next OID
-O, --multixact-offset=OFFSET  set next multitransaction offset
-u, --oldest-transaction-id=XID set oldest transaction ID
-V, --version          output version information, then exit
-x, --next-transaction-id=XID  set next transaction ID
  --wal-segsize=SIZE      size of WAL segments, in megabytes
-?, --help            show this help, then exit
Report bugs to <pgsql-bugs@lists.postgresql.org>.
1.2pg_resetwal 恢复数据
1.2.1、创建需要的表和数据
1.2.2delete误删和恢复
delete数据
1.2.2.1、恢复数据
1.2.2.1.1、先确认当前的日志的以及LSN
postgres=# insert into test1 values(1,'asd');
INSERT 0 1
postgres=# insert into test1 values(2,'qwe');
INSERT 0 1
postgres=# insert into test1 values(3,'zxc');
INSERT 0 1
postgres=# select * from test1;       
id | name
----+------
10 | aaaa
1 | asd
2 | qwe
3 | zxc
(4 rows)
postgres=# delete from test1 where id>1;
DELETE 3
postgres=# select * from test1;    
id | name
----+------
1 | asd
(1 row)
postgres=# select
pg_current_wal_lsn(),pg_walfile_name(pg_current_wal_lsn()),pg_walfile_name_offse
t(pg_current_wal_lsn());
pg_current_wal_lsn |   pg_walfile_name   |    pg_walfile_name_offset 
 
--------------------+--------------------------+---------------------------------
---
20/2615C090    | 000000020000002000000026 |
(000000020000002000000026,1425552)
(1 row)
of 8
10墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜