"psql: server closed the connection unexpectedly" working locally on MacOS - postgresql

I encountered a weird issue with my Postgres, suddenly (after YEARS) I can't connect to it using my Golang application code or via psql but the funny thing is that my DBeaver application can!
This is what I try and the error I get:
psql -U postgres -h localhost
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
I did some research and tried a bunch of stuff which seems to resolve this issue for other users :
Following this answer I made sure that both pg_hba.conf and postgresql.conf files configured correctly (added listen_addresses = '*' to postgresql.conf and made sure that I accept any IP host all all 0.0.0.0/0 trust in pg_hba.conf.
Following this answer I've downgraded my Postgres version from 12 to 10 and it did not work either.
Removed EVERYTHING related to Postgres and reinstalled using Homebrew using this guide
Removed the Homebrew installation and tried to use the PostgresApp for Mac - no luck either.
I'm stuck!
Does anyone know what could go wrong? I have no idea what went wrong to cause this issue.
I'm working on OSX Catalina 10.15.4 if it helps.
Any help will be highly appreciated!
Update:
Step 2 works great, the issue was with the latest update of my anti-virus (ESET).

Related

pgAdmin4 SCRAM authentication libpq 10

First of all - I'm not an expert (to say the least).
I want to set up a PostgreSQL database on my Raspberry Pi 4, with Ubuntu Desktop 22.04 LTS and pgAdmin4, but I got stuck.
After running pgadmin in Python Virtual Environment and going to 127.0.0.1:5050, login page appears, all seems fine, until I try to set up a new server. After providing server name and address alert appears: "Unable to connect to PostgreSQL server: SCRAM authentication requires libpq version 10 or above"
Modifying password-encryption and METHOD in pg_hba.conf and postgresql.conf to md5 did not help.
Postgres 14, pgAdmin 4 v 6.10, libpq-dev is already the newest version (14.4-1.pgdg22.04+1).
Any suggestions?
I have tried many combinations of changing passwords, configs and restarting. Here's what worked:
I have removed libpq.so from usr/lib/aarch64-linux-gnu (libpq.so.5 and libpq.so.5.14 are left alone)
Changed all METHODs in pg_hba.conf to trust & restart postgres
Changed password-encryption in postgresql.conf to md5 & restart postgres
Reset password for user postgres (which might have been redundant due to "method/trust") & restart postgres
...and it works.
Thank you!

connection to server on socket "/tmp/.s.PGSQL.5432" failed: fe_sendauth: no password supplied

Rails --API, when I run rails db:reset or try to do anything with my backend I get the following error:
connection to server on socket "/tmp/.s.PGSQL.5432" failed: fe_sendauth: no password supplied
PSQL previously worked, not sure what's changed.
I tried the fourth solution on this page, but it doesn't work and tells me to check the server logs. My server logs are posted here.
I think I originally installed PSQL through Brew but I can't remember for sure. Either way, it was present when I ran brew list, so I uninstalled/reinstalled PSQL through Brew, but the problem persists.
Using DBeaver I tried changing both the connection port number and password but neither of these worked.
How can I get Postgresql back up and running?

How to solve psql error: could not connect to server?

I'm trying to install GeoDjango for my website. To do that, I first need to create a PostgreSQL database. Following this tutorial, I'm trying to connect to PostgreSQL by using sudo su - postgres and then psql. The problem is that I get this error : psql: error: could not connect to server: 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 made some researchs and found this post explaining how to solve the problem. However, when I run sudo service postgresql start I have to type the password for postgres but I don't know what it is, I never created a password for postgres. I've made researchs about that and I can't find a solution because all solutions need to first connect to psql in order to alter the existing user. But I need first to find the password in order to solve the problem of connection to psql.
What am I supposed to do ?
Thanks in advance !
PS : I'm using windows 10 with the Ubuntu terminal.
PS2 : I've found some topics saying it's easier to install PostgreSQL and PostGIS using Docker. However, there are lots of compatibility problems with Docker due to the fact I'm using windows 10. Do you think I should use Docker ?
I've found the solution !
So for those interested, I had to change the password in order to get log in and that solve the psql error: could not connect to server. To change the password, simply type sudo passwd postgres and set up a new password. I hope this will help other people !

Unable to connect postgres DB remotely

Every time, when I try to connect to remote Postgres DB, I receive error:
no pg_hba.conf entry for host "159.224.92.121", user "xpkzxqrkisdrjd", database "d92na0gp4bdq4", SSL off
I googled it and found that two config files should be updated.
Should append:
pg_hba.conf
host all all 0.0.0.0/0 md5
postgresql.conf
listen_addresses = '*'
I did it, but error still occurs, when I try to connect to remote DB.
Local DB work fine.
Any ideas?
UPDATE
Maybe it will be useful. I have installed postgres using homebrew.
For restarting postgres server I use:
brew services postgres restart
Two items to help you on the way:
pg_hba.conf is processed from top to bottom, so if the incoming connection matches an earlier line, that entry will be used.
Set log_connections = on in postgresql.conf and reload. Then, after a connection attempt has failed, look into the log file for the reason. Recent PostgreSQL versions will also tell you which pg_hba.conf line was used.
So, I continued to google this issue and finally found the answer. You should use SSL option.
Please, check this link:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/205996299/comments/206373089

Openbravo - Connecting pgadmin with postgresql database in Ubuntu

I have installed Openbravo ERP 3.0 in Ubuntu 12.04(LTS). After completed the installation I tried to connect with postgresql database using pgadmin 9.1. I gave all the details as mentioned in this link: http://wiki.openbravo.com/wiki/Installation/Appliance/Openbravo.
Also I have changed the config file settings like listen_addresses="*". I got this error after I click "Ok" button
Could anyone give suggestion to fix this error? Thanks in advance.
Actually the problem comes because of not mentioning the local cluster or data area for PostgreSQL. To do this after installing Openbravo, need to give this command in terminal
psql -d openbravo -U tad -h localhost -p 5932
Finally give the PostgreSQL configuration details as mentioned in this link
It works fine now...
To be able to reach the server remotely you have to add the following line into the file: /var/lib/pgsql/data/postgresql.conf:
listen_addresses = '*'
PostgreSQL, by default, refuses all connections it receives from any remote address. You have to relax these rules by adding this line to /var/lib/pgsql/data/pg_hba.conf:
host all all 0.0.0.0/0 md5
This is an access control rule that lets anyone login from any address if a valid password is provided (the md5 keyword). You can use your network/mask instead of 0.0.0.0/0 to only allow access from certain IP addresses.
When you have applied these modifications to your configuration files, you will need to restart the PostgreSQL server.
/etc/init.d/postgresql start
Now, you will be able to login to your server remotely