SSH Tunneling to PostgreSQL.
I am going to talk about PostgreSQL, but the idea is the same for the whole spectrum of data bases.
Imagine that you would like to debug your staging machine which is deployed on Amazon and use an Amazon's DB service. In case of the well configured security level, the access to your DB from the external world should be forbidden.
Therefore for your remote debugging you have two options: to open your DB connection and shoot yourself in the foot in terms of security or to open the ssh tunneling and sleep safely.
Format of SSH tunneling:
ssh -l login_name -L [bind_address:]port:host:hostport hostname -N
Example of usage:
ssh -l superUser -L 63333:xxx.xxx.us-west-2.rds.amazonaws.com:5432 shell.foo.com -N
63333 : the new port
xxx.xxx.us-west-2.rds.amazonaws.com : remote DB machine
5432 : default port
-N : keeps the pipe open
In case of successful executing the pipe is still open the prompt shouldn't return to you.
Now, you are able to connect to the DB but on port 63333.
For Hibernate users:
In addition, I would recommend you add:
to your hibernate config in order to accelerate the boot of the application. Otherwise, the application loading could take few very long minutes.