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

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.

Related

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.

Cannot install postgres with brew. Get "FATAL: role "postgres" does not exist" no matter what command I try

I've tried to install postgres 13.1 on my Mac using homebrew. (Also tried versions 11 & 12 which at one time were installed on this Mac, but encountering same error with those versions now). Am using notes I took from previous installs & of course google/stackoverflow. Tried many things/many times, but always, if I run psql, createuser, createdb (any postgres command), it responds with:
FATAL: role "postgres" does not exist
Also tried just creating a postgres user on my Mac to run install from that account; no luck.
Also tried postgresql install from the enterprisedb.com site. That worked, but seems klunky & seems to rely on .sh scripts. Interestingly, got the 'role postgres does not exist' error after the edb install too, but noticed if I just entered 'postgres' twice on the command line it worked. Example:
/Library/PostgreSQL/13/bin/psql -h localhost -p 5432 -U postgres postgres
This trick doesn't work tho with the brew install.
Understand I need to create the postgres role, but I can't find a command to do this that doesn't complain that the role doesn't already exist.
Any help would be so so appreciated!
Most sites documenting postgres install with homebrew said to use commands like:
psql postgres
or
createuser postgres
Those didn't work for me, but this did:
psql -d postgres -U <myUserName>
Attaching a screenshot to try to summarize the install experience & what worked:
screenshot
Can you try:
/Library/PostgreSQL/13/bin/psql
and then:
CREATE USER postgres SUPERUSER;
?
This document solved it for me: https://enrq.me/dev/2021/01/13/fix-role-postgres-does-not-exist/
The gist: run createuser -s postgres -U <os-username>

psql connection to AWS PostgreSQL 10.4 results in pw auth failed?

Question
I set up an AWS RDS PostgreSQL 10.4 database. The dataset is in a private network, therefore, I use a bastion to forward the connection to it. I can then connect using Postico but not using psql.
Details
I installed PostgreSQL locally using brew install postgres. The command output is (and on a AWS instance see update):
❯ psql --version
psql (PostgreSQL) 10.5
Then I use the following SSH command to tunnel:
ssh -q -o "ConnectTimeout 3" -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" -i bastion-key.pem -L 5432:xxxxxx.xxxxx.eu-central-1.rds.amazonaws.com:5432 ec2-user#xx.xx.xx.xx -N
Then I connect using Postico .. everything fine!
Last but not least I try to connect using the following command:
❯ psql \
--host=127.0.0.1 \
--port=5432 \
--username=USERNAME \
--password \
--dbname=DBNAME
Password for user USERNAME:
psql: FATAL: password authentication failed for user "USERNAME"
FATAL: password authentication failed for user "USERNAME"
I use a macOS High Sierra Version 10.13.6 Macbook 13".
Update 2018-12-05:
Tried it also from a Amazon image running Amazon Linux release 2 (Karoo) same result with psql 9 as version 10. Version 10 was installed following this recommendation.
Solved, still a really shitty problem!
I generated my PostgreSQL passwords using secrets.token_urlsafe(90) Python3 method, which resulted in strings including [_-] which psql could not handle.
Using secrets.choice(string.ascii_uppercase) 1 with the right selection solved the problem!
Long story short: Use only characters and digits for your password and you will have no problems!

PostgreSQL: Can't log into Postgres - sudo broken?

Hey so after I ran into somes issues I decided to uninstall Postgres and re-install it (re install a newer version btw).
I'm trying to access postgres to create a new db for my Rails app so I run su postgresor su _postgres then I am asked a password but nothing that I enter works.
So I tried sudo -u postgres psql and got
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
I tried also to disable SIP (see: here)
but it didn't work either. same results.
I don't know what to do. Any idea ? I am using Mac OS High Sierra 10.13.6.
Thanks to #gordon Davidson and #wildplasser 's help, I found the solution:
sudo -u myusername psql postgres
I had this same challenge when trying to access a PostgreSQL database.
When I run the command below:
sudo -u postgres psql
I get the error below:
sudo: unknown user: postgres
sudo: unable to initialize policy plugin
The issue was that I did not have the PostgreSQL database server installed on the server. The server only had a MySQL database server set up on it.
That's all.
I hope this helps
From your EC2 node issue the following command to test if database is reachable.
/opt/gitlab/embedded/bin/psql -U YourExistingUsername -d template1 -h AWS-RDS-POSTGRES-ENDPOINT

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.