Remove _postgres user safely and completely from Mac /etc/passwd
Use the command brew remove postgresql
. Or investigate the uninstall scripts manually.
Edit: Have you tried this?
Quit Postgres.app & drag it to the Trash
Delete the data directory (default location: ~/Library/Application Support/Postgres)
Delete preferences for Postgres.app by executing the following command: defaults delete com.postgresapp.Postgres2
Remove the $PATH config for the command line tools (optional): sudo rm /etc/paths.d/postgresapp
Edit 2: To delete a user from the command line, boot into single user mode. Hold Command-s at startup. Check the filesystem: /sbin/fsck -fy If no remaining errors, mount the filesystem: /sbin/mount -uw / Start up directory services: launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist Note that single user mode said to use com.apple.DirectoryServicesLocal.plist, but that didn't work -- this did. Find what groups the user belongs to: dscl . -list /groups GroupMembership | grep username -- repeat for each group except for the user's own group. Remove the group corresponding to the username: dscl . delete /groups/username (this may not be necessary -- you may get an error that the group doesn't exist; you can ignore it and go on). Remove the user account: dscl . delete /users/username At this point, you may wish to remove or archive the user folder in /Users. You may wish to remove the .AppleSetupDone file in /var/db to cause the Setup Assistant to run when next booted. Type reboot to reboot the system or shutdown -h now to shut down the system.
Related videos on Youtube
![AJP](https://i.stack.imgur.com/3RiAU.png?s=256&g=1)
AJP
Updated on September 18, 2022Comments
-
AJP almost 2 years
I'm am attempting to reinstall PostgreSQL as I am unable to log into it at all. I realise I had installed it a long time ago using both the installer from the postgres website and
brew install postgres
. I have uninstalled both of these now:- uninstalled using
brew uninstall --force postgresql
to remove all versions installed via brew. - uninstalled using
sudo /Library/PostgreSQL/9.5/uninstall-postgresql.app/Contents/MacOS/installbuilder.sh
- manually removed
/Library/PostgreSQL
(rm -rf /Library/PostgreSQL
) - manually the PostgreSQL user (via the Mac
Users & Groups
).
However I have a
_postgres
user left in/etc/passwd
:$ grep post /etc/passwd _postgres:*:216:216:PostgreSQL Server:/var/empty:/usr/bin/false
There are no
userdel
orusermod
commands available on Mac (10.11 El Capitan) and the alternative seems excessively complex (but perhaps necessarily so?) - uninstalled using
-
AJP about 7 yearsthanks for the help. I have edited answer to make it clear I have already run this command
-
user2497 about 7 yearsOh - well, perhaps then reading the install/uninstall scripts will not be helpful.
-
user2497 about 7 yearsI once messed around in the guts of OSX, assuming a normal passwd/group configuration. Even then it was a filthy experience. Jobs certainly made FreeBSD weirder.
-
AJP about 7 yearsWow... that is intimidating. Thank you very much for your answer. Playing whack-a-mole with postgres has at some point resulted in success. When I reinstall with brew and ran
createdb `whoami`
I can now login to a psql shell successfully :) Thank you very much for the detailed answer. I'm going to mark this as correct though I haven't summoned the courage to try it! -
user2497 about 7 yearsIt is prudent to perform a backup. I am not sure why they got rid of the classical passwd/group system, but it is certainly possible regardless of this obfuscation. When I went cavediving in OSX, I was also removing a user account that wouldn't be removed with conventional weapons, but that was long ago.
-
user2497 about 7 yearsIIRC, on a multivolume setup, if you have your Users folder on another disk, you must invoke
mount -uwa