【PostgreSQL】关于文件
首先
在PostgreSQL中,被称为数据库集群的目录将创建以下所需的文件。本次我们将深入理解这些目录和文件。
数据库集群的配置
数据库集群的构成如下:
-bash-4.2$ pwd
/var/lib/pgsql/11/data
-bash-4.2$ ll
合計 64
-rw-------. 1 postgres postgres 3 1月 18 2023 PG_VERSION
drwx------. 6 postgres postgres 58 6月 13 17:26 base
-rw-------. 1 postgres postgres 30 12月 4 14:07 current_logfiles
drwx------. 2 postgres postgres 4096 12月 4 14:07 global
drwx------. 2 postgres postgres 188 1月 24 2023 log
drwx------. 2 postgres postgres 6 1月 18 2023 pg_commit_ts
drwx------. 2 postgres postgres 6 1月 18 2023 pg_dynshmem
-rw-------. 1 postgres postgres 4267 1月 23 2023 pg_hba.conf
-rw-------. 1 postgres postgres 1636 1月 18 2023 pg_ident.conf
drwx------. 4 postgres postgres 68 12月 4 14:07 pg_logical
drwx------. 4 postgres postgres 36 1月 18 2023 pg_multixact
drwx------. 2 postgres postgres 18 12月 4 14:07 pg_notify
drwx------. 2 postgres postgres 6 1月 18 2023 pg_replslot
drwx------. 2 postgres postgres 6 1月 18 2023 pg_serial
drwx------. 2 postgres postgres 6 1月 18 2023 pg_snapshots
drwx------. 2 postgres postgres 6 11月 16 14:44 pg_stat
drwx------. 2 postgres postgres 25 12月 4 14:08 pg_stat_tmp
drwx------. 2 postgres postgres 18 1月 18 2023 pg_subtrans
drwx------. 2 postgres postgres 6 1月 11 1957 pg_tblspc
drwx------. 2 postgres postgres 6 1月 18 2023 pg_twophase
drwx------. 3 postgres postgres 4096 10月 18 16:24 pg_wal
drwx------. 2 postgres postgres 18 1月 18 2023 pg_xact
-rw-------. 1 postgres postgres 88 1月 18 2023 postgresql.auto.conf
-rw-------. 1 postgres postgres 24007 11月 16 14:44 postgresql.conf
-rw-------. 1 postgres postgres 58 12月 4 14:07 postmaster.opts
-rw-------. 1 postgres postgres 103 12月 4 14:07 postmaster.pid
可以使用PGDATA命令将数据目录切换到/var/lib/pgsql/data。
命令为cd $PGDATA。
命令为cd $PGDATA。
关于目录和文件
我們將總結目錄和文件各自的用途。
关于目录
baseディレクトリ
PostgreSQLが管理する各データベースの物理的なデータファイルが格納される
各データベースは、baseディレクトリ内の独自のサブディレクトリにデータを保持している。サブディレクトリは、データベースのOID(オブジェクト識別子)によって命名される。以下のようなファイルを格納する。
テーブルファイル
インデックスファイル
TOASTデータ
システムカタログ
globalディレクトリ
データベースクラスタ全体に共通のシステム情報を格納する。以下のファイルが格納される。
システムカタログ
トランザクションログ
設定ファイル
pg_walディレクトリ
WALファイルを格納するディレクトリ
pg_xactディレクトリ
トランザクションのコミットログを格納する
pg_tblspcディレクトリ
テーブルスペースへのシンボリックシンクを格納する
テーブルスペースとは、データベースオブジェクトを保存するための物理的な場所を定義する概念。
关于文件
-
- PG_VERSIONファイル
- PostgreSQLのメジャーバージョン番号が書き込まれているテキストファイル。
cat PG_VERSION
11
-
- テーブルファイル
-
- テーブルデータの実態が格納されているファイル
- 8192バイトのページで管理されている
ll base/13881/
合計 15184
-rw-------. 1 postgres postgres 8192 1月 18 2023 112
-rw-------. 1 postgres postgres 8192 1月 18 2023 113
-rw-------. 1 postgres postgres 98304 10月 18 14:53 1247
-rw-------. 1 postgres postgres 24576 10月 18 14:18 1247_fsm
-rw-------. 1 postgres postgres 8192 1月 24 2023 1247_vm
インデックスファイル
インデックスの情報が格納されているファイル
8192バイトのページで管理されている
TOASTファイル
長大な行を格納する場合に生成される特殊なファイル。
Free Space Mapファイル
空き領域を追跡するための情報が格納されたファイル。
ll base/13881/
合計 15184
-rw-------. 1 postgres postgres 8192 1月 18 2023 112
-rw-------. 1 postgres postgres 8192 1月 18 2023 113
-rw-------. 1 postgres postgres 98304 10月 18 14:53 1247
-rw-------. 1 postgres postgres 24576 10月 18 14:18 1247_fsm # Free Space Mapファイル
-rw-------. 1 postgres postgres 8192 1月 24 2023 1247_vm
-
- Visibility Mapファイル
- テーブルの可視性を管理するファイル
ll base/13881/
合計 15184
-rw-------. 1 postgres postgres 8192 1月 18 2023 112
-rw-------. 1 postgres postgres 8192 1月 18 2023 113
-rw-------. 1 postgres postgres 98304 10月 18 14:53 1247
-rw-------. 1 postgres postgres 24576 10月 18 14:18 1247_fsm
-rw-------. 1 postgres postgres 8192 1月 24 2023 1247_vm # Visibility Mapファイル
-
- WALファイル
-
- PostgresQLに対して行われた更新操作を記録するファイル。pg_walディレクトリは以下に格納される。
-
- postgresql.confとpg_hba.conf
-
- PostgreSQLの動作を設定するファイル。
-
- postmaster.pid
- PostgreSQLの稼働中に作成されるロックファイルで、データベースクラスタは以下に格納される。
cat postmaster.pid
1210
/var/lib/pgsql/11/data
1701666445
5432
/var/run/postgresql
localhost
5432001 0
ready
总结
通过理解文件目录结构,可以提高数据库的管理和维护效率,因此请务必深入理解。
请参考。
学习 PostgreSQL 的内部结构 – 设计和运维计划的不可或缺之规则