Heroku to fly postgres migration guide not working

And if the pg_dump command still fails after you ssh, then getting your database downloaded locally and then uploading it to postgres has been some users workaround.

You might find this post of a customer with a similar issue helpful