PostgreSQL data directory structure

Introduction root directory

data
├── base                  # use to store database file(SELECT oid, datname FROM pg_database;)
├── global                # under global, all the filenode is hard-code(select oid,relname,relfilenode from pg_class where relfilenode=0 order by oid;)
├── pg_clog               # dir of transaction commit log
│   └── 0000
├── pg_commit_ts
├── pg_dynshmem
├── pg_hba.conf           # client authentication config file
├── pg_ident.conf         # user ident map file
├── pg_logical
│   ├── mappings
│   └── snapshots
├── pg_multixact
│   ├── members
│   │   └── 0000
│   └── offsets
│       └── 0000
├── pg_notify
│   └── 0000
├── pg_replslot
├── pg_serial
├── pg_snapshots         # dir of snapshot file
├── pg_stat
├── pg_stat_tmp          # dir of tmp stat file
│   ├── db_0.stat
│   ├── db_12407.stat
│   ├── db_16384.stat
│   └── global.stat
├── pg_subtrans
│   └── 0000
├── pg_tblspc
├── pg_twophase
├── PG_VERSION           # version file
├── pg_xlog              # dir of xlog file
│   ├── 000000010000000000000001
│   └── archive_status   # status info of xlog archive
├── postgresql.auto.conf
├── postgresql.conf      # config file of postmaster progress
├── postmaster.opts
└── postmaster.pid       # pid file of postmaster progress

global catalog description

global name implies meaning, file storage for storing global system table information and global control information.

There are four files in the global:

  1. pg_control
    used for global control information
  2. pg_filenode.map
    for the OID in the current directory system tables with specific file names are hard-coded maps (also under the same name for each database file directory created by the user).
  3. pg_internal.init
    for caching system tables, system tables to speed up the read speed (also under the same name for each database file directory created by the user).
  4. Global system table file
    digital file named for content storage system tables. They relfilenode pg_class entry are 0, depending on pg_filenode.map file with the OID hard-coded map. (Note: Not all relfilenode system tables 0)
data
├── global                # under global, all the filenode is hard-code(select oid,relname,relfilenode from pg_class where relfilenode=0 order by oid;)
│   ├── 1136              # pg_pltemplate
│   ├── 1137              # pg_pltemplate_name_index
│   ├── 1213              # pg_tablespace
│   ├── 1214              # pg_shdepend
│   ├── 1232              # pg_shdepend_depender_index
│   ├── 1233              # pg_shdepend_reference_index
│   ├── 1260              # pg_authid
│   ├── 1261              # pg_auth_members
│   ├── 1262              # pg_database
│   ├── 2396              # pg_shdescription
│   ├── 2397              # pg_shdescription_o_c_index
│   ├── 2671              # pg_database_datname_index
│   ├── 2672              # pg_database_oid_index
│   ├── 2676              # pg_authid_rolname_index
│   ├── 2677              # pg_authid_oid_index
│   ├── 2694              # pg_auth_members_role_member_index
│   ├── 2695              # pg_auth_members_member_role_index
│   ├── 2697              # pg_tablespace_oid_index
│   ├── 2698              # pg_tablespace_spcname_index
│   ├── 2846              # pg_toast_2396
│   ├── 2847              # pg_toast_2396_index
│   ├── 2964              # pg_db_role_setting
│   ├── 2965              # pg_db_role_setting_databaseid_rol_index
│   ├── 2966              # pg_toast_2964
│   ├── 2967              # pg_toast_2964_index
│   ├── 3592              # pg_shseclabel
│   ├── 3593              # pg_shseclabel_object_index
│   ├── 4060              # pg_toast_3592x
│   ├── 4061              # pg_toast_3592_index
│   ├── 6000              # pg_replication_origin
│   ├── 6001              # pg_replication_origin_roiident_index
│   ├── 6002              # pg_replication_origin_roname_index
│   ├── pg_control        # global control file, use pgcheck -pc to see it.
│   ├── pg_filenode.map   # system table (oid -> filenode) mapping file, use pgcheck -pm to see it.
│   └── pg_internal.init  # system table cache file, use pgcheck -pr to see it.

base catalog description

base directory used to store files in the database of all entities. For example, we created the first library testdb the OID is 16384, it will produce data files in a directory named 16384 for storing testdb in the data / base.

testdb=# select oid,datname from pg_database;
  oid  |  datname
-------+-----------
 12407 | postgres
 16384 | testdb
     1 | template1
 12406 | template0
(4 rows)

base directory structure

data
├── base                  # use to store database file(SELECT oid, datname FROM pg_database;)
│   ├── 1                 # template database
│   ├── 12406             # template0 database
│   ├── 12407             # postgres database
│   └── 16384             # testdb, first user database │ │ ├── 3600 │ │ ├── 3600_fsm │ │ ├── 3600_vm │ │ ├── 16385 │ │ ├── pg_filenode.map │ │ ├── pg_internal.init │ │ └── PG_VERSION 
  1. pg_filenode.map is pg_class entry system tables relfilenode 0, hard-coded mapping file and OID.
  2. pg_internal.init is a system table of cache files, used to speed read. There is no default, automatically generated after query the system tables.
  3. PG_VERSION database is a data format corresponding to the current version number
  4. Other files that need to be found in the corresponding relfilenode pg_class according OID to match the file name.
    For example: relfilenode tab1 is 16385, then 16385 tab1 this file is a data file
    testdb=# select oid,relfilenode,relname from pg_class where relname='tab1';
      oid  | relfilenode | relname
    -------+-------------+---------
     16385 |       16385 | tab1
    (1 row) 
  1. Free space map
    names to files ending _fsm data file corresponding FSM (free space map) file, a way to identify which block map are idle. Byte instead of using a bit to identify a block. For an N-byte block, the value of that byte blknum _fsm recorded in the file is (31 + N) / 32. A block number identifying idle bytes in this way. FSM is not a simple array, but a three-layer tree structure. FSM file is where it is used only when auto generated.
  2. Visibility map file
    names to the end of the file is a data file _vm corresponding VM (visibility map). PostgreSQL in doing multi-version concurrency control is achieved by the tuple head logo "is invalid" deleted or updated, and finally to clean up the invalid data reclaim free space by VACUUM function. On the use of VM open when doing VACUUM Quick Search block contains invalid tuple. VM is only a simple bitmap, a bit corresponding to a block.

Note: The system tables into the global system tables and library-level system tables.
The global table is a global system, for example: Table pg_database, pg_tablespace, pg_auth_members such a storage system level object.
Library level system located in the database catalog table, for example: Table pg_type, pg_proc, pg_attribute this object class repository.
It is noteworthy that pg_class located in the library's catalog level, but also contains the global system table information, research and development or operation and maintenance personnel when changes in the global system tables that require attention.

Table space Contents Introduction

testdb=# select oid,* from pg_tablespace;
  oid  |  spcname   | spcowner | spcacl | spcoptions
-------+------------+----------+--------+------------
  1663 | pg_default |       10 |        |
  1664 | pg_global  |       10 |        |
 49162 | dbspace    |       10 |        |
(3 rows)

Each Oid corresponds to a file named Oid soft link in the data / pg_tblspc, pointing to the real space directory.

 tree ../data/pg_tblspc/
../data/pg_tblspc/
└── 49162 -> /home/postgres/postgresql-9.6.6/postgres/data/dbspace

In the space directory is how to organize it?

testdb=# create table tab3(a int) tablespace dbspace;
CREATE TABLE

testdb=# select oid,relname,relfilenode from pg_class where relname='tab3';
  oid  | relname | relfilenode
-------+---------+-------------
 57351 | tab3 | 57351 (1 row) tree ../data/pg_tblspc/49162 ../data/pg_tblspc/49162 └── PG_9.6_201608131 └── 16384 └── 57351 


Author: leapking
link: https: //www.jianshu.com/p/cd8c5b988e52
Source: Jane books

Guess you like

Origin www.cnblogs.com/xibuhaohao/p/11103783.html