版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/ctypyb2002/article/details/89400766
os: ubuntu 16.04
db: postgresql 9.6.8
上一篇安装了 pg_filedump,这篇文章简单介绍了如何使用.
pg_filedump --help
# su - postgres
$ which pg_filedump
/usr/bin/pg_filedump
$ pg_filedump --help
Error: Missing file name to dump.
Usage: pg_filedump [-abcdfhikxy] [-R startblock [endblock]] [-S blocksize] [-s segsize] [-n segnumber] file
Display formatted contents of a PostgreSQL heap/index/control file
Defaults are: relative addressing, range of the entire file, block
size as listed on block 0 in the file
The following options are valid for heap and index files:
-a Display absolute addresses when formatting (Block header
information is always block relative)
-b Display binary block images within a range (Option will turn
off all formatting options)
-d Display formatted block content dump (Option will turn off
all other formatting options)
-f Display formatted block content dump along with interpretation
-h Display this information
-i Display interpreted item details
-k Verify block checksums
-R Display specific block ranges within the file (Blocks are
indexed from 0)
[startblock]: block to start at
[endblock]: block to end at
A startblock without an endblock will format the single block
-s Force segment size to [segsize]
-n Force segment number to [segnumber]
-S Force block size to [blocksize]
-x Force interpreted formatting of block items as index items
-y Force interpreted formatting of block items as heap items
The following options are valid for control files:
-c Interpret the file listed as a control file
-f Display formatted content dump along with interpretation
-S Force block size to [blocksize]
Report bugs to <[email protected]>
创建测试表,生成测试数据
$ psql
psql (9.6.8)
Type "help" for help.
postgres=# create table tmp_t0(c1 varchar(100));
CREATE TABLE
postgres=# insert into tmp_t0 select '1';
INSERT 0 1
postgres=# insert into tmp_t0 select 'a';
INSERT 0 1
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+--------+-------+----------
public | tmp_t0 | table | postgres
(1 row)
postgres=# select * from tmp_t0;
c1
----
1
a
(2 rows)
postgres=# select pg_relation_filepath('tmp_t0');
pg_relation_filepath
----------------------
base/12439/32769
(1 row)
postgres=# checkpoint;
CHECKPOINT
一定要手动执行下 checkpoint ,确保数据落盘.
# su - postgres
$ pg_filedump -S 8192 -i -f /data/pg9.6/main/base/12439/32769
*******************************************************************
* PostgreSQL File/Block Formatted Dump Utility - Version 9.6.0
*
* File: /data/pg9.6/main/base/12439/32769
* Options used: -S 8192 -i -f
*
* Dump created on: Fri Apr 19 12:11:53 2019
*******************************************************************
Block 0 ********************************************************
<Header> -----
Block Offset: 0x00000000 Offsets: Lower 32 (0x0020)
Block: Size 8192 Version 4 Upper 8128 (0x1fc0)
LSN: logid 0 recoff 0xa10001c0 Special 8192 (0x2000)
Items: 2 Free Space: 8096
Checksum: 0x0000 Prune XID: 0x00000000 Flags: 0x0000 ()
Length (including item array): 32
0000: 00000000 c00100a1 00000000 2000c01f ............ ...
0010: 00200420 00000000 e09f3400 c09f3400 . . ......4...4.
<Data> ------
Item 1 -- Length: 26 Offset: 8160 (0x1fe0) Flags: NORMAL
XMIN: 628 XMAX: 0 CID|XVAC: 0
Block Id: 0 linp Index: 1 Attributes: 1 Size: 24
infomask: 0x0902 (HASVARWIDTH|XMIN_COMMITTED|XMAX_INVALID)
1fe0: 74020000 00000000 00000000 00000000 t...............
1ff0: 01000100 02091800 0531 .........1
Item 2 -- Length: 26 Offset: 8128 (0x1fc0) Flags: NORMAL
XMIN: 629 XMAX: 0 CID|XVAC: 0
Block Id: 0 linp Index: 2 Attributes: 1 Size: 24
infomask: 0x0902 (HASVARWIDTH|XMIN_COMMITTED|XMAX_INVALID)
1fc0: 75020000 00000000 00000000 00000000 u...............
1fd0: 02000100 02091800 0561 .........a
*** End of File Encountered. Last Block Read: 0 ***
这个怎么看?参考了德哥的这篇文章https://yq.aliyun.com/articles/72253?t=t1
需要关注下 infomask,这个需要查看: src/include/access/htup_details.h
看来需要努力看看源码.
参考:
https://wiki.postgresql.org/wiki/Pg_filedump
https://git.postgresql.org/gitweb/?p=pg_filedump.git
https://git.postgresql.org/gitweb/?p=pg_filedump.git;a=blob;f=README.pg_filedump
https://yq.aliyun.com/articles/72253?t=t1