PostgreSql之文件目录结构

2,643 阅读5分钟

这是我参与新手入门的第3篇文章。

安装完成后,再来看看它有哪些东西吧~

  • 从环境变量里看它涉及的目录
export PGHOME=/usr/local/pgsql/
export PGUSER=postgres
export PGPORT=5432
export PGDATA=/app/pgsql/data
export PGLOG=/app/pgsql/log/postgres.log
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
PATH=/usr/local/pgsql/bin:$PATH
export PATH

软件安装目录

/usr/local/pgsql/ 相当于oracle的 /app/oracle 软件安装目录,psql、pg_ctl等软件可执行的一些命令都在这下面。


[postgres@yuan ~]$ cd /usr/local/pgsql/
[postgres@yuan pgsql]$ ll
total 16
drwxr-xr-x 2 root root 4096 Jul  9 17:54 bin
drwxr-xr-x 6 root root 4096 Jul  9 17:54 include
drwxr-xr-x 4 root root 4096 Jul  9 17:54 lib
lrwxrwxrwx 1 root root   26 Jul  9 17:56 postgresql-12.4 -> /usr/local/postgresql-12.4
drwxr-xr-x 6 root root 4096 Jul  9 17:54 share
[postgres@yuan pgsql]$ cd bin
[postgres@yuan bin]$ ll
total 12348
-rwxr-xr-x 1 root root   73808 Jul  9 17:54 clusterdb
-rwxr-xr-x 1 root root   73552 Jul  9 17:54 createdb
-rwxr-xr-x 1 root root   78416 Jul  9 17:54 createuser
-rwxr-xr-x 1 root root   68944 Jul  9 17:54 dropdb
-rwxr-xr-x 1 root root   68920 Jul  9 17:54 dropuser
-rwxr-xr-x 1 root root  975928 Jul  9 17:54 ecpg
-rwxr-xr-x 1 root root  142520 Jul  9 17:54 initdb
-rwxr-xr-x 1 root root   44344 Jul  9 17:54 pg_archivecleanup
-rwxr-xr-x 1 root root  130528 Jul  9 17:54 pg_basebackup
-rwxr-xr-x 1 root root  172512 Jul  9 17:54 pgbench
-rwxr-xr-x 1 root root   66984 Jul  9 17:54 pg_checksums
-rwxr-xr-x 1 root root   42880 Jul  9 17:54 pg_config
-rwxr-xr-x 1 root root   61376 Jul  9 17:54 pg_controldata
-rwxr-xr-x 1 root root   76888 Jul  9 17:54 pg_ctl
-rwxr-xr-x 1 root root  422888 Jul  9 17:54 pg_dump
-rwxr-xr-x 1 root root  109376 Jul  9 17:54 pg_dumpall
-rwxr-xr-x 1 root root   73064 Jul  9 17:54 pg_isready
-rwxr-xr-x 1 root root   93208 Jul  9 17:54 pg_receivewal
-rwxr-xr-x 1 root root   93832 Jul  9 17:54 pg_recvlogical
-rwxr-xr-x 1 root root   71256 Jul  9 17:54 pg_resetwal
-rwxr-xr-x 1 root root  187840 Jul  9 17:54 pg_restore
-rwxr-xr-x 1 root root  109784 Jul  9 17:54 pg_rewind
-rwxr-xr-x 1 root root   49216 Jul  9 17:54 pg_test_fsync
-rwxr-xr-x 1 root root   39152 Jul  9 17:54 pg_test_timing
-rwxr-xr-x 1 root root  148952 Jul  9 17:54 pg_upgrade
-rwxr-xr-x 1 root root  103904 Jul  9 17:54 pg_waldump
-rwxr-xr-x 1 root root 8227064 Jul  9 17:53 postgres
lrwxrwxrwx 1 root root       8 Jul  9 17:53 postmaster -> postgres
-rwxr-xr-x 1 root root  615376 Jul  9 17:54 psql
-rwxr-xr-x 1 root root   78032 Jul  9 17:54 reindexdb
-rwxr-xr-x 1 root root   86968 Jul  9 17:54 vacuumdb

数据目录

/app/pgsql/data 相当于oracle建库时指定的数据目录,数据库所需的参数文件,数据文件等均在这下面。

[postgres@yuan include]$ cd /app/pgsql/data
[postgres@yuan data]$ ll
total 60
drwx------ 5 postgres postgres    41 Jul  9 18:02 base
drwx------ 2 postgres postgres  4096 Jul  9 18:06 global
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_commit_ts
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_dynshmem
-rw------- 1 postgres postgres  4789 Jul  9 18:03 pg_hba.conf
-rw------- 1 postgres postgres  1636 Jul  9 18:02 pg_ident.conf
drwx------ 4 postgres postgres    68 Jul  9 18:10 pg_logical
drwx------ 4 postgres postgres    36 Jul  9 18:02 pg_multixact
drwx------ 2 postgres postgres    18 Jul  9 18:05 pg_notify
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_replslot
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_serial
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_snapshots
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_stat
drwx------ 2 postgres postgres    63 Jul  9 20:50 pg_stat_tmp
drwx------ 2 postgres postgres    18 Jul  9 18:02 pg_subtrans
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_tblspc
drwx------ 2 postgres postgres     6 Jul  9 18:02 pg_twophase
-rw------- 1 postgres postgres     3 Jul  9 18:02 PG_VERSION
drwx------ 3 postgres postgres    60 Jul  9 18:02 pg_wal
drwx------ 2 postgres postgres    18 Jul  9 18:02 pg_xact
-rw------- 1 postgres postgres    88 Jul  9 18:02 postgresql.auto.conf
-rw------- 1 postgres postgres 26659 Jul  9 18:03 postgresql.conf
-rw------- 1 postgres postgres    53 Jul  9 18:05 postmaster.opts
-rw------- 1 postgres postgres    74 Jul  9 18:05 postmaster.pid

文件及目录说明:

  • pg_hba.conf:认证配置文件,配置了允许哪些IP访问数据库,及认证方式等信息。
  • pg_ident.conf:"ident"认证方式的用户映射文件。
  • PG_VERSION:记录了数据库版本号信息。
  • postgresql.auto.conf:作用同 postgresql.conf ,优先级高于 postgresql.conf,在数据库中通过alter命令更改的参数记录在此文件中。
  • postgresql.conf:数据库实例主配置文件,基本上所有的数据库参数配置都在此文件中。
  • postmaster.opts:记录数据库启动命令。
  • postmaster.pid:数据库进程文件,数据库启动时被创建,关闭时消失。
  • base:该目录包含数据库用户所创建的各个数据库,同时也包括postgres、template0和template1的pg_defaulttablespace。
  • global:该目录包含集群范围的各个表和相关视图。(pg_database、pg_tablespace)
  • pg_dynshmem:该目录包含动态共享内存子系统使用的文件。
  • pg_commit_ts:该目录包含已提交事务的时间。
  • pg_logical:该目录包含逻辑解码的状态数据。
  • pg_multixact:该目录包含多事务状态数据。(等待锁定的并发事务)
  • pg_notify:该目录包含LISTEN/NOTIFY状态数据。
  • pg_replslot:该目录包含复制槽数据。
  • pg_snapshots:该目录包含导出的快照。
  • pg_stat:该目录包含统计子系统的永久文件。
  • pg_stat_tmp:该目录包含统计子系统的临时文件。
  • pg_subtrans:该目录包含子事务状态数据。
  • pg_tblspc:该目录包含表空间的符号链接。
  • pg_twophase:该目录包含预备事务的状态文件。
  • pg_wal:该目录包含wal日志。
  • pg_xact:该目录包含事务提交状态数据。

日志目录

/app/pgsql/log/ 路径自定义,可在此配置数据库的各种日志,本环境仅配置了数据库启动关闭记录日志。

[postgres@yuan log]$ cd /app/pgsql/log/
[postgres@yuan log]$ ll
total 4
-rw------- 1 postgres postgres 1006 Jul  9 21:21 postgres.log

目前上述文件用到的还比较少,尤其是数据目录里的一些目录,还未深入了解,待我慢慢研究。嗯?什么是快乐星球……