How do I move the postgres database of an phoenix app to a new server?

I want to move an phoenix app to another server.

For that I would like to create a postgres dump and restore the database on the new server.

How would I do that?

I thought about dumping the database:

pg_dump video_page_dev > video_page_dev_backup.sql

restore:
psql dbname < infile

But how do I connect to the running postgres instance?
I tried: psql, but it returns psql: could not connect to server: No such file or directory

This is not at all specific to Elixir or Phoenix. Look at the psql doc for the appropriate arguments to pass.

2 Likes

That error message means that psql has loaded a config file, the config file says the database should be located in a certain place, but its not.

Firstly, make sure the database is actually running, otherwise it won’t be able to connect to it.

Sometimes, you get this error when you have multiple versions of Postgres installed and you’re running a different version of psql to the database. How do you start postgres?

Are you running psql on your local machine, or on the server? If locally, you’ll need to add connection details to the psql command to connect to the remote database (as, by default, it’ll be looking for the database locally), for example (if your server is 1.2.3.4):

psql -h 1.2.3.4 -u myusername -p 5432 -W
2 Likes

Thank you for the help, the database was not running anymore.

Once the database was running again, I could get into the database like this:

psql -U postgres -h 127.0.0.1 db_name

1 Like