pg10 安装pageinspect插件
1.切换到源码包的contrib路径下,ls 插件名称
cd /data/soft/PostGreSQL/postgresql-10.20/contrib/pageinspect
编译该插件
make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o rawpage.o rawpage.c -MMD -MP -MF .deps/rawpage.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o heapfuncs.o heapfuncs.c -MMD -MP -MF .deps/heapfuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o btreefuncs.o btreefuncs.c -MMD -MP -MF .deps/btreefuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o fsmfuncs.o fsmfuncs.c -MMD -MP -MF .deps/fsmfuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o brinfuncs.o brinfuncs.c -MMD -MP -MF .deps/brinfuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o ginfuncs.o ginfuncs.c -MMD -MP -MF .deps/ginfuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE -c -o hashfuncs.o hashfuncs.c -MMD -MP -MF .deps/hashfuncs.Po
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -fPIC -shared -o pageinspect.so rawpage.o heapfuncs.o btreefuncs.o fsmfuncs.o brinfuncs.o ginfuncs.o hashfuncs.o -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/home/postgres/10/lib',--enable-new-dtags
安装该插件,安装插件时需要确保对数据库安装目录有权限,否则报错如下
make install
/usr/bin/mkdir -p '/home/postgres/10/lib'
/usr/bin/mkdir -p '/home/postgres/10/share/extension'
/usr/bin/mkdir -p '/home/postgres/10/share/extension'
/usr/bin/install -c -m 755 pageinspect.so '/home/postgres/10/lib/pageinspect.so'
/usr/bin/install: cannot create regular file ‘/home/postgres/10/lib/pageinspect.so’: **Permission denied**
make: *** [install-lib-shared] Error 1
赋权
chown -R postgres.postgres /home/postgres/10/
重新安装
su - postgres
cd /data/soft/PostGreSQL/postgresql-10.20/contrib/pageinspect
**ls**
brinfuncs.c expected ginfuncs.o heapfuncs.o pageinspect--1.2--1.3.sql pageinspect--1.5.sql pageinspect--unpackaged--1.0.sql
brinfuncs.o fsmfuncs.c hashfuncs.c Makefile pageinspect--1.3--1.4.sql pageinspect.control rawpage.c
btreefuncs.c fsmfuncs.o hashfuncs.o pageinspect--1.0--1.1.sql pageinspect--1.4--1.5.sql pageinspect.h rawpage.o
btreefuncs.o ginfuncs.c heapfuncs.c pageinspect--1.1--1.2.sql pageinspect--1.5--1.6.sql pageinspect.so sql
**make install**
/usr/bin/mkdir -p '/home/postgres/10/lib'
/usr/bin/mkdir -p '/home/postgres/10/share/extension'
/usr/bin/mkdir -p '/home/postgres/10/share/extension'
/usr/bin/install -c -m 755 pageinspect.so '/home/postgres/10/lib/pageinspect.so'
/usr/bin/install -c -m 644 ./pageinspect.control '/home/postgres/10/share/extension/'
/usr/bin/install -c -m 644 ./pageinspect--1.5.sql ./pageinspect--1.5--1.6.sql ./pageinspect--1.4--1.5.sql ./pageinspect--1.3--1.4.sql ./pageinspect--1.2--1.3.sql ./pageinspect--1.1--1.2.sql ./pageinspect--1.0--1.1.sql ./pageinspect--unpackaged--1.0.sql '/home/postgres/10/share/extension/'
安装完成后进行查看
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
postgres=# \c template1
You are now connected to database "template1" as user "postgres".
查询该插件已存在
template1=# select * from pg_available_extensions ;
name | default_version | installed_version | comment
-------------+-----------------+-------------------+-------------------------------------------------------
plpgsql | 1.0 | 1.0 | PL/pgSQL procedural language
**pageinspect** | 1.6 | | inspect the contents of database pages at a low level
(2 rows)
template1=# create extension pageinspect;
CREATE EXTENSION
template1=# \dx
List of installed extensions
Name | Version | Schema | Description
-------------+---------+------------+-------------------------------------------------------
**pageinspect** | 1.6 | public | inspect the contents of database pages at a low level
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
pageInspect相关函数介绍
get_raw_page函数:将指定表文件中的页面内容返回。param1:表名,param2:main/fsm/vm, param3:第几页;
page_header函数:返回本页面中的page header信息。param1:get_raw_page函数的返回值;
heap_page_items函数:显示堆页面上的所有行指针。param1:get_raw_page函数的返回值。