PostgreSQL查找配置文件位置、数据所在目录

方案一、用数据库的超级用户登录数据库,使用查询语句查询

# su - postgres # 这里是切换到操作系统的postgres用户
$ psql # 缺省用户名的情况下,会把当前系统用户名当作数据库登录用户名,数据库的postgres是超级用户
psql (13.2 (Ubuntu 13.2-1.pgdg18.04+1))
Type "help" for help.

postgres=# show config_file; -- 查询配置文件所在位置
               config_file               
-----------------------------------------
 /etc/postgresql/13/main/postgresql.conf
(1 row)

postgres=# show data_directory; -- 查询数据储存目录
      data_directory      
--------------------------
 /data/postgresql/13/main
(1 row)

方案二、使用操作系统root用户查找postgresql进程

# ps -ef|grep postgresql
postgres 23746     1  0 Aug31 ?        00:04:40 /usr/lib/postgresql/13/bin/postgres -D /data/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf

可以看到-D后面的参数即为数据目录,-c后面的参数即为配置文件所在位置。


转自:https://blog.csdn.net/DongGeGe214/article/details/121489384