Postgresql#12 on Big Sur Won't Start - postgresql

Installed postgresql#12 and for some reason won't start:
/opt/homebrew/var/postgresql#12 stable ❯ pg_ctl -D /opt/homebrew/opt/postgresql#12/bin/postgres start
pg_ctl: could not open PID file "/opt/homebrew/opt/postgresql#12/bin/postgres/postmaster.pid": Not a directory
/opt/homebrew/var/postgresql#12 stable ❯ brew services list
Name Status User Plist
postgresql#12 error rich /Users/rich/Library/LaunchAgents/homebrew.mxcl.postgresql#12.plist
~ ❯ sudo su - postgres
su: unknown login: postgres
~ ❯ brew services start postgresql#12
Service `postgresql#12` already started, use `brew services restart postgresql#12` to restart.
~ ❯ brew services restart postgresql#12
Stopping `postgresql#12`... (might take a while)
==> Successfully stopped `postgresql#12` (label: homebrew.mxcl.postgresql#12)
==> Successfully started `postgresql#12` (label: homebrew.mxcl.postgresql#12)
~ ❯ sudo su - postgres
su: unknown login: postgres
Not sure why there isn't a postgres user created with the install.
Anybody know what I can do to get this back in line? Cheers

Related

Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/josh/Library/LaunchAgents/homebrew.mxcl.postgresql#14.plist` exited with 5

When trying to start postgresql
➜ ~ brew services start postgresql
Warning: Use postgresql#14 instead of deprecated postgresql
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/josh/Library/LaunchAgents/homebrew.mxcl.postgresql#14.plist` exited with 5.
Getting "error" as status when running brew services list
➜ ~ brew services list
Name Status User File
postgresql#14 error 256 root ~/Library/LaunchAgents/homebrew.mxcl.postgresql#14.plist
PSQL was working perfectly fine, shut down my laptop (did not update) and when I turned it on the next day psql was not working. I am on OSX Version 12.6 (Monteray).
Had the same error today 🤓 on my Mac Ventura 13.0. Did these steps and it helped.
Run rm /usr/local/var/postgresql#{YOUR_VERSION}/postmaster.pid to remove postmaster.pid file. this is usually caused by an error in the postmaster.pid file.
Run brew services stop postgresql to stop the current postgresql service.
Then finally run brew services start postgresql, a new postmaster.pid file will be generated.
If this doesn't work you can run brew doctor and see if it will return Your system is ready to brew. If there are warnings 🥶, you can share them here with the community for more details.?
I had the same issue on 13.0 on M1 pro, all is did was brew services restart postgresql#14, it shut down, restarted and ran fine, issue gone.
Had the same issue, but couldn't get Postgres 14 working, and ended up just upgrading to Postgres 15, which I did get to work.
The steps looked like this (version numbers might vary)
brew services stop postgresql#14
brew install postgresql#15
# This command will copy data over to the new database
brew /opt/homebrew/Cellar/postgresql#15/15.1/bin/pg_upgrade -b /opt/homebrew/Cellar/postgresql#14/14.6/bin/ -d /opt/homebrew/var/postgres/ -D /opt/homebrew/var/postgresql#15/
brew services start postgresql#15
In my case, I had postgresql#13 and postgresql#14 install with brew on Ventura 13.1
I first removed postgresql#13 and all data within :
brew remove postgresql#13 and rm -rf /usr/local/var/postgresql#13
This assure me that the previous folder is fully remove, however, I did not care about my local data ... you may want to take care of it before doing this
After that, I reinstall postgresql#14 within the following commands :
# Remove postgresql 14 with brew
brew remove postgresql#14
# Reinstall postgresql 14 with brew
brew install postgresql#14
# Remove all the files in the db folder
rf -rf /usr/local/var/postgresql#14/*
# Kill all process that run any db of the postgresql 14 folder
pkill -f /usr/local/var/postgresql#14
# Initialize the db folder for postgresql 14
initdb --locale=C -E UTF-8 /usr/local/var/postgresql#14
# Restart postgresql with brew (should say that it's already running)
brew services start postgresql#14

Brew Postgresql Starts But Process Is Not Running

I have installed Postgres via Brew on a Mac. Then, I have tried to start it
| => brew services restart postgres
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
After that, I inspect to see if the process is running
(base) ________________________________________________________________________________
| ~/ # MacBook-Pro (user)
| => ps -ef | grep postgres
501 61568 561 0 5:00PM ttys000 0:00.00 grep postgres
In addition, brew services produces the following
| => brew services
Name Status User Plist
dnsmasq unknown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
emacs stopped
postgresql error root /Library/LaunchDaemons/homebrew.mxcl.postgresql.plist
postgresql#12 stopped
rabbitmq stopped
unbound stopped
Any help on how to troubleshoot this is appreciated.
Unlike a builtin pkg manger in Linux, Homebrew on macOS doesn't require root privilege during most brew command. The only exception is sudo brew services when you're starting a services listen on port < 1024.
Answer to your question: you messed up file permission with sudo brew services.
The solution works for x86 Mac. I've not tested it on M1 mac. (Homebrew stores related files under /usr/local on x86 Mac, under /opt/homebrew under M1 Mac.)
### Run in Bash or Zsh
# Stop postgresql
sudo brew services stop postgresql
# In case service file is copied to ~/Library/LaunchAgents as well
brew services stop postgresql
# Fix permission of homebrew files
sudo chown -R $USER:admin $(brew --prefix)/*
# Remove socket like `/tmp/.s.PGSQL.5432`
# Restart postgresql without sudo
brew services start postgresql
Besides above fix, you may also need to
Do a db migration from psql 12 -> psql 13, check brew info postgresl for detail
Start psql manually and check the start log
# Change /usr/local to /opt/homebrew on M1 Mac
# Check the start log
pg_ctl -D /usr/local/var/postgres start
# to stop it
pg_ctl -D /usr/local/var/postgres stop
sudo and brew
I'm not saying postgresql can't be started as root, but the Homebrew and brew services are not designed to work with sudo.
And sudo brew services changes some of the files' owner to root. You'd better change them back being owned by yourself.
Here's an example (check the Warning part)
❯ sudo brew services start adguardhome
Warning: Taking root:admin ownership of some adguardhome paths:
/usr/local/Cellar/adguardhome/0.106.3/bin
/usr/local/Cellar/adguardhome/0.106.3/bin/AdGuardHome
/usr/local/opt/adguardhome
/usr/local/opt/adguardhome/bin
/usr/local/var/homebrew/linked/adguardhome
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
Warning: adguardhome must be run as non-root to start at user login!
==> Successfully started `adguardhome` (label: homebrew.mxcl.adguardhome)
sudo brew services is not that intelligent enough to change the files' onwer bach to $USER automatically.
I've written a script to do this: brew-fix-perm. But this is not enough in your case. You have to change back the ownership of postgres configuration files under $(brew --prefix)/var/postgres. That's why I put sudo chown -R $USER:admin $(brew --prefix)/*.
Related Answer
I've known a stubborn guy stick with sudo brew services to start mysql. And a more detailed answer about brew services is there. You may wanna have a check.
Short answer:
brew services stop postgresql
sudo chown -R $(whoami) $(brew --prefix)/*
brew services start postgresql

"brew services restart mongodb-community" throws a status of error under brew services list. What is this error?

I recently completed the m001 basics course on Mongo University and connecting to Atlas with the connection string was not a problem. With experimenting I messed up and now I am not able to start mongo. The steps I followed are (from my root directory):
brew doctor --verbose
to make sure Homebrew is running correctly and there were no issues.
HomeBrew version: 3.0.1,
macOs: 11.1,
Homebrew Cask Staging Location: /usr/local/Caskroom
Homebrew Cask Taps: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask (3823 casks)
/usr/bin/xattr
brew cleanup
brew update
brew tap mongodb/brew
Mongo Docs installation
brew install mongodb-community#4.4
Already downloaded: /Users/kevinturney/Library/Caches/Homebrew/downloads/269692f6b2d908000ecd7602021f4826947a782576c1fea760d25ece5ccbb521--mongodb-macos-x86_64-4.4.3.tgz
brew services start mongodb-community#4.4
Service mongodb-community already started, use brew services restart mongodb-community to restart.
brew services restart mongodb-community
==> Successfully stopped mongodb-community (label: homebrew.mxcl.mongodb-community)
==> Successfully started mongodb-community (label: homebrew.mxcl.mongodb-community)
kevinturney / $ brew services list
Here is the error:
Name
Status
User
Plist
mongodb-community
error
kevinturney
/Users/kevinturney/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql
stopped
postgresql
stopped
redis
stopped
unbound
stopped
I checked the processes,
MongDB University-processes
ps -ef | grep mongo
501 10770 81999 0 10:34AM ttys007 0:00.00 grep mongo
ps -ef | grep mongod
501 10776 81999 0 10:34AM ttys007 0:00.00 grep mongod
ps -ef | grep mongos
01 10781 81999 0 10:34AM ttys007 0:00.00 grep mongos
mongo --version
MongoDB shell version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
allocator: system
modules: enterprise
build environment:
distarch: x86_64
target_arch: x86_64
mongod --version
db version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
allocator: system
modules: enterprise
build environment:
distarch: x86_64
target_arch: x86_64
When I run brew services start mongodb-community it successfully starts and then
mongo this is the result:
kevinturney / $ brew services start mongodb-community
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
kevinturney / $ mongo
MongoDB shell version v4.2.2<br/>
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br/>
2021-02-17T11:37:32.192-0500 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, <br/>connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:341:17<br/>
#(connect):2:6
2021-02-17T11:37:32.195-0500 F - [main] exception: connect failed
2021-02-17T11:37:32.195-0500 E - [main] exiting with code 1
I followed a very similar StackOverflow question, went though mongo docs, uninstalled, reinstalled, Also, tried this great post I am not sure what to try next.
If you are using macOS Catalina / BigSur Above this fix will work:
Go to command line and execute these commands, you need to use SUDO else this will not work.
We first remove the folder mongodb,
sudo rm -rf /usr/local/var/mongodb
then, we add it manually,
cd /usr/local/var && mkdir mongodb
Now, we run the brew service as below, please mention the mongodb version at the end, as below:
brew services start mongodb-community#5.0
If you get below response please restart the service,
Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.
To restart the service use below, please mention the mongodb version at the end:
brew services restart mongodb-community#5.0
Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-commu
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu
Now we list all services, with below command:
brew services list
Output:
Name Status User Plist
mongodb-community started xxx homebrew.mxcl.mongodb-community.plist
Open your Terminal and type mongod –version to verify your installation.
Could be permission issues Check ownership of /tmp/mongodb-27017.sock Try to remove this file and start the service again
via:https://www.mongodb.com/community/forums/t/help-brew-mongodb-community-5-0-error-macos/125648

The problem when installing mongodb on MacOS

I tried to install mongodb on my Mac. But the error message below appeared.
Someone please tell me the solution.
Updating Homebrew...
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.1.tgz
Already downloaded: /Users/t17akeru/Library/Caches/Homebrew/downloads/d46781539dca95a7ced7d9b466b13bd4cc0202f17a8bf4bd499a5e1a4a241262--mongodb-macos-x86_64-4.4.1.tgz
Error: Failed to install plist file
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mongodb/brew/mongodb-community`
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb-community/4.4.1: 11 files, 136.8MB, built in 4 seconds
==> `brew cleanup` has not been run in 30 days, running now...
Error: Permission denied # apply2files - /usr/local/share/5.2/luarocks/add.lua
MongoDB was correctly installed. The problem is the installation of the plist file (which allows you to launch MongoDB when your computer starts, for example).
You can still run MongDB using mongod --config /usr/local/etc/mongod.conf.
Also, brew seems to have some permission problem. Here are some possible resolutions from this GitHub issue:
Reinstalling Brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Resetting permissions in /usr/local
sudo chown -R $(whoami):admin /usr/local/* \
&& sudo chmod -R g+rwx /usr/local/*
You can then try to run MongoDB's post-install script using brew postinstall mongodb/brew/mongodb-community
Hope it helped !

postgresql not installed but homebrew reports it is

I've never had an issue like this before - normally brew install postgres works and everything is fine.
I've had instances with this machine where I see "Mac OSX restarted due to a problem" and usually there is a stale postmaster.pid file that I can delete and restart postgresql and everything is fine.
Not any longer - there is something out of whack and I don't know how homebrew works well enough to troubleshoot this.
➜ ~ pg_ctl
zsh: command not found: pg_ctl
➜ ~ brew info postgresql
postgresql: stable 13.1 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl#1.1 ✔, readline ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
https://www.postgresql.org/docs/13/app-initdb.html
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
==> Analytics
install: 188,386 (30 days), 549,953 (90 days), 1,863,554 (365 days)
install-on-request: 180,714 (30 days), 528,971 (90 days), 1,789,016 (365 days)
build-error: 0 (30 days)
➜ ~ ls -ltra /usr/local/var
total 0
drwxrwxr-x 4 myhandle admin 128 Aug 21 2019 homebrew
drwxr-xr-x 4 myhandle admin 128 Apr 18 2020 log
drwxr-xr-x 15 root wheel 480 Dec 1 17:32 ..
drwxrwxr-x 4 root wheel 128 Dec 2 08:56 .
I have exactly the issue reported here - https://discourse.brew.sh/t/postgress-install-fails-in-postinstall-step/6209
The only answer says "I ran the install script on the old installation" which means nothing to me - I tried brew postinstall postgres#12 imagining this to be what is meant by the "old installation" but I get the exact same result:
➜ ~ brew postinstall postgresql
==> Postinstalling postgresql
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql`
➜ ~ brew postinstall postgresql#12
==> Postinstalling postgresql#12
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall postgresql#12`
Any ideas?
UPDATE: it's starting to feel like /usr/local/var and /usr/local/bin have gotten confused by either me, homebrew, or the postgres cask because the error messages don't match the reality:
➜ ~ pg_ctl -D /usr/local/var/postgres start
pg_ctl: directory "/usr/local/var/postgres" does not exist
➜ ~ pg_ctl -D /usr/local/bin/postgres start
pg_ctl: could not open PID file "/usr/local/bin/postgres/postmaster.pid": Not a directory
➜ ~ mkdir /usr/local/bin/postgres
mkdir: /usr/local/bin/postgres: File exists
Why does homebrew suggest running pg_ctl from /usr/local/var but postgres process does not exist here after fresh install? Why do I find it in /usr/local/bin ? Then when I try to launch from bin/ it's asking for the postmaster.pid file in bin/ but of course there is no postgres directory in bin/ as these are the processes themselves...
I've run these steps and postgresql has started working - I'll admit that this is a case of "better lucky than good" because I was just stabbing in the dark here -
➜ ~ sudo mkdir /usr/local/var/postgres
➜ ~ sudo chown -R `whoami` /usr/local/var/postgres
➜ ~ initdb -D /usr/local/var/postgres
The files belonging to this database system will be owned by user "tyler".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... America/Chicago
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /usr/local/var/postgres -l logfile start
➜ ~ brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
➜ ~ brew postinstall postgresql
==> Postinstalling postgresql
Success
Then I could get back into Rails-world and migrate the DB properly - I surmise that this means the homebrew installation step (perhaps the postinstall step that kept failing) wasn't creating the /usr/local/var/postgres directory as it should have, or it was trying with insufficient permissions to do so and failing silently.
Once I created the directory manually and chown'd it, things started to work as they should.
For MacOS: monterey I followed these steps:
Check if postgres is installed or not:
brew list | grep postgres
Initialize DB:
initdb /opt/homebrew/var/postgresql
Start DB:
pg_ctl -D /opt/homebrew/var/postgresql -l logfile start
checking if the db started enter below command:
psql postgres