HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

Support For Pageinspect & Pagehack

Availability

This feature is available since MogDB 5.0.2.

Introduction

New pageinspect and pagehack tools are used to assist in locating related issues. pageinspect is an extension, after installation to create extension to use, pagehack is an executable tool, need to be installed on the command line to use.

Benefits

The new tool is only available to front-line maintenance, testers, and developers for internal use in locating problems.

Description

pageinspect

This extension implements in the row-store table (astore) scenario to view the data file and Btree index file related page content information, belongs to the online query (MogDB use case ALIVE), in the SQL side of the execution of the relevant commands to view the information.

Pageinspect is an extension, you need to install manually, before installation, please download the released Toolkits in official website download page, unpack the corresponding files and copy them to the specified directory and change the permissions. Log in to the database and create the extension.

# Unpack the toolkit with the root user
tar -xzvf Toolkits-5.0.2-Kylin-arm64.tar.gz

# Use the database instance user (e.g., omm), go to the pageinspect folder under toolkits and copy the appropriate files to the specified directory
cd pageinspect/
cp pageinspect--1.0.sql $GAUSSHOME/share/postgresql/extension
cp pageinspect.control $GAUSSHOME/share/postgresql/extension
cp pageinspect--unpackaged--1.0.sql $GAUSSHOME/share/postgresql/extension
cp pageinspect.so $GAUSSHOME/lib/postgresql

# Modify permissions
cd $GAUSSHOME/share/postgresql/extension
chmod 644 pageinspect--1.0.sql pageinspect.control pageinspect--unpackaged--1.0.sql
cd $GAUSSHOME/lib/postgresql
chmod 755 pageinspect.so

# Log into the database and create extension
gsql -r
CREATE EXTENSION pageinspect;

The extension provides several system functions to query using a fixed format with the following syntax:

# View the contents of the heap data table
SELECT * FROM heap_page_items(get_raw_page('table_name','main',page_no));
# View header information on a heap page
SELECT * FROM page_header(get_raw_page('table_name','main',page_no));
# View meta page information
SELECT * FROM bt_metap('index_name');
# View the contents of the specified index page number
SELECT * FROM bt_page_items('index_name', page_no);

pagehack

The pagehack tool is used to parse offline files generated by row-store tables and BTree indexes created in MogDB instances. Pagehack is a binary executable tool executed directly on the terminal command line, with parameters for the files to be parsed (row-store tables and BTree index files are supported), displaying the specific data content of the page in the file. This tool needs to be installed manually, the method is as follows:

# Unpack the toolkit with the root user
tar -xzvf Toolkits-5.0.2-Kylin-arm64.tar.gz

# Use the database instance user (e.g., omm), go to the pagehack folder under toolkits and copy the appropriate files to the specified directory
cd pagehack/
cp pagehack $GAUSSHOME/bin
cp pagehack.so $GAUSSHOME/lib/postgresql

# Modify permissions
cd $GAUSSHOME/bin
chmod 755 pagehack
cd $GAUSSHOME/lib/postgresql
chmod 755 pagehack.so

Once the installation is complete, execute the following command directly to use the tool:

pagehack -f [filename]

Examples

pageinspect

# Create the pageinspect extension, then create a row-store table and a BTree index, and insert some data into the table.
MogDB=# CREATE EXTENSION pageinspect;
CREATE EXTENSION
MogDB=# CREATE TABLE t(id int, a text);
CREATE TABLE
MogDB=# CREATE INDEX idx_id on t(id);
CREATE INDEX
MogDB=# INSERT INTO t SELECT num, repeat('ABCD', 8) || num from generate_series(1, 500) as num;
INSERT 0 500
MogDB=# SELECT * FROM t LIMIT 32;
 id |                 a
----+------------------------------------
  1 | ABCDABCDABCDABCDABCDABCDABCDABCD1
  2 | ABCDABCDABCDABCDABCDABCDABCDABCD2
  3 | ABCDABCDABCDABCDABCDABCDABCDABCD3
 ......
 32 | ABCDABCDABCDABCDABCDABCDABCDABCD32
(32 rows)

# View the contents of the heap data table
MogDB=# SELECT * FROM heap_page_items(get_raw_page('t','main',0));
 lp  | lp_off | lp_flags | lp_len | t_xmin | t_xmax | t_field3 | t_ctid  | t_infomask2 | t_infomask | t_hoff | t_bits | t_oid
-----+--------+----------+--------+--------+--------+----------+---------+-------------+------------+--------+--------+-------
   1 |   8128 |        1 |     62 |  14111 |      0 |        0 | (0,1)   |           2 |       2306 |     24 |        |
   2 |   8064 |        1 |     62 |  14111 |      0 |        0 | (0,2)   |           2 |       2306 |     24 |        |
   3 |   8000 |        1 |     62 |  14111 |      0 |        0 | (0,3)   |           2 |       2306 |     24 |        |
   4 |   7936 |        1 |     62 |  14111 |      0 |        0 | (0,4)   |           2 |       2306 |     24 |        |
   5 |   7872 |        1 |     62 |  14111 |      0 |        0 | (0,5)   |           2 |       2306 |     24 |        |

# View header information on a heap page
MogDB=# SELECT * FROM page_header(get_raw_page('t','main',0));
    lsn    | tli | flags | lower | upper | special | pagesize | version | prune_xid
-----------+-----+-------+-------+-------+---------+----------+---------+-----------
 0/C4DC510 |   0 |     0 |   516 |   576 |    8192 |     8192 |       6 |     14108
(1 row)

# View meta page information
MogDB=# SELECT * FROM bt_metap('idx_id');
 magic  | version | root | level | fastroot | fastlevel
--------+---------+------+-------+----------+-----------
 340322 |       2 |    3 |     1 |        3 |         1
(1 row)

# View the contents of the specified index page number
MogDB=# SELECT * FROM bt_page_items('idx_id', 1);
 itemoffset |  ctid   | itemlen | nulls | vars |          data
------------+---------+---------+-------+------+-------------------------
          1 | (3,9)   |      16 | f     | f    | 6e 01 00 00 00 00 00 00
          2 | (0,1)   |      16 | f     | f    | 01 00 00 00 00 00 00 00
          3 | (0,2)   |      16 | f     | f    | 02 00 00 00 00 00 00 00
          4 | (0,3)   |      16 | f     | f    | 03 00 00 00 00 00 00 00
          5 | (0,4)   |      16 | f     | f    | 04 00 00 00 00 00 00 00

pagehack

# As in the previous example, the MogDB database instance has generated a row-store table/BTree index data file, and the data has been written to the file (if there is no disk you can force a checkpoint or create another table and insert data to make the transaction move forward).
# Get object OID
MogDB=# \d+
                                    List of relations
 Schema | Name | Type  | Owner  | Size  |             Storage              | Description
--------+------+-------+--------+-------+----------------------------------+-------------
 public | t    | table | omm    | 72 kB | {orientation=row,compression=no} |
(1 row)

MogDB=# \d+ t
                           Table "public.t"
 Column |  Type   | Modifiers | Storage  | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
 id     | integer |           | plain    |              |
 a      | text    |           | extended |              |
Indexes:
    "idx_id" btree (id) TABLESPACE pg_default
Has OIDs: no
Options: orientation=row, compression=no

# Upon querying, table t has oid=17092 and index idx_id has oid=17098
MogDB=# select pg_relation_filepath('t');
 pg_relation_filepath
----------------------
 base/15318/17092
(1 row)

MogDB=# select pg_relation_filepath('idx_id');
 pg_relation_filepath
----------------------
 base/15318/17098
(1 row)

# Execute the following command at the command line to parse the heap data of the row-store table
[omm@mogdb-kernel-001 toolkits]$ pagehack -f /opt/mogdb/data/base/15318/17092 | head -n 32
page information of block 0/5
        pd_lsn: 0/C4DC510
        pd_checksum: 0xB4FA, verify success
        pd_flags:
        pd_lower: 516, non-empty
        pd_upper: 576, old
        pd_special: 8192, size 0
        Page size & version: 8192, 6
        pd_xid_base: 14108, pd_multi_base: 0
        pd_prune_xid: 14108

        Heap tuple information on this page

                Tuple #1 is normal: length 62, offset 8128
                        t_xmin/t_xmax/t_cid: 14111/0/0
                        ctid:(block 0/0, offset 1)
                        t_infomask: HEAP_HASVARWIDTH HEAP_XMIN_COMMITTED HEAP_XMAX_INVALID HEAP_HAS_NO_UID
                        t_infomask2: Attrs Num: 2
                        t_hoff: 24
                        t_bits:
                                NNNNNNNN


                Tuple #2 is normal: length 62, offset 8064
                        t_xmin/t_xmax/t_cid: 14111/0/0
                        ctid:(block 0/0, offset 2)
                        t_infomask: HEAP_HASVARWIDTH HEAP_XMIN_COMMITTED HEAP_XMAX_INVALID HEAP_HAS_NO_UID
                        t_infomask2: Attrs Num: 2
                        t_hoff: 24
                        t_bits:
                                NNNNNNNN

# Parsing data from BTree indexes
[omm@mogdb-kernel-001 toolkits]$ pagehack -f /opt/mogdb/data/base/15318/17098 | head -n 32
page information of block 0/4
        pd_lsn: 0/C4EBD58
        pd_checksum: 0xF9AA, verify success
        pd_flags:
        pd_lower: 48, non-empty
        pd_upper: 8168, old
        pd_special: 8168, size 24
        Page size & version: 8192, 5
        pd_xid_base: 8590274914, pd_multi_base: 4294967299
        pd_prune_xid: 8590274914

        Heap tuple information on this page

                Tuple #1 is redirected: length 2, offset 12642
                Tuple #2 is unused

                Tuple #3 is unused

                Tuple #4 is unused

                Tuple #5 is unused

                Tuple #6 is unused
        Summary (6 total): 5 unused, 0 normal, 0 dead

Normal Heap Page, special space is 0

page information of block 1/4
        pd_lsn: 0/C4EBD58
        pd_checksum: 0x95F3, verify success
        pd_flags:
        pd_lower: 1488, non-empty
Copyright © 2011-2024 www.enmotech.com All rights reserved.