psa
psa

Reputation: 27

Saving PostgreSQL database to an external HDD

I need to save a database to an external HDD. This question has been asked previously here. However, upon changing the data_directory variable in the postgresql.conf file that exists in /usr/local/var/postgres/ to

data_directory = /path/to/externalHDD/directory/

I then restart the PostgreSQL server with brew services restart postgresql, but when I try to reconnect to the database via

psql -U username -d postgres

I receive the following error:

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

How do I fix this?

Upvotes: 1

Views: 1661

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246688

If all you did was point data_directory somewhere else, that cannot work, because there is no data directory at the destination. You have to create the data directory using initdb.

Upvotes: 2

Related Questions