简体   繁体   English

将 PostgreSQL 数据目录更改为 PostgresSQL 在另一台机器上创建的目录

[英]Change PostgreSQL data directory to directory created by PostgresSQL on another machine

I have a database stored on an external hard drive.我有一个存储在外部硬盘驱动器上的数据库。 The database was created using PostgreSQL 11, on an Ubuntu 18.04 machine.该数据库是在 Ubuntu 18.04 机器上使用 PostgreSQL 11 创建的。 The folder it's stored in was the data directory of my PostgreSQL instance on my Ubuntu machine, everything worked fine.它存储的文件夹是我的 Ubuntu 机器上我的 PostgreSQL 实例的数据目录,一切正常。 I don't have access to this Ubuntu machine anymore, and this will last for a few months, but I have the external drive.我无法再访问这台 Ubuntu 机器,这将持续几个月,但我有外部驱动器。 I'm working under macOS 14.6 in the meantime.我同时在 macOS 14.6 下工作。 I setup PostgreSQL on my Mac using the Postgres.app.我使用 Postgres.app 在我的 Mac 上设置了 PostgreSQL。 I created a new server, making sure to use version 11. The defaut data directory was of course not the one I want, so I changed its path in postgresql.conf to point to my existing data dir:我创建了一个新服务器,确保使用版本 11。默认数据目录当然不是我想要的,所以我在 postgresql.conf 中更改了它的路径以指向我现有的数据目录:

data_directory = 'path_to_external_HDD_data_directory'      

Note that this is all I changed in the.conf file (should I change anything else?).请注意,这是我在 .conf 文件中所做的全部更改(我还应该更改其他内容吗?)。 When I try to connect to the server via Postgres.app, I get the following error:当我尝试通过 Postgres.app 连接到服务器时,我收到以下错误:

pg_ctl: server did not start in time pg_ctl: 服务器没有及时启动

And the log is:日志是:

2019-10-21 22:06:47.628 CEST [72547] LOG:  listening on IPv6 address "::1", port 5432
2019-10-21 22:06:47.629 CEST [72547] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2019-10-21 22:06:47.654 CEST [72547] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2019-10-21 22:06:47.742 CEST [72548] LOG:  database system was interrupted; last known up at 2019-10-21 22:00:07 CEST
2019-10-21 22:06:58.263 CEST [72548] LOG:  database system was not properly shut down; automatic recovery in progress
2019-10-21 22:06:58.266 CEST [72548] LOG:  redo starts at 4A/B2804E40
2019-10-21 22:06:58.266 CEST [72548] LOG:  invalid record length at 4A/B2804E78: wanted 24, got 0
2019-10-21 22:06:58.266 CEST [72548] LOG:  redo done at 4A/B2804E40
2019-10-21 22:06:58.314 CEST [72547] LOG:  database system is ready to accept connections

Postgres.app then tells me that the port is in use. Postgres.app 然后告诉我该端口正在使用中。 Running lsof -n -i4TCP:5432 , I see that postgres is listening.运行lsof -n -i4TCP:5432 ,我看到 postgres 正在监听。 I killed it and retried but got the same pg_ctl error.我杀了它并重试,但得到了相同的 pg_ctl 错误。 Any idea of what I can do?知道我能做什么吗?

Your server started successfully.您的服务器已成功启动。 You don't use pg_ctl to connect to PostgreSQL, but the command line client psql .您不使用pg_ctl连接到 PostgreSQL,而是使用命令行客户端psql

Anyway, you should stop what you are doing right now before any damage is done.无论如何,在造成任何损害之前,你应该停止你现在正在做的事情。

It is not supported to use a PostgreSQL data directory created with one architecture (Linux) on a different architecture (MacOS).支持使用在不同架构 (MacOS) 上使用一种架构 (Linux) 创建的 PostgreSQL 数据目录。

If the server starts, it is by coincidence.如果服务器启动,那是巧合。 Connecting might work, but it might just as well corrupt your database.连接可能会起作用,但它也可能会破坏您的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM