语言
<< 返回文章列表

bbed for PostgreSQL

2019年1月10日
李亮
1719

续:http://www.enmotech.com/web/detail/1/629/2.html


Directory

一、关于bbedp

用python模仿bbed写了一个bbed for pg的脚本,简单的查看和修改字节都可以做到,你可以在这里下载到最新的版本。如果你不清楚这个脚本的功能,请不要轻易在生产环境使用它,这很危险。

使用环境:

1、linux

2、python 2.7

二、如何开始

2.1 找到table对应page的绝对路径

你可以通过$PGDATA环境变量找到数据文件的目录。

postgres@whf307-> echo $PGDATA
/oracle/soft/pg_data/
postgres@whf307->

如果没有配置环境变量,当然可以通过进程找到

postgres@whf307-> ps -ef | grep postgres
postgres 32739     1  0 Nov13 ?        00:00:07 /oracle/soft/pgsql9.6/bin/postgres
postgres 32747 32739  0 Nov13 ?        00:00:02 postgres: checkpointer process   
postgres 32748 32739  0 Nov13 ?        00:00:06 postgres: writer process   
postgres 32749 32739  0 Nov13 ?        00:00:12 postgres: wal writer process   
postgres 32750 32739  0 Nov13 ?        00:00:05 postgres: autovacuum launcher process  
postgres 32751 32739  0 Nov13 ?        00:00:00 postgres: archiver process   last was 000000010000000600000067
postgres 32752 32739  0 Nov13 ?        00:00:12 postgres: stats collector process  
postgres@whf307-> lsof -p 32739| grep cwd
postgres 32739 postgres  cwd    DIR              253,7      4096 147604224 /oracle/soft/pg_data
postgres@whf307->

再比如t1表的page

postgres=# select pg_relation_filepath('t1');
 pg_relation_filepath 
----------------------
 base/13323/24706
(1 row)

postgres=#

然后编辑bbedp脚本下的file文件就可以开始了,目前仅支持单个文件

vi file
/oracle/soft/pg_data/base/13323/24706

2.2 运行bbedp

这里你需要给x权限运行就可以了,为了效果就不要密码了。

postgres@whf307-> ./bbedp
Password: 

BBEDP: Release 0.1.0.0.0 - Limited Production on Sat Nov 24 16:50:30 2018

Copyright (c) 2018, 2018, whf307 and/or its affiliates.  All rights reserved.

************* !!! For PostgreSQL Internal Test only !!! *************** 

BBEDP> help
set block [block_offset]
set count [bytes_to_display]
set offset  [offset_to_dump]
map :map the struct
d   :dump the offset
p   :print offset
p PageHeaderData :to print the page header struct
p Linps :to print the linps
p linp[n] :to print the linp[n]
p Tuples: print all tupels
p tuples [n]:print the tuple n
p Pd_special : print pd_special
m /x aaaa offset bbbb :to modify the offset
exit :exit the program
BBEDP>

如果你了解bbed,那么help看一眼帮助就很容易上手bbedp了,你不了解bbed也没关系,脚本很简单,主要功能有查看page结构,dump字节,修改字节。