Nothing new under the sun, but this is how I use it, and I’m reporting it here since I’ve found some misleading indications out on the net. Remote machine is 192.168.1.2 with SSH running on non-standard port 12345
ssh -p12345 -L 3333:localhost:5432 root@192.168.1.2
After this, you can connect to port 3333 on localhost to access remote postgresql DB server.