Search code examples
postgresqlrelational-databaseinternals

How to open postgresql heap file


I want to check how files, where PostgreSQL stores data from tables, are stored, for educational purposes. How can I do it?

I tried open it with notepad, but structure is corupt database heap file. "How should I open this file so that it is structured in a normal page view as:

 * +----------------+---------------------------------+
 * | PageHeaderData | linp1 linp2 linp3 ...           |
 * +-----------+----+---------------------------------+
 * | ... linpN |                                      |
 * +-----------+--------------------------------------+
 * |           ^ pd_lower                             |
 * |                                                  |
 * |             v pd_upper                           |
 * +-------------+------------------------------------+
 * |             | tupleN ...                         |
 * +-------------+------------------+-----------------+
 * |       ... tuple3 tuple2 tuple1 | "special space" |
 * +--------------------------------+-----------------+ 

Solution

  • These files are binary files, not text files. That image is just a conceptual drawing. You'd need a hex editor to look at the data, but if you want to see them presented in human readable form, you should use the functions in the pageinspect extension, in particular the heap_page_items() and heap_page_item_attrs() functions.