移动 postgresql 数据目录

Jan*_*ora 5 postgresql linux ubuntu

我按照以下步骤移动了 postgresql 的数据目录:

  1. 停止 postgres
  2. cp -a 源数据目录 目标数据目录
  3. 导出 PGDATA=destination_data_directory
  4. 将 postgresql.conf 中的数据目录更改为destination_data_directory
  5. pg_ctl开始

但是当我运行:“pg_ctl start”时,出现以下错误。有人可以帮我找出错误吗?

服务器启动 postgres@Server:/usr/lib/postgresql/9.1/bin$ postgres 无法访问服务器配置文件“/home/destination_data_directory/postgresql.conf”:没有这样的文件或目录

小智 1

首先确保该文件确实存在于该位置。如果环境变量中有错误,请运行ls $PGDATA,您将看到错误的文件或因路径不存在而收到错误。

然后确保父目录/home/destination_data_directory及其下所有目录和文件的所有者与您启动 pg_ctl 的用户相匹配。如果他们都不使用

su postgres_user
Run Code Online (Sandbox Code Playgroud)

在运行 pg_ctl 之前切换到正确的用户或使用

chown -R postgres_user /home/destination_data_directory
Run Code Online (Sandbox Code Playgroud)

更改目录及其下所有内容的所有者。