#!/usr/bin/python import sys,os,struct,string site_base = "/var/lib/pgsql/base" db_name = "betest" table_name = "test" db_path = os.path.join(site_base,db_name) table_path = os.path.join(db_path,table_name) page_size = 8*1024 def strbits(s,len): bits = [] while s: c = s[0] s = s[1:] b = struct.unpack('B',c)[0] for i in range(8): if b & (1<> 17) lp_flags = int((ItemIdData_I32 >> 15) & 3) lp_off = int(ItemIdData_I32 & 0x7fff) self.item_pointers.append(hex(ItemIdData_I32),lp_off,lp_flags,lp_len) rawItemData = self.rawdata[lp_off:lp_off+lp_len] t_oid = struct.unpack('L', rawItemData[ 0: 4])[0] t_001 = struct.unpack('L', rawItemData[ 4: 8])[0] t_002 = struct.unpack('L', rawItemData[ 8:12])[0] t_xmin = struct.unpack('L', rawItemData[12:16])[0] t_xmax = struct.unpack('L', rawItemData[16:20])[0] t_ctid = struct.unpack('LH', rawItemData[20:26]) t_fcnt = struct.unpack('H', rawItemData[26:28])[0] t_xxx = struct.unpack('2B', rawItemData[28:30]) t_doff = struct.unpack('B', rawItemData[30:31])[0] t_mask = strbits(rawItemData[31:t_doff],t_fcnt) # t_mask = rawItemData[31:t_doff] t_data = rawItemData[t_doff:] self.items.append(t_oid,t_001,t_002,t_xmin,t_xmax,t_ctid,t_fcnt,t_xxx,t_doff,t_mask,t_data) def __str__(self): strval = [str((self.lower, self.upper, self.special, self.opaque))] strval.append(string.join(map(str,self.item_pointers),'\n')) strval.append(string.join(map(repr,self.items),'\n')) return string.join(strval,'\n------------------\n') if __name__=="__main__": print '# dumping %s' % table_path fd = open(table_name) page = table_page(fd,0) print page