this is a bit complicated, please bear with me
I want to use org-babel to query postgresql, and I can do it for DBs that I can access directly from my localhost:
#+begin_src sql :engine postgresql :cmdline "-h localhost -U postgres -p 5434 -d my_db"
I can even probably do that if DB is on a remote ssh machine, by setting ssh tunnel first.
The problem is: in my company (for security reasons) it's made that you have to:
- first ssh to a machine (let's call it
- and only then access the DB, which is still on a remote host (let's call it
Another problem is, that
first-lvl-host does not even have
psql (command line utility). In order to access it - you have to ssh hop to another machine (let's call it
Basically I'm expected to do:
ssh first-lvl-host ssh second-lvl-host # and then: PGPASSWORD=mypass psql -h db-lvl-host -U ag
So, my question is, can I anyhow still do it directly from my org file?
I know I can reduce ssh hops by adding:
Host second-lvl-host ProxyJump first-lvl-host
to my ssh/config, but that still doesn't allow me to access db-machine directly, using local
psql, and if I can't poke on it with psql, I don't think I can do it with org-babel, or can I?
I tried setting a tunnel like this:
ssh -L 9999:localhost:9999 first-lvl-host ssh -L 9999:localhost:1234 -N db-lvl-host
but that didn't work. I can't ssh to db-lvl-host, even if I do
ssh first-lvl-host ssh second-lvl-host ssh db-lvl-host. It doesn't work like that. I can't connect to
db-lv-host via ssh, it reports: "Connection timed out", if I can't ssh to it - means I can't establish a tunnel, right?