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

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.

Related

Cannot connect AppSmith to local PostgreSQL server

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

Accessing postgres server with limited pg_hba.conf access

I am trying to access a postgres server that has limited IP access in pg_hba.conf file.
I am trying to use dbeaver to access it.
I am - computer A
postgres server - computer C
server i can access postgres server from - computer B
In my computer I have this view.
As far as I understand I need to trick my computer into using the computer B.
So when i write postgreserver.blaah.com into host/ip and port 5432. It will ssh to computer B and then access it from there.
So in my ssh config file i wrote this:
LocalForward 5432:postgreserver.blaah.com:5432 myuser#server.b.com
Well this didn't work.
Any suggestions?
I don't think you should do anything in your ssh config (and which computer's ssh config was it?). DBeaver's SSH tab is an alternative to manually setting up your own tunnel.
If you have already manually set up your own tunnel, then you would just point DBeaver to it, you wouldn't tell DBeaver that it is using a tunnel. It doesn't need to know.
If you want DBeaver to set up the tunnel, then "computer_B" would go in the Host/IP field of the SSH tab. "computer_C" would go in the Host field of the Main tab.
I ended up using
ssh -L5432:databasehostname:5432 intermediatehostname
So this is running in a random shell somewhere on my screen while i am working with the database.
In DBeaver the hostname is localhost and port is 5432
and i am using Main connection tab not ssh tunnel.

Can't connect remotely to postgres, no response from psql request

Ubuntu 16.04 LTS
I have followed the guides which all say the same thing; to enable remote connection to a postgres server, update the postgresql.conf file, update the pg_hba.conf file and make sure the port (5432) is open and firewall is not blocking.
When I attempt to connect to my server from the remote machine using the following command, I receive no response (for example, 'Connection refused...'). It hangs as if the firewall has DROP policy, but I checked and the host's firewall is ACCEPT all. Here is the command:
psql -h 45.67.82.123 -U postgres -p 5432 -d mydatabase
I have googled extensively and can't find anyone else who's psql request sits with no response from the host server.
Edit: I should mention I have been connecting locally on the host machine. I should also mention that the data directory on the host machine is in a non-default location. I have my cluster on a mounted drive, in case this could affect the remote connection.
Solution:
It is my first AWS instance and I didn't know they have their own firewall rules on the platform. So I was highly confused by the fact all my policies were ACCEPT on my server. Turns out you are behind AWS firewall and you have to go onto the platform to add/change security groups etc. In the past when I've used Digital Ocean droplets or Linodes, the firewall policy on the vps is all I need to change. AWS threw me another curveball there.

how to solve the error of DBeaver database?

I used DBeaver (database management tools) and faced this type of error
It looks like you're trying to connect to a MySQL instance over SSH. Most likely issue is that the remote server isn't accepting SSH connections. If you try the following at a command line, can you establish a connection? (Bash if you're using Linux, putty if you're on Windows)
ssh <user>#<remotehost>
Also it's important to mention that you probably have two sets of credentials you're using here. The credentials to connect to the SSH server are not necessarily the same as the credentials to connect to the MySQL database.

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