【问题标题】:Is there any way migrate postgresql db without pg_dump?有没有办法在没有 pg_dump 的情况下迁移 postgresql db?
【发布时间】:2018-05-11 07:17:47
【问题描述】:

原来的postgres服务器是在ubuntu上运行的,但是机器死机无法启动。

我尝试在安装了 postgres 的 Ubuntu 上安装磁盘,然后将 data_directory 更改为我安装的原始 data_directoty 的路径,但失败了。 当我运行systemctl start postgresql 时没有错误消息,但是当我尝试使用 psql 登录时,它显示

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

服务器似乎没有打开。我该如何解决?

或者有没有其他方法可以在不启动原机的情况下获取数据库?

【问题讨论】:

  • 如果使用相同的数据库版本,应该可以从原来的data_directory恢复。如果不能,则会出现错误消息。您需要找出该服务器无法启动的原因。
  • 试试pg_ctl -D data_directory?..
  • 在您执行任何操作之前,对该卷及其上的数据库进行完整备份。
  • 我运行systemctl start postgresql时的日志是2018-05-11 07:53:45 UTC [29628-2] LOG: received smart shutdown request 2018-05-11 07:53:45 UTC [29633-2] LOG: autovacuum launcher shutting down 2018-05-11 07:53:45 UTC [29630-1] LOG: shutting down 2018-05-11 07:53:45 UTC [29630-2] LOG: database system is shut down
  • 检查服务器是否正在运行(ps -f -u postgres)。

标签: linux postgresql crash database-backups


【解决方案1】:

我找到了问题,

  1. data_directory 的权限应该 是 700,但我设置为 777
    sudo chmod -R <data_dir> 700
  2. data_directory 的所有者应该是 postgres
    sudo chown -R postgres:postgres <data_dir>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    相关资源
    最近更新 更多