Dump data from PostgreSQL's table which have few bad blocks

今天在群里有位兄弟遇到PostgreSQL坏块的表无法读取的问题,版本是8.2的。当涉及到全表扫描是会遇到错误块的提示。
以前我在 GreenPlum中也遇到过类似问题。当时是使用COPY的方法把可以导出的数据导出。遇到坏块之后的数据都无法导出。
今天再来看这个问题,可 能还有更好的解决办法:不过已经没有场景可以验证了,以后遇到的时候一定要试一试。
参考方法1 :
COPY bad_table to csv
参考方法2 :
删除坏块的所有记录,可行性不高,因为删除记录是需要改动TUPLE的HEAD的xmax的,而扫描到PAGE 都有问题,这样肯定还是不行。
参考方法3 :
采用指针,跳过出错的块,这样的好处是可以导出更多的正常数据。
参考方法4 :
来 自互连网,
Below is the entry quoted from the online manual for 7.3:

ZERO_DAMAGED_PAGES (boolean)
        
        Detection of a damaged page header normally causes PostgreSQL to
        report an error, aborting the current transaction. Setting
        zero_damaged_pages to true causes the system to instead report a
        warning, zero out the damaged page, and continue processing.
        This behavior will destroy data, namely all the rows on the
        damaged page. But it allows you to get past the error and
        retrieve rows from any undamaged pages that may be present in
        the table. So it is useful for recovering data if corruption has
        occurred due to hardware or software error. You should generally
        not set this true until you have given up hope of recovering
        data from the damaged page(s) of a table. The default setting is
        off, and it can only be changed by a superuser.

修 复过程 :
Please note -
Note: vacuum is a time-consuming procedure; it may take up to several hours to complete! This procedure requires a lot of system resources and creates a high server load.
Be careful: if the server gets down during this process, some data may be lost!
We recommend you to backup HS database before you follow the steps below.
So, to fix the issue, you should do the following :
1. Stop H-Sphere and postgres :
Login into CP box under root user and run :
Linux :
# /etc/rc.d/init.d/httpcp stop
# /etc/rc.d/init.d/postgresql stop
FreeBSD :
# /usr/local/etc/rc.d/apachecp.sh stop
# /usr/local/etc/rc.d/010.pgsql.sh stop
2. Please edit the postgresql.conf ( Linux - ~postgres/data/postgresql.conf , FreeBSD - ~pgsql/data/postgresql.conf ) file and add the following line : zero_damaged_pages=on
3. Start postgresql service :
Linux :
# /etc/rc.d/init.d/postgresql start
FreeBSD :
# /usr/local/etc/rc.d/010.pgsql.sh start
4. Log into H-Sphere database and run the "vacuum analyze" command. E.g. :
[root@cp ~]# su -l cpanel
-bash-3.00$ psql hsphere
Welcome to psql 7.4.13, the PostgreSQL interactive terminal.
Type:
/copyright for distribution terms
/h for help with SQL commands
/? for help on internal slash commands
/g or terminate with semicolon to execute query
/q to quit
hsphere=# vacuum analyze
hsphere-# ; WARNING: relation "bill_entry" page 31516 is uninitialized --- fixing VACUUM
hsphere=#
5. Comment the "zero_damaged_pages=on" line in the postgresql.conf file and restart postgres/H-Sphere.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值