pg_dump postgres database from remote server when port 5432 is blocked

You can connect with ssh to your remote server, do with the connect the pg_dump call and send the output back to stdout of local machine.

ssh user@remote_machine "pg_dump -U dbuser -h localhost -C --column-inserts" \
 > backup_file_on_your_local_machine.sql

let's create a backup from remote postgresql database using pg_dump:

pg_dump -h [host address] -Fc -o -U [database user] <database name> > [dump file]

later it could be restored at the same remote server using:

sudo -u postgres pg_restore -C mydb_backup.dump

Ex:

pg_dump -h 67.8.78.10 -Fc -o -U myuser mydb > mydb_backup.dump

complete (all databases and objects)

pg_dumpall -U myuser -h 67.8.78.10 --clean --file=mydb_backup.dump

restore from pg_dumpall --clean:

psql -f mydb_backup.dump postgres #it doesn't matter which db you select here

Copied from: https://codepad.co/snippet/73eKCuLx