在 fedora 22 中移动 postgresql 9.4 数据目录

Moving postgresql 9.4 data directory in fedora 22

我想知道如何在 Fedora 22 安装中移动 PostgreSQL 数据库目录。在 Ubuntu 中,使用 pg_dropclustersudo pg_createcluster -d /the/new/location/ 9.4 main 非常简单,但 Fedora 似乎没有此类功能。

我将目录 /var/lib/pgsql/data 复制到一个新位置,并执行了以下操作:

su - postgres
service postgresql stop
export PGDATA="/the/new/location/"
echo $PGDATA # gives the correct /the/new/location/
service postgresql start
psql
show data_directory;

这仍然导致默认 /var/lib/pgsql/data...

有人可以提供 link 相关的最新教程或解释如何完成移动吗?

注意:我知道其他发行版和旧版本的 Fedora 和 Psql 已经回答了这个问题,但似乎很多文件都被移动了,none 的方法似乎为我工作。

原来这个方法已经过时了。正确的做法是添加此文件 nano /etc/systemd/system/postgresql.service:

.include /lib/systemd/system/postgresql.service
[Service]
Environment=PGDATA=/the/new/location/

我相信这也需要重新启动。

之后还需要正确设置SELinux,PostgreSQL才能启动