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"?
PostgreSQL database passwords are separate from operating system user passwords. The password for each database user is stored in the pg_authid system catalog. Passwords can be managed with the SQL commands CREATE ROLE and ALTER ROLE, e.g., CREATE ROLE foo WITH LOGIN PASSWORD 'secret' , or the psql command \password .
For most systems, the default Postgres user is postgres and a password is not required for authentication. Thus, to add a password, we must first login and connect as the postgres user.
PostgreSQL can also be installed on macOS using Homebrew. Please see the Homebrew documentation for information on how to install packages. A list of PostgreSQL packages can be found using the Braumeister search tool.
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-domain socket access by postgres
db user to all databases with no password required.
Now clear and redefine the password for postgres
system user (which is automatically created during PostgreSQL installation):
sudo passwd -d postrges
sudo su postgres -c passed
The special thing about this user account is that postgres server allows it to connect to the database, no questions asked.
Now, to define an explicit password for postgres
db user using which you can login via other means than local Unix-domain socket connection, run:
su postgres -c psql template1
psql> ALTER USER postgres WITH PASSWORD '<password>';
You will be asked for the postgres
system user account password before this command can be run. On successful completion, type \q
to quit psql
shell, and you are done with resetting the password for postgres
db user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With