not able to connect to postgres on aws ubuntu

Hi There,

I am getting the following issue with postgresql in aws ubuntu environment.

When I  run python3 manage.py makemigrations, I get the following error.  
It throws the following error. File "/usr/local/lib/python3.5/dist-packages/psycopg2/init.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

Hence I checked whether postgresql is working fine.
I had tried sudo su - postgres It went inside the postgres cmd prompt so it became postgres@ip-10-254-3-58:~$

now when I try psql I get the same error as when I run python3 manage.py makemigrations.

postgres@ip-10-254-3-58:~$psql psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

I had tried uninstall and reinstall postgres,

During uninstall , i had tried the following command

$sudo apt-get --purge autoremove postgresql*

I got many errors

Then I had tried
sudo apt-get clean
sudo apt-get update

I got the following errors.  

Hit:1 https://deb.nodesource.com/node_8.x xenial InRelease
0% [1 InRelease gpgv 4,646 B] [Connecting to archive.ubuntu.com (91.189.88.161)] [Connecting to security.ubuntu.com (91.189.91.26)] [Connecting to ppa.launchpad.net (9CErr:1 https://deb.nodesource.com/node_8.x xenial InRelease
  Could not execute 'apt-key' to verify signature (is gnupg installed?)
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Hit:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial InRelease
0% [4 InRelease gpgv 18.0 kB] [3 InRelease 14.2 kB/247 kB 6%] [2 InRelease 14.2 kB/102 kB 14%] [Waiting for headers]Couldn't create tempfiles for splitting up /var/lib/Err:4 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial InRelease
  Could not execute 'apt-key' to verify signature (is gnupg installed?)
Hit:5 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease
0% [5 InRelease gpgv 6,372 B] [3 InRelease 43.1 kB/247 kB 17%] [2 InRelease 63.4 kB/102 kB 62%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/packages.clErr:5 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease
  Could not execute 'apt-key' to verify signature (is gnupg installed?)
0% [2 InRelease gpgv 102 kB] [3 InRelease 63.4 kB/247 kB 26%]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_xeniErr:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
  Could not execute 'apt-key' to verify signature (is gnupg installed?)
Ign:3 http://archive.ubuntu.com/ubuntu xenial InReleasen't create tempfiles for splitting up /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial_InRelease
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
0% [6 InRelease gpgv 102 kB] [Waiting for headers]Couldn't create tempfiles for splitting up /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial-updates_IIgn:6 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Get:7 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Ign:7 http://archive.ubuntu.com/ubuntu xenial-backports InReleaseng up /var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_xenial-backports_InRelease
Fetched 553 kB in 2s (217 kB/s)
Reading package lists... Done
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://deb.nodesource.com/node_8.x xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://ppa.launchpad.net/deadsnakes/ppa/ubuntu xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://security.ubuntu.com/ubuntu xenial-security InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: GPG error: http://archive.ubuntu.com/ubuntu xenial InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://archive.ubuntu.com/ubuntu xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://archive.ubuntu.com/ubuntu xenial-updates InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://archive.ubuntu.com/ubuntu xenial-updates InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://archive.ubuntu.com/ubuntu xenial-backports InRelease: Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: The repository 'http://archive.ubuntu.com/ubuntu xenial-backports InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: Failed to fetch http://ppa.launchpad.net/deadsnakes/ppa/ubuntu/dists/xenial/InRelease  Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: Failed to fetch http://packages.cloud.google.com/apt/dists/cloud-sdk-xenial/InRelease  Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: Failed to fetch https://deb.nodesource.com/node_8.x/dists/xenial/InRelease  Could not execute 'apt-key' to verify signature (is gnupg installed?)
W: Some index files failed to download. They have been ignored, or old ones used instead.
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/google-cloud-sdk.list:1 and /etc/apt/sources.list.d/google-cloud-sdk.list:2


Please help me in resolving this.


TIA,

Kind Regards,
Bharath AK
LVL 1
Bharath A.KAsked:
Who is Participating?
 
Duncan RoeSoftware DeveloperCommented:
You don't usually need to reinstall production subsystems under Linux - that's a Windows thing. Anyway, the question now is: do you now have a working postgresql or not?
If you do, we can go ahead and investigate your original problem. If not, I can't help.
0
 
Bharath A.KAuthor Commented:
Hi Duncan,

I had postgressql already installed on my aws ubuntu which was working fine earliar.  I will provide you the complete picture.   Unknowingly,  I had enabled ufw firewall with out allowing ssh and closed the putty.  Next day when I am back I was not able to access my ubuntu.  Hence my tech team restored ubuntu from earlier days back up and provided a new Ip address for ubuntu in AWS.  All was working fine before restoration.  after restoration port error is happening.  I tried to remove then reinstalling postgres.  When googling, I found an article to update the sourcelist for NPM update.  It was not referencing archives.ubuntu.com but point to au-east-singapore.archives.ubuntu.com something like AWS url reference.  I changed all to archives.ubuntu.com.   I found some  apt.key required error.  errors are not going.  Later I googled and found once I reboot my aws ec2 instance all the errors would go.  I am afraid to reboot aws ec2 instance. I am not a aws guy.  But when I login into aws console I see Launch Instance.    I don't know why it is like this, without launching the instance, I am able to access the ubuntu system.  I don't know whether this launch instance would be for my aws console or for everyone.    Please tell what would be the right solution.   If I am wrong at any of the places please correct me.

With many thanks,
Bharath K
0
 
Duncan RoeSoftware DeveloperCommented:
Why did your tech team feel it necessary to give you a new IP address after restoring from backup? (dhcp?)
If you no longer trust the current state of your server then I would advise to restore it from backup again.
After that, either configure the firewall to allow ssh or disable the firewall
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Bharath A.KAuthor Commented:
Hi Duncan,

          They provided the ipaddress to configure the putty settings to connect new restored ubuntu aws.  the ipaddress they provided was different than the earlier one.   i.e why they provided the ip address.  Have I made a mistake please correct me if I am wrong.

With Many Thanks,
Bharath AK
0
 
Duncan RoeSoftware DeveloperCommented:
Do you  have a system you can trust now? If not, have your tech guys restore from backup again.
0
 
Bharath A.KAuthor Commented:
Hi Duncan,

I am waiting for them to provide a new backup system.

I get back to you once I have a new system.

With Many thanks,

Bharath AK
0
 
Bharath A.KAuthor Commented:
Hi  Duncan,

        Now we have a new System, which is working now.  We have our problems resolved.

Thank you so much.

Regards,
Bharath AK
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.