Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lion update removed the 'postgres' user. How to restore it?

I've installed postgres with the kyngchaos installer a couple of months ago. I've now updated to OSX Lion, but the database server fails to start.

A comment on kyngchaos's blog (http://www.kyngchaos.com/blog/2011/20110723_lion) made me look at the 'postgres' user: it doesn't exist anymore! At least, I can't "sudo su postgres" anymore. So I figure that's the reason my server doesn't run.

How can I best restore that user?

like image 747
Reinout van Rees Avatar asked Jul 25 '11 09:07

Reinout van Rees


People also ask

How do I find my Postgres username?

PostgreSQL: Find Users in PostgreSQL Answer: In PostgreSQL, there is a system table called pg_user. You can run a query against this system table that returns all of the Users that have been created in PostgreSQL as well as information about these Users.

What is PostgreSQL user on Mac?

PostgreSQL is an open source relational database management system (RDBMS). It is the default database for macOS server.


2 Answers

(Answering myself)

In the end, the only thing I needed to do was to re-create the "postgres" user. Beforehand, I listed the contents of /usr/local/pgsql/ and saw that for instance the data/ directory was owned by user 101 and group postgres. So I wanted to tie that postgres user to the 101 userid:

sudo dscl . -create /Users/postgres
sudo dscl . -create /Users/postgres UniqueID 101

(And afterwards I restarted my mac as I didn't know how to start that postgres server by hand... ;-)

like image 167
Reinout van Rees Avatar answered Oct 23 '22 18:10

Reinout van Rees


I think, in your dscl command, rather than doing a -create, you want to do an -append. Apple tends to prefix underbars to daemon usernames. So Apple probably created a _postgres label for user 101. By doing a -create, you're deleting the default _postgres user, and replacing it with postgres, which could cause other problems down the road. Whereas if you do an -append, then you can user either _postgres or postgres to reference user 101. In any event, you should do a -list before doing either a -create or an -append, just so you know the lay of the land.

Note: I'm still running Snow Leopard, so can't verify that user 101 is indeed _postgres, but I expect Apple is still using the same naming conventions as in Leopard & Snow Leopard, and that's how it should work. Doing a -list will show you what you need to know to confirm my suspicions.

like image 3
Hawkeye Avatar answered Oct 23 '22 19:10

Hawkeye