PostgreSQL查看數據目錄總結


PostgreSQL數據庫中,如何查看PostgreSQL的數據目錄呢? 測試驗證了一下,大概有下面幾種方法:

 

方法1

 

postgres=# show data_directory;
      data_directory       
---------------------------
 /home/postgres/pgsql_data
(1 row)

 

方法2

 

postgres=# select setting from pg_settings where name='data_directory';
          setting          
---------------------------
 /home/postgres/pgsql_data
(1 row)

 

clip_image001

 

方法3

 

postgresql.conf文件中查看,但是這種方式有可能無法獲取到數據目錄的配置,因為在有些情況下,可能在postgresql.conf中沒有配置data_directory參數

 

# grep data_directory postgresql.conf

 

方法4

 

ps命令查看,如下你會看到參數-D后面的值就是PostgreSQL的數據目錄。

 

[root@KerryDB ~]# ps -ef | grep postgres | grep -v postgres:
postgres 22998     1  0 Jan06 ?        00:00:01 /home/postgres/pgsql/bin/postgres -D /home/postgres/pgsql_data
root     26737 26692  0 11:36 pts/0    00:00:00 su - postgres
postgres 26738 26737  0 11:36 pts/0    00:00:00 -bash
postgres 26766 26738  0 11:36 pts/0    00:00:00 /bin/bash /home/postgres/pgsql/bin/psql
postgres 26768 26766  0 11:36 pts/0    00:00:00 /home/postgres/pgsql/bin/psql.bin
root     27413 26788  0 11:45 pts/1    00:00:00 grep --color=auto postgres
[root@KerryDB ~]# ps ax | grep postgres | grep -v postgres:
 7154 pts/3    S      0:00 su - postgres
 7182 pts/3    T      0:00 /bin/bash /home/postgres/pgsql/bin/psql
 7184 pts/3    T      0:00 /home/postgres/pgsql/bin/psql.bin
 7506 pts/3    S+     0:00 /bin/bash /home/postgres/pgsql/bin/psql
 7508 pts/3    S+     0:00 /home/postgres/pgsql/bin/psql.bin
 7903 pts/0    S+     0:00 grep --color=auto postgres
22998 ?        S      0:00 /home/postgres/pgsql/bin/postgres -D /home/postgres/pgsql_data

其實最簡單的方法就是這個命令

 

[root@KerryDB ~]#  ps -ax | grep postgres | grep "\-D"
22998 ?        S      0:01 /home/postgres/pgsql/bin/postgres -D /home/postgres/pgsql_data

 

方法5

 

查看環境變量PGDATA。在傳統上,數據庫集簇所使用的配置和數據文件都被一起存儲在集簇的數據目錄里,通常用PGDATA來引用(用的是可以定義它的環境變量的名字)。PGDATA的一個常見位置是/var/lib/pgsql/data。由不同數據庫實例所管理的多個集簇可以在同一台機器上共存。PGDATA目錄包含幾個子目錄以及一些控制文件。

 

$ echo $PGDATA
/var/lib/pgsql/9.5/data

 

注意:如果沒有配置變量PGDATA的話,這種方式也是不行的。

 

[postgres@KerryDB ~]$ echo $PGDATA


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM