Cannot connect AppSmith to local PostgreSQL server - postgresql

Problem
In general, there have been a ton of issues in connecting a remote service to a PostgreSQL database. The documentation for most services doesn't really have documentation for this since the task of connecting to a PostgreSQL database requires the Admin to modify both the postgresql.conf and pg_hba.conf files.
The current scenario is giving AppSmith remote access to the given server.
PostgreSQL needs to allow the following IP addresses at the pg_hba.conf: 18.223.74.85 and 3.131.104.27
Research SSL Connections and if one would be required in this case
Success Criteria:
Appsmith is able to connect to given database
Appsmith is able to read/write data to given database
Resolution Research
Allowing the above IP addresses to connect to the PostgreSQL database in the pg_hba.conf file and changing the postgresql.conf file to allow remote connections using listening_addresses = '*' did not resolve the issue. Appsmith is unable to connect to the database.
SSL Connection: SSL stands for Secure Sockets Layer and, in short, it's the standard technology for keeping an internet connection secure and safeguarding any sensitive data that is being sent between two systems, preventing criminals from reading and modifying any information transferred, including potential personal details.
SSL proved to be a dead-end for this issue with no resolution.
In order to create an SSL connection, the following steps must be followed (PostgreSQL SSL documentation: https://www.postgresql.org/docs/9.1/ssl-tcp.html):
OpenSSL needs to be installed on the host server (https://fedingo.com/how-to-install-openssl-in-ubuntu/). Determined that OpenSSL is already installed on the host server using openssl version -a.
Following the above steps from the postgresql documentation does not produce the desired result.
Following steps from https://www.cyberciti.biz/faq/postgresql-remote-access-or-connection/ does not work either.
Error in all cases on Appsmith: Failed to initialize pool: The connection attempt failed
Next-steps
Consult with the Stackoverflow community to see if anyone else is having a similar issue.
Similar issues have been found, but Appsmith documentation and the Stackoverflow community did not have the information needed to fulfill this issue. I will post the full case to the community.

I resolved this problem using ngrok to make a tcp tunnel on your localhost.
Donwload and conifg ngrok and create a new tunnel on terminal, just run ngrok tcp 5432 at terminal
After this, get the host/port and insert at Appsmith PostgreSQL Connection.
make sure your username/password is correct.
Image from host/port create on ngrok
Image to how config this host/port on Appsmith

Related

Connecting to Fly.io Postgres from Vercel

Is it possible possible to connect to Fly.io Postgres from a NEXT.js API route served from a Vercel severless function, and if so, how?
I've read and reread the Fly.io Postgres docs, focusing especially on Connecting from outside Fly.io and (since my API routes use Prisma to connect to Postgres) Connecting with Prisma, but it seems I would need to either install flyctl or a set up a WireGuard Tunnel in Vercel, neither of which I could figure out how to do from web searches.
I found essentially the same question on the Fly.io community forum, but unfortunately, no one has answered it after 26 days (as of this writing).
To add a bit more detail, I'm familiar with Heroku Postgres, where a connection string is essentially all that's needed to connect, but it seems connecting to Fly.io Postgres requires a connection string plus a proxy created with flyctl. This was easy to get working on my local machine, but it's not clear how to do this on a remote host like Vercel.
One of the solutions is to allocate an ip address to your app with link here
fly ips allocate-v4 --app <pg-app-name>
Then add these service configurations to the fly.toml file
[[services]]
internal_port = 5432 # Postgres instance
protocol = "tcp"
[[services.ports]]
handlers = ["pg_tls"]
port = 5432
Redeploy your app with fly deploy
Go to your fly dashboard you will be able to see Ip Addresses that you can use as host to connect to the database

Apache Superset remote connection to PostgreSQL database: Can't determine Superset IP

I'm running a Superset instance via Docker on a MacBook Air (2019, v11.5.2, Intel i5). I'm trying to set up a remote connection to a PostgreSQL database via an AWS endpoint. I entered the credentials via the dynamic form, as such:
HOST: {dbalias}.{xyz}.us-east-1.rds.amazonaws.com
PORT: 5432
DATABASE: {dbname}
USERNAME: {username}
PASSWORD: {password}
I'm sure that my credentials are valid because I used them to connect from both Databox and DBeaver. But when I try to connect here, Superset tells me that port 5432 is closed. A little digging tells me that this is likely a firewall issue.
I know that our database is set up to only allow connections from allowed IPs, and of course my machine's IP is whitelisted, so I assume I need to whitelist the IP that is sending the connection request (i.e., Superset). However, I cannot seem to find that information. Indeed, even Superset's PostgreSQL connection instructions seem to be incomplete vis-a-vis connecting to an AWS endpoint.
Assuming I've diagnosed the problem correctly (which is by no means a guarantee), the key question is: Where can I find my Superset instance's IP to add to my PostgreSQL IP whitelist? Relatedly, would this IP change next time I launch Superset from Docker, or will it persist?
Many thanks for any consideration.

How can I transfer a dumped database in Postgres CLI from my remote server to my remote server or my local machine?

Normally, when I transfer a dumped database from postgres CLI in my local machine, I can simply sftp my_user_name#my_ip remotely from postgres CLI to my local machine without any problems. However, when it comes to my remote server, this seems like I have already connected with my server via ssh connection; thus, when I sudo su - postgres to open up postgres CLI, I cannot use the same technique to
i)sftp my_user_name#my_ip. It said request Connection timed out; I think this may be because they are not in the same WiFI network connection.
ii) or even sftp ubuntu#ec2-xx-xx-xx-xxx.....amazonaws.com. It said my aws ec2 server: Permission denied (public key)
I think this may result from I have made a SSH connection already, so if i sftp again, this will duplicate with the previous SSH connection.
Any idea ?? Please help
it should be simple. I will help you here. Firstly are both machines on same network ? your first comment looks like they are not on same network or we can say they are not connected to each other hence connection timed out. on your second comment; u would need to use pem file to connect to ec2.. Please give all details ; and I will give you commands etc. needed. Also, check security group of destination server if port 22 is open.

PGAdmin III cannot connect AWS RDS

I am trying to connect AWS RDS PostgreSql from PgAdmin 3. I followed the below link
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html
In Security Group, I also added PostgreSQL and All traffic as below
The "publicly accessible" flag was enabled (updated after Mark B's comment)
I got the error from PGAdmin3
Very appreciate for any suggestion
******UPDATE*******
I can connect pgAdminIII to AWS RDS successfully using home wifi, but cannot connect using office wifi.
My concern is:
Was the port 5432 blocked by office wifi?
How can I configure/update the port without impacting to current API?
Note: My current API is working well (CRUD)
Can you can test your connection to a DB instance using common Linux or Windows tools first?
From a Linux or Unix terminal, you can test the connection by typing the following (replace with the endpoint and with the port of your DB instance):
$nc -zv DB-instance-endpoint port
For example, the following shows a sample command and the return value:
$nc -zv postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com 8299
Connection to postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com
8299 port [tcp/vvr-data] succeeded!
Windows users can use Telnet to test the connection to a DB instance. Note that Telnet actions are not supported other than for testing the connection. If a connection is successful, the action returns no message. If a connection is not successful, you receive an error message such as the following:
C:>telnet sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com
8299
Connecting To sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com...Could not
open connection to the host, on port 819: Connect failed
If Telnet actions return success, then you are good to go.
If you are trying to access it from a network which is not listed for that port. you need to add inbound rules for those network IPs from AMAZON RDS system
You will also need to set Public accessibility true under Connect & security tab in RDS console.
Read this post.In your security group go to unbound rules and add my ip.
and make sure your database is public.
https://serverfault.com/questions/656079/unable-to-connect-to-public-postgresql-rds-instance

Postgres and Atlassian Jira: driver issue

I am trying to setup a server with centOS 32 bit to install Atlassian Jira on it.
I followed the official Atlassian installation guide at https://confluence.atlassian.com/display/JIRA/Installing+JIRA
Now I am running the Setup Wizard and I need to configure a PostgreSQL database. On my centOS, I installed version 8.4.20 via yum.
However, I am having a hard time setting Jira. Postgres is running and I can login via Linux console, but when I test the connection to the database, I get the following error:
Error connecting to database
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused
Also, this error appears when I type the full public IP address. If I insert localhost, I get this:
Error connecting to database
FATAL: Ident authentication failed for user "jiradbuser"
If I insert
http://<public ip>
I get the following:
Error connecting to database
No suitable driver found for jdbc:postgresql://http://<public ip>:5432/jiradb
However, I put my jdbc driver into /opt/atlassian/jira/lib and its name is postgresql-8.4-703.jdbc4.jar. Postgresql version is 8.4.20.
Where am I doing wrong?
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
By default, PostgreSQL listens only on the local loopback interface, so connecting to the public IP won't work. If you're connecting from localhost you don't need to anyway, just use localhost.
FATAL: Ident authentication failed for user "jiradbuser"
This is good, it shows that you're connecting to PostgreSQL successfully, then getting an authentication error when trying to log in.
Your PostgreSQL server install defaulted to ident authentication for TCP/IP connections, but the JIRA application isn't running under a unix user named "jiradbuser" so the connection is rejected. Change pg_hba.conf to use md5 instead of ident and set a password for the user. See the client authentication chapter in the docs, particularly, pg_hba.conf.
No suitable driver found for jdbc:postgresql://http://:5432/jiradb
I have no idea where you got the idea that that URL would work...
You want something like:
jdbc:postgresql://localhost:5432/jiradb
I had the same problem. I could solve it setting up the postgres driver .jar from maven repository to \target\jira\webapp\WEB-INF\lib\
Pretty late to the question here but thought I'd add a couple bits to help out the future, going backwards:
No suitable driver found for jdbc
A while ago Atlassian didn't distribute the PostGreSQL JDBC driver file with the JIRA releases. They have been doing this for a while now (I'd say since mid 2013) - regardless, the driver file belongs in the <jira-base>/lib directory unless you are doing a WAR install, in which case you shouldn't, and just put the driver file in the lib directory anyway
FATAL: Ident authentication failed for user "jiradbuser"
1. Listen on a socket if you need to - The best approach to this is to look at your JDBC driver URL - if it has an IP/hostname other than 127.x.x.x or 'localhost' you need to modify PostGreSQL to listen to a TCP port by modifying your postgresql.conf file to enable listening on ports. Just find the file, back it up, then open it and search for localhost, read the file comments and make the correct change. If you find yourself looking around in multiple locations in the file or changing more than a single word you are trying too hard - restore your backup and try again. Just remember to *stop* and *start* your postgres db cluster when you are done
2. enable the correct login METHOD in pg_hba.conf (same directory as the postgresql.conf file - on unix typically under /etc/postgresql/<version>/main/.) - this is difficult to writeup in brief but I'll try
1. backup the pg_hba.conf file - I ain't foolin, this is something you'll be happy with later - back the sucker up
2. edit the file
3. go to the bottom of the file - look for the last line like "# TYPE DATABASE USER ADDRESS METHOD"
4. comment out every line under this 'table heading' line
- the reason to do this is that the package maintainers often fall back to commenting here and so you'll have 2 commented out lines and then one line that isn't commented out - and you'll never notice it - it's easiest to just start off with commenting out the whole block of stuff so there isn't a single uncommented line in the file
- add a two lines for the postgres user to connect local and to a db socket unless your corporate security does not allow - something like this:
local all postgres 127.0.0.1/32 peer
host all postgres 127.0.0.1/32 trust
- add a line for your jiradbuser to connect to the newly created database via sockets with md5 encryption. md5 isn't the best - there are other options to google - if you use md5, it'd look something like this:
host jiraversiondb jiradbuser 127.0.0.1/32 md5
Then save the file, restart postgres cluster (with a stop and start, not with the 'restart' option), and test connecting from the command line.
How to test connections from the command line
If you are logged into a unix system with the postgres tools installed you should be able to mimic the connection attempt which the JIRA server will try to connect to the database. If you cannot connect to the new postgresql db from the command line it's a REAL GOOD chance that JIRA won't be able to either. Plus you'll get better error messages. So to do this just bring up a shell and enter (replacing variables where appropriate - things within the '<' and '>' characters) - all the values for these are in your head and the postgresql.conf file:
psql --port <port - default is 5434> --username=<db user name> --password --dbname=<database name>
Once you can connect from the command line it's a good bet JIRA will as well - no promises, but you'll be on sound footing.
...ahhh....now, that'll hopefully help someone...