pgAdmin4: remote access to PostgreSQL server - postgresql

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.

Related

psql server ssh tunneling authentication failure

I'm trying to connect to a psql database on a remote server.
So I ssh tunnel into the remote server with port forwarding as below
ssh -L 7777:psqlServerHost.com:5432 me#remoteServerHost.com
Unfortunately using this method I'm unable to authenticate properly when I try the below command on separate terminal on my local
psql -h localhost -p 7777 -U user database
I would get
FATAL: password authentication failed for user
However if I were to directly ssh into me#remoteServerHost.com I would be able to connect to the database with the same credentials using the below command
psql -h psqlServerHost.com -U user database
I imagine this is probably a configuration file somewhere that I've missed, but I can't seem to find any similar queries that are helpful on the internet.

Cant login with postgresql user created via ansible

Normally, I would create create postgresql user like this.
sudo -u postgres psql
create user deploy_sample with password 'secret';
create database deploy_sample_production owner deploy_sample;
I tried to create the user through ansible script with this task
- name: Create database user
become: yes
become_user: postgres
postgresql_user:
user: user123
password: password123
encrypted: yes
state: present
This does create a user but i cant login using the creds.
I tried to login with this command psql --username=user123 --password. I get peer authenticate failuer error.
Ansible configuration looks correct, and may have nothing to do with the problem.
By the message we can see that it is trying to login with the Peer authentication method. This means that the O.S. user is being used to connect to the database instead of the provided password (see: https://www.postgresql.org/docs/10/auth-methods.html)
Two things you should look at:
How is your auth method configuration?
It is in the file: {data dir}/pg_hba.conf
It is possible that all local connections are configured to use peer (notice that are two types of local connections, one is called local = connection through unix socket, the other is host 127.0.0.1/32 = using network to reach localhost).
I would change the second one to use md5 method, this way you will be able to connect with user/pass using network, but still use peer for local connection - useful for the system user postgres
Connect with the application user using network
psql --username=user123 -> PSQL program will try to use local connections by default, meaning that the Peer authentication is used. You probably don't have the user user123 on the system so this will fail!
psql -h localhost --username=user123 -d <database> -> This way you will connect to local machine using network, thus allowing to authenticate with password.

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>

pgAdmin4: Unable to connect to Amazon EC2 via SSH Tunnel

I have Amazon EC2 instance running Ubuntu. I have installed and configured PostgreSQL.
Contents of the file /etc/postgresql/9.3/main/pg_hba.conf:
local all all md5
host all all 0.0.0.0/0 md5
Also in postgresql.conf
I have set listen_addresses='*'.
The test command below is successfully starting psql console.
psql -U postgres testdb
Now I am trying to connect pgAdmin4 from MacOS.
I have created a SSH tunnel with following command:
ssh -i ~/.ssh/test.pem -fN -L 5433:localhost:5432 ubuntu#mytestdomain.com
Now I have following details in pgAdmin:
When I save, I get this output:
Unable to connect to server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.
What am I doing wrong ?
Here is the solution,
install pgadmin 4 into your system. and configure the below-added configurations. if the below configurations do not work then please check that DB user permissions on AWS. because of the restriction on IP level so it may not be able to access.

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

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!