SSH tunnel to postgres from Tableau desktop - invalid username and password - tableau-api

I am trying to connect Tableau to a postgres DB using a SSH tunnel. The steps I have taken are
Install postgres drivers (32 bit) on my desktop
Create the tunnel in putty (tunnel L5432 127.0.0.1:5432) and open up the terminal
From this session I can run Postgres from the command line psql -d mydb -U myuser
However, when trying to connect using Tableau I get the error message "Invalid username and Password"
If I try to connect to a DB that doesn't exists I get the same error message "Invalid username and Password"
I have also created a psql user with superuser privileges but no success. Note that the username for the ssh tunnel and the psql db are different.
I have seen a number of posts on the forum with no solution.
Can anyone help? Thanks.
Roger

I met with the same question, with slight difference, I didn't use PuTTY but instead using Cygwin Autossh.
The answer is that two tunnels need to be built, first an ssh tunnel from local host to server, and then from the server port to the database port. A possible solution is to set up ssh tunnel like this:
5432:localhost:5432 username#hostserverdomain
The first 5432 is the local port(Tableau or PGAdmin), the second localhost actually refers to the server(cuz once log in localhost means the server itself), the second 5432 is the database on the server. And in order to get access to the database, one has to log in the server.
The above is just the syntax to connect thru two tunnels using ssh.
At first I didn't understand what Roger means by two tunnels, and then I look into the underlying methodology and finally got all the setup work done. Thanks Roger!

Related

Can't connect to postgres via PSQL or php, only pgAdmin4

I have PostgreSQL 12 installed and using Windows 10. My goal is to connect to postgre via php, because it didn't work I tried with plsql but it didn't work either, i always get (with both plsql and php using PDO):
FATAL: password authentication failed for user "postgres"
Connection via plsql in cmd
However, when trying via pgAdmin4, I can connect and access my databases. I first use my root password then sometime my postgres user one, so I'm sure my password works.
Here is my pg_hba.conf file:
pg_hba.conf file
I have a set password for postgres which was set vua pgAdmin4.
I don't understand why it would work one way and not the other, can anyone help me?
So after trying several things, I found that plsql and php error was due to the wrong port being adressed.
By default 5432 is used, but for some reason my configuration was using 5433.
You can find this information in pgAdmin4 by opening PostgreSQL 12 properties, and then checking in connection tab.
To change the used port in plsql I used:
psql -U postgres -p 5433
Change 5433 by your configured port if you have same issue, you also need to specify the port if using php's PDO.

pgAdmin4: remote access to PostgreSQL server

I can access the remote PostgreSQL server in the lab from both the terminal and using pgAdmin4 when connected to same private network.
From Terminal:
PC:~$ psql -h 193.13x.xx.xx -U myusername -W dbname
#then password after prompt
Using pgAmin4:
Host name/address: 193.13x.xx.xx
Port: 5432
Maintainance database: dbname
Username: myusername
Password: *******
However, when I switched to another network eduroam, I can only connect to the remote server via the terminal, not from pgAdmin4. So it is not very easy to work away from the lab.
Is there a workaround to enable connecting via pgAdmin4?
I can only connect to the remote server via the terminal, not from
pgAdmin4. So it is not very easy to work away from the lab.
Is there a workaround to enable connecting via pgAdmin4?
Yes. The generic answer to that is: use an SSH tunnel. It's very usual when you cannot access directly a database from outside a certain network, which appears to be your case based on the error message in the comments.
If you need specific advice for pgAdmin4, consider searching for "pgadmin4 ssh tunnel", there are many tutorials available online.

why can't i connect to postgres on AWS EC2?

I'm hoping someone who has experienced this before can help me get this connection to AWS/EC2 -> Postgres working.
All the following is via terminal, on a Mac client.
The database in question - Postgres - is running remotely on this EC2 server, not, on my local Mac (nor is Postgres installed on my local Mac)
My understanding is that I need to be able to actually connect to the EC2 server and make an SSL "tunnel" connection -: from my PC to this same EC2 server -- so I can then, access the Postgres database
If my understanding there is wrong please let me know.
So, I have 2 terminal windows open. Terminal A, and Terminal B.
In Terminal A
(a) connecting to the EC2 server works fine. Here's the CLI command:
ssh -L 3307:127.0.0.1:3306 -i my.pem ubuntu#xx.yy.zzz.99
The CLI in Terminal A then shows me the Ubuntu/server prompt
Last login: Wed Oct 25 12:27:31 2017 from aaa222-444.xxxx.rrr.ff.net
ubuntu#ip-111-222-333-44:~$
then, I go to terminal B...
In Terminal B
(b) i try to make a connection to Postgres from local using the following command:
psql -h localhost -p 3307 -U postgres_uid postgres_databasename
THIS FAILS EVERY TIME.
I get this response in Terminal B:
psql: received invalid response to SSL negotiation: [
I am wondering, is there is a DIFFERENT SSL setup that is needed to make this DATABASE connection ? Or should it be that once I am logged into the AWS EC2 server (as noted above) I should be able to run psql commands (or use GUI clients like Navicat etc) ?
I'm at a loss and no one here knows how to fix this / set this up. it's probably something simple but that's fine, I just need to get connected :-)
Appreciate anyone's help with this thanks.
Use URI syntax in the -d option, and the SSL should take care of itself.
I use the following command to access cloud postgres instances (on bluemix, not ec2), give it a go...:
psql -d postgres://<user>:<password>#<host>:<port>/<dbname>

pgAdmin III : No servers showing up

I've followed many online tutorials on how to install pgAdmin correctly, I've installed and uninstalled it multiple times but whenever install it. It shows Server Groups without any servers in it.
Then when I try and register a new server using localhost for both name and host I get this error:
server doesn't listen
Searched for days trying to find a solution for this, any ideas?
Happened with me as well, when I started pgadmin3 for the first time, I was expecting it to ask for the password which I provided during but it didnt ask and then didnt display any servers.
Anyways, you can create a server yourself.
If your server is on the same machine,
provide a name: test
provide server: localhost
provide a port number : 5432 (default port)
provider a username: postgres (default user, you can change later in login roles)
password: provide something
Restart if required, and it will then show you a
database with postgres (default db),
tablespace, and login roles under your server, and you should be good to go .
First Create a Server with the following credential-
Host Name/address : localhost
Port : 5432
Maintenance database : postgres
Username : postgres
Password : *Your_Password*
Note : Before Creating the Server first start the postgresql server
Reinstalled program and saved it to directory C:\ instead of C:\program_Files
When I did this invalid password message appeared. So I had to change postgres user password:
In the terminal window:
Switch to the postgres account on the server by typing:
sudo -i -u postgres
Now I can access a Postgres prompt immediately by:
psql
Change the postgres user password:
ALTER USER postgres WITH PASSWORD 'newpass';

pgadmin gives me the error: no password supplied

I've installed postgresql 9.2 on linux (kubuntu) and the last version of pgadmin3, but when I connect them I have this error:
An error has occurred:
Error connecting to the server: fe_sendauth: no password supplied
What can I do?
I have also configured tomcat for my web application in java. In fact, postgresql was working before trying my application.
Change the password for role postgres:
sudo -u postgres psql postgres
alter user postgres with password 'postgres';
Try connect using "postgres" for both username and password.
Refer to: How to change PostgreSQL user password
Whether a password is required depends on your settings in pg_hba.conf. And there are different ways you can connect - different settings in pg_hba.conf may apply.
I quote the help shipped with pgAdmin 3 for the "Host" field in the connection ("server") settings:
The host is the IP address of the machine to contact, or the fully
qualified domain name. On Unix based systems, the address field may be
left blank to use the default PostgreSQL Unix Domain Socket on the
local machine, or be set to an alternate path containing a PostgreSQL
socket. If a path is entered, it must begin with a “/”. The port
number may also be specified.
If you connect via Unix socket the rules for "local" apply.
Whereas when connecting via TCP/IP "host" (or "hostssl") rules applies.
If you have a line like this at the top your pg_hba.conf file:
local all all peer
or:
local all all ident
.. then you can connect locally without password if your system user is "postgres" and your database user is "postgres", too.
I realize this is question is years old, but I ran into this same problem today and have a solution that uses trust in a limited but useful way.
As in many development shops, when the devs need a QA postgres password, they just yell it, message it, email it, write it on their foreheads, etc. And I'm like, "This is really bad. I need to figure out a way to use PKI here." We also use pgAdmin3.
First, add a line like this to your pg_hba.conf, where dev represents the user for the developers in your shop:
host all dev 127.0.0.1/32 trust
Drop the developers' public key in their authorized_keys folder on the database server. Now have them ssh into the server with the -L flag with a command similar to the following:
ssh -i ~/.ssh/id_rsa -L5432:127.0.0.1:5432 -vvv 101.102.103.104
This allows one to use the postgres port as if it were localhost. Of course, replace the key, server and make sure to map to an open port locally (if you have a local postgres running, it's probably bound to 5432). I use a pretty verbose flag so I can easily troubleshoot any ssh issues.
Open another terminal and issue this command:
psql -h 127.0.0.1 -U dev -p 5432
You should have access to the database and never be prompted for a password, which I think is great because otherwise, the devs will just waive the password around with little regard to security, passing it out like Halloween candy.
As of now, PgAdmin3 will still prompt you for a password, even though -- plain as day -- you do not need it. But other postgres GUIs will not. Try Postico. It's in beta but works great.
I hope this answer helps anyone like me who would rather use PKI for postgres auth rather than sharing passwords willy-nilly.
Met this problem recently.
If you're using PostgreSQL on local machine, and psql works well without logging needed, try pgadmin3's menu File - Add Server - Properties tab, fill in Name field for this connection, leave Host field and Password field empty, and click ok.
from pgadmin docs
On Unix based systems, the address field may be left blank to use the
default PostgreSQL Unix Domain Socket on the local machine, or be set
to an alternate path containing a PostgreSQL socket. If a path is
entered, it must begin with a “/”.
Worked on Debian testing (pgadmin3 1.22, PostgreSQL 11), without touching pg_hba.conf.
For me, I run pg_ctl -D /usr/local/var/postgres start, start the server, then everything is OK, it will pop out the connection host port.