"sudo: unknown user: postgres" when trying to create postgres user - macos

I'm using Mac 10.9.5 and PostgreSQL 9.3.4. I'm following instructions for installing a third-party software package (Instructure Canvas) on my local machine) and the instructions say to execute:
sudo -u postgres createuser $USER
sudo -u postgres psql -c "alter user $USER with superuser" postgres
but upon executing the first command, I get the error
davea$ sudo -u postgres createuser $USER
sudo: unknown user: postgres
Other posts seemed to indicate I needed to prepend a "_" to my "postgres" user, but upon doing so, i get this error ...
davea$ sudo -u _postgres createuser $USER
createuser: could not connect to database postgres: FATAL: role "_postgres" does not exist
Any ideas what I need to do to get this to work properly?

It looks like whatever you installed has a system user named _postgres and a PostgreSQL user named postgres. Fun!
Try:
sudo -u _postgres createuser -U postgres myusername
(The numerous messy, conflicting and incompatible PostgreSQL installs used on OS X are a nightmare, argh).

Related

Unable to uninstall postgres completely from mac osx

I have completely unintsalled postgres and postgis from my system but still I am able to enter postgres through psql command . I need to uninstall completely because it is showing two psql and later I am able to reinstall afresh.
GW:~ User$ sudo -u postgres psql -h localhost
Password:
Password:
psql (9.1.5, server 9.1.14)
Type "help" for help.
postgres=#
I don't understand how is it showing 9.1.5 and 9.1.14 . I need to get rid of this. Any help would be really grateful.

-bash: initdb: command not found

I have installed PostgreSQL using the EnterpriseDB installation.
I ran sudo ./postgresql-9.3.5-3-osx.app/Contents/MacOS/installbuilder.sh --mode unattended and then ran open /Applications/TextEdit.app .profile to edit my .profile file newly created in /Users/Dhruv to add the line source /Library/PostgreSQL/9.3/pg_env.sh.
Running createuser Dhruv --pwprompt --username=postgres I got
-bash: createuser: command not found
Then running unknown-88-1f-a1-1b-c2-ec:9.3 dhruv$ sudo -u postgres /bin/createuser and various other methods I was able to set up something using some sort of password prompt. I know this later because using sudo -u postgres /Library/PostgreSQL/9.3/bin/createuser I got
createuser: creation of new role failed: ERROR: role "postgres" already exists
Running then initdb -D /Library/PostgreSQL/9.3/data I get
-bash: initdb: command not found.
Similiarly, if I try the same thing but while connected to postgres, sudo su - postgres and then initdb -D /Library/PostgreSQL/9.3/data I get again
-bash: initdb: command not found.
At a loss at what to do. 1) how do I know details of this supposed role "postgres" I created magically and 2) why is initdb not working?
How I fixed this is run brew doctor, and you might see the postgresql un der the Warning: that indicates there's unlinked kegs in your Cellar.
Try to run brew link postgresql. It will show some symlinks got created. Then run init db ... again.
Hope this help!
Who are you logged in as?
When you do sudo or su -, it will run init scripts for root, such as .bashrc and .bash_profile.
These may set up difference executable search paths between root, postgres, and you.
Try something like sudo initdb, or su - postgres -c initdb ... whichever user has the paths constructed correctly, so that the path gets set up.
You could also duplicate the path/lib creation code in your own environment, but that will break if it is ever changed.
Same thing happened to me. I'm new to OS X coming from Linux, here's what I had to do. I installed postgres via homebrew and when I did so I noticed it put everything it download to: /usr/local/Cellar/postgresql/($postgres_version)/
When I cd'd into that folder I saw a directory named bin so I cd'd and saw initdb right there. So I had to then add this to my path so I could use the command:
$ export PATH=/usr/local/Cellar/postgresql/9.4.4/bin:$PATH
hope that helps you

Why can't I get the postgresql server to run?

Ok. I have been trying to solve this problem for several days. I installed, uninstalled, and reinstalled Postgresql 3 times. I followed precisely the instructions in this forum: https://dba.stackexchange.com/questions/42048/cant-connect-to-the-postgres-server-ls-tmp-s-pgsql-5432-no-such-file-or-dir
I found this solution in many forums, so I tried to run:
$ mkdir /var/pgsql_socket/
$ sudo mkdir /var/pgsql_socket/
$ ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
But this didn't work. When I try to start the server it still says there is another one running and then proceeds to fail every time I try to create a database or type "psql"
I then tried to run the following in order to change the path of the commands from OS X's builtin version of postgres to my version and it seemed to work:
$ cd /usr/local/bin
$ rm postgres
$ ln -s /Library/PostgreSQL/9.2/bin/postgres postgres
$ rm psql
$ ln -s /Library/PostgreSQL/9.2/bin/psql psql
$ rm pg_ctl
$ ln -s /Library/PostgreSQL/9.2/bin/pg_ctl pg_ctl
So then I ran the following to create a user for postgres:
$ sudo -u postgres createuser --superuser $Sarah
$ sudo -u postgres createuser --superuser user_sarah
$ sudo -u postgres psql postgres
But it kept saying "unknown user postgres"
I then tried to install the Ruby pg gem, but that also failed, saying there was a problem with necessary libraries.
I have saved a text file of everything I tried to do in the terminal. Let me know if I should post that. Thanks.
update:
When I try to run this:
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
I get this:
-bash: /usr/local/bin/pg_ctl: No such file or directory
Which is different from a lot of other errors that I have seen posted on this problem.
first, you should verify that there is no postmaster running: ps -ef | grep postmaster. once you've verified the postmaster is not running, you should look into the postgresql command initd. Depending on your server installation, it may or may not be installed. You need to create a database before attempting to start postgres. It sounds to me like you got an installation that didn't install the main postgresql commands to /usr/bin, pg_ctl being one of these.
FYI: the postgres account is not a login account and is automatically created when installing postgresql, so it should be there if you had a good installation. You cannot sudo as postgres if postgres is not in the sudoers file.
The homebrew install of PostgreSQL does not create or need a postgres account, so all the mentions of doing sudo -u postgresor ps -fu postgres don't apply to your case.
The command brew info postgresql outputs various information about to start and stop it, you may read them. By contrast you don't want to put blind faith into what random users tell about how they "fixed" their non-working installation. In fact, the web carries a shocking amount of bad advice concerning PostgreSQL on MacOS X, and to me the answer you linked on dba.se is among them. It's wrong from start to finish, and you should note that it was not accepted as an answer. Certainly the author means well, but he fails to see that his own context can't be generalized to other installations.
The worst part is the suggestion to delete in /usr/local/bin/ the binaries postgres, psql, pg_ctl and soft-linking them into supposed equivalents inside /Library/PostgreSQL/9.2/bin/.
To me it just breaks the homebrew install.
No wonder that after doing this you get this error:
/usr/local/bin/pg_ctl: No such file or directory
So my answer would be to reinstall postgresql with brew to restart from a clean state, then make sure that all postgres commands you launch are from /usr/local/bin, and always first read the server log file passed to pg_ctl if you have any doubt on anything PG-related.

sudo: unknown user: postgres

I'm currently trying to run postgresql (9.3) on my iMac but I have some issues with user postgres and psql connection.
I bought an iMac old generation (with snow Leopard) that was migrated to Lion. As followed on other StackOverflow topics I added this line on my .bash_profile :
export PATH=/Library/PostgreSQL/9.3/bin:/usr/bin:$PATH
When launching pg :
sudo su postgres -c '/Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data/ -m fast start'
it returns :
su: unknown login: postgres
What should I do ?
The default postgres user in OSX 10.8 & 10.9 should be _postgres, you can use sudo -u _postgres to run the command
I got this same error (su: unknown login: postgres) when trying sudo su - postgres. I then managed to log in using sudo psql -U my.username postgres.
I could then create the appropriate users, etc.
Hope that helps.
Try to start from current user:
/Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data/ -l /usr/local/var/postgres/server.log start
Additional info: How to start PostgreSQL server on Mac OS X?

PostgreSQL on Mac OSX - cannot log in as postgres user

I installed postgresql and geodjango on Mac OSX following this tutorial word for word.
For some reason
sudo su - postgres
does not work. I put in my sudo password, but when I type "whoami" it's still my normal user login.
I know there is postgres user after I saw the list from
dscl . -list /Users UniqueID
Any idea why this is happening? I installed PSQL 9.1.1 server version.
Thank you.
The postgres account probably has disabled login rights and/or /bin/false as the login shell.
In this case you had best invoke postgresql commands directly, eg: sudo -u postgres psql
That should work even with a disabled login shell.

Resources