简体   繁体   中英

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. The folder it's stored in was the data directory of my PostgreSQL instance on my Ubuntu machine, everything worked fine. I don't have access to this Ubuntu machine anymore, and this will last for a few months, but I have the external drive. I'm working under macOS 14.6 in the meantime. I setup PostgreSQL on my Mac using the Postgres.app. 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:

data_directory = 'path_to_external_HDD_data_directory'      

Note that this is all I changed in the.conf file (should I change anything else?). When I try to connect to the server via Postgres.app, I get the following error:

pg_ctl: server did not start in time

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. Running lsof -n -i4TCP:5432 , I see that postgres is listening. I killed it and retried but got the same pg_ctl error. 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 .

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).

If the server starts, it is by coincidence. Connecting might work, but it might just as well corrupt your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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