即使我已经更改,仍然位于默认数据目录postgreSQL



我在centOs7服务器上新安装了postgreSQL,并希望在服务器上将默认的postgreSQL数据目录更改为/opt/postgres。这就是我所做的:

# chown postgres:postgres /opt/postgres
# chmod 700 /opt/postgres

接下来,我使用rsync命令将默认数据目录转移到新位置

# rsync -av /var/lib/pgsql/11/data /opt/postgres

然后我删除了默认的配置文件,因为在另一个教程中说它会崩溃,因为postgres只监听默认的文件夹配置。此处

以及我更新/var/lib/pgsql/11/data/postgresql.conf配置文件的data_directory变量以指向新的my-data目录的最后一种方式。

# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.
data_directory = '/opt/postgres/data'         # use data in another directory

最后,我启动了postgresql-11服务,我看到我的postgres数据目录仍然位于默认数据中

[root@soa-forwarder postgres]# su - postgres
Last login: Tue Sep 29 23:48:52 WIB 2020 on pts/3
-bash-4.2$ psql
psql (11.9)
Type "help" for help.
postgres=# show data_directory;
data_directory
------------------------
/var/lib/pgsql/11/data
(1 row)
postgres=#

我一直在尝试重新启动数据库,但仍然没有更改。我必须重新初始化数据库吗?

仅在postgresql.conf中更改data_directory不会有任何作用。首先,启动过程必须找到包含postgresql.conf的目录,然后才能读取文件以确定数据目录的位置。

因此,您必须重新配置启动过程,以便查找正确的目录。在针对CentOS的PGDG包的情况下,这意味着用另一个具有的服务文件覆盖服务文件

Environment=PGDATA=/opt/postgres

在CCD_ 4部分中。

最新更新