Don't use a tuple
. Use a dictionary
d = {'p1': val1, 'p2': val2}
cur.execute("""
select *
from t
where col1 = %(p1)s and col2 = %(p2)s
""", d
)
If there are optional parameters pass then as null
d = {'p1': None, 'p2': val2}
cur.execute("""
select *
from t
where
(%(p1)s is null or col1 = %(p1)s)
and
(%(p2)s is null or col2 = %(p2)s)
""", d
)
Establish an ssh
connection to the server and connect through it.
ssh -L 5432:localhost:5432 remotehost.com