local backup from mpg cluster fails

I have read the docs and tried the ‘fly proxy / pg_dump’ process several times with no success.

% fly proxy 5433:5432 -a appname

% pg_dump -h localhost -p5433 -U postgres -F c dbname_db > dump.sql

My pg_dump command comes back with

pg_dump: error: connection to server at "localhost" (::1), port 5433 failed: Connection refused

	Is the server running on that host and accepting TCP/IP connections?

connection to server at "localhost" (127.0.0.1), port 5433 failed: server closed the connection unexpectedly

	This probably means the server terminated abnormally

	before or while processing the request. 

My local PG is v16, the same as my mpg cluster.

Any suggestions?

Hey Bill - Hope you are well!

It looks like the commands you’re using are for unmanaged Fly Postgres instead of Managed Postgres. For an MPG cluster, you’ll want to run fly mpg proxy. That proxy listens locally on 127.0.0.1:16380 by default. In another terminal, try your dump using the connection details from the cluster’s Connect tab, for example something like:

pg_dump "postgres://fly-user:<password>@127.0.0.1:16380/<database>" -F c -f dump.pgdump

I’d also use 127.0.0.1 instead of localhost, since the ::1 error shows pg_dump is also trying IPv6 while the MPG proxy is listening on IPv4. For MPG, you’ll also want to use the database credentials shown in the Connect tab in the dashboard rather than -U postgres. Also, since -F c creates a custom format dump, I’d use a .pgdump filename instead of .sql to make the restore format clearer.

Hope this helps!