I have problem creating new psql user because I cannot log in psql as "postgres", I have tried
1. sudo -u postgres psql
2. sudo -u postgres createuser img_site -P -s -e
and they are all ask for password of "postgres" which I don't know. I have tried to change unix password of user "postgres"(I know it's dangerous) and it still tells me: password authentication failed for user "postgres". I also have tried GUI pgAdmin but it's the same error.
I don't know if it's related: I have created a symbolic link
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
in order to get rid of 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/pgsql_socket/.s.PGSQL.5432"?
Check pg_hba.conf
. it should have a line like this at the top (before all other entries):
local all postgres peer
this allows local unix socket access by postgres
db user to all databases with no password required.
Also clear and redefine password for postgres
system user:
sudo passwd -d postrges
sudo su postgres -c passwd
then run:
su postgres -c psql template1
psql> ALTER USER postgres WITH PASSWORD '<password>';
type \\q
to quit psql and you are done with resetting password for postgres
user.
sudo
doesn't want the password of the account you're switching to, it wants the password of the account you're switching from . It also requires that you be an admin (or otherwise listead in /etc/sudoers). su
, on the other hand, requires the password for the account you're switching to .
I was trying to setup postgres for Ruby on Rails and I was getting the the password authentication failed for user error. Check if the server is actually running:
pg_ctl -D /usr/local/var/postgres status
If you get
pg_ctl: no server running
Run
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Also you must include localhost in psql.
psql -U postgres -h localhost
This worked for me:
ALTER USER my_user WITH PASSWORD 'my_password';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.