Server closes connection unexpectedly when connecting to Azure Postgres - postgresql

I'm trying to connect to Azure Postgresql using psql from my local machine and get the following error:
$ psql "host=username.postgres.database.azure.com port=5432 dbname=postgres user=username#domain password=mypassword sslmode=require"
psql: error: could not connect to server: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Local Postgres version: 12.1, Azure Postgres database version: 10, macOS Majove.
This issue only recently started after I reinstalled Postgres using Homebrew. I have no issues running $ psql --host=localhost.
I've tried installing postgresql#10 with homebrew so that when I run psql I get the message psql (12.1, server 10.11). But when I attempt to log into Azure Postgres I get the same error as above.
I'm fairly new to Postgres and Azure and would appreciate any suggestions.
Update:
Thanks for the comments and feedback.
I properly installed Postgres 10 with Homebrew and linked it to fix the problem.
$ brew services stop postgresql
$ brew install postgresql#10
$ brew services start postgresql#10
$ brew link --overwrite --force postgresql#10
I can now access the Azure database as expected.

In this case, you could install the PostgreSQL Client for macOS with Homebrew properly then link it as it will symlink all the tools into the /usr/local/bin directory.
To fix this issue, run the following commands:
$ brew services stop postgresql
$ brew install postgresql#10
$ brew services start postgresql#10
$ brew link --overwrite --force postgresql#10
Ref: https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/

Related

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed:

NOTE: I have a MacOS Monterey M1 chip.
After I put in the command line - psql postgres - I get the response state below.
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refused
Is the server running locally and accepting connections on that socket?
I have done the following already:
Restarting PostgreSQL using homebrew brew services restart postgresql
Re-installing PostgreSQL using Homebrew
brew uninstall postgresql
Updating PostgreSQL using Homebrew
brew install postgresql#14
brew services start postgresql#14
brew link postgresql#14 --force

How do i install Postgres on Ubuntu and create a superuser?

I have successfully installed Postgres on Ubuntu 20.04 by running the following commands:
$ sudo apt-get update
$ sudo apt-get install postgresql postgresql-contrib libpq-dev
which was successful. I then run the command:
$ sudo service postgresql start
which was also successful.
However, the command
$ sudo -u postgres createdb $USER
failed. The error message was as follows:
createuser: error: could not connect to database template1: 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"?
Please help me out.

PostgreSQL 13.3 installation on MacOS (Big Sur) failed with error: Failed to initialise the database cluster with initdb

Downloaded the PostgreSQL installer from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads, and tried to install it on my new Macbook Pro running Big Sur.
The installation went fine, but it failed when executing the script /Library/PostgreSQL/13/installer/server/initcluster.sh. I traced to the following script:
su - $OSUSERNAME -c "$INSTALLDIR/bin/initdb --pwfile $INSTALLDIR/installer/server/initdbpw.$$ --encoding=utf8 -A scram-sha-256 -U \"$SUPERNAME\" -D \"$DATADIR\""
Apparently, su - postgres does not work because the new service account postgres is not enabled for login. Maybe this script should use sudo -u postgres instead of su - postgres.
I got it working by updating the service account postgres as follows, so it is enabled for login:
sudo dscl . -passwd /Users/postgres 'MyNewPassword'
sudo dscl . -read /Users/postgres
After you verify that the password of the account is no longer "*", you can uninstall and reinstall PostgreSQL, so it can initialize the db, as long as you provide the same password for postgres when you re-install it.

Unable to Open Postgres shell in Mac Terminal ZSH

Disclaimer that I'm both new to Mac & Postgres. I recently got the 2020 MacBook Pro and have been setting it up for my personal [learning] development computer. In the process of attempting to install Postgres, I am having issues and am not sure what I am doing wrong / missing.
I've installed Postgres via Homebrew using:
brew install postgresql
All seems to have been installed fine, but whenever I try to open up a Postgres shell to enter commands into (coming from a Windows/Bash background), I keep getting the same response:
>> psql
[1] ##### killed psql
>> psql postgres
[1] ##### killed psql postgres
>> psql -U postgres
[1] ##### killed psql -U postgres
When asking where psql is:
>> where psql
/opt/homebrew/bin/psql
When trying to make sure postgresql is launched I run as instructed in the brew installation output:
>> pg_ctl -D /opt/homebrew/var/postgres start
pg_ctl: directory "/opt/homebrew/var/postgres" is not a database cluster directory
And when attempting to check the Postgres version:
>> postgres -V
[1] ##### killed postgres -V
I am not sure what I'm missing and any help would be appreciated! I'm trying to set up Postgres so I can use it for an Angular tutorial I'm trying to understand. The backend connection has never been my strong-suit and I'm working to fix that.
I've had the same problem. Now there's a new version of Postgres that works (stable 13.3). Just upgrade the app via brew upgrade.

postgresql: no such file or directory

I'm trying to install a postgresql database on my VPS server by using this guide.
In there it says
sudo apt-get install postgresql postgresql-contrib libpq-dev
And then
sudo su - postgres
createuser --pwprompt
exit
When I run createuser --pwprompt it asks me to create a password, once I fill it in I get the following error:
createuser: could not connect to database postgres: 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"?
If I do psql --version I get psql (PostgreSQL) 9.4beta3
And which psql outputs /usr/bin/psql
Any idea on how to fix this problem?
Update
Running pg_ctl gives another error
WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'
The program 'pg_ctl' is currently not installed. To run 'pg_ctl' please ask your administrator to install the package 'postgres-xc'
Althgough reading up on postgres-xc shows quite a lot of other problems.