I have installed PostgreSQL for a long time but just currently learning it.
Here is what happened if I run psql in the command prompt
C:\Users\VandaRsq>psql
Password for user Vanda Rashq:
Since I forgot the password for the Vanda Rashq role but I remember for the postgres role, I run psql -U postgres.
I tried to list the role by using du command and the result is this:
I also tried using SELECT rolname FROM pg_roles command and yield:
I have tried to follow this tutorial and do ALTER USER "Vanda Rashq" WITH PASSWORD 'new_password'; but it returns ERROR: role "Vanda Rashq" does not exist
My question is, does the "Vanda Rashq" role actually still exist? If yes, how to reset (change) the password in case I forgot the password? If not, how to change the default role when running psql to postgres role
Notes: I have tried to uninstall the PostgreSQL and remove all of the directories but when I try to run psql, it still ask Password for user Vanda Rashq
If the user you're looking for is not listed after calling \du in psql then the user does not exist in the database.
Btw, you could also use a select to retrieve information about database users: select * from pg_catalog.pg_user;
EDIT:
Like #jjanes pointed out you get challenged for a password based on the USER configuration in yourpg_hba.conf (see docs).
For authentication method peer it is stated:
Obtain the client's operating system user name from the operating system and check if it matches the requested database user name.
Windows 10 user trying to either delete a role permanently so the error doesn't show up or create a superuser with no password.
Been searching for hours to no avail. Tried:
Creating a new user and database with
CREATE USER Nistic SUPERUSER;
CREATE DATABASE registration WITH OWNER Nistic;
The role was successfully created, but upon logging out, and back in, typing "psql" into the terminal will still bring up the same error. [EDIT] I can login with the postgres username by typing psql -U postgres, but for whatever reason the default username is still set to Nistic.
I've already checked the conf file and set all the methods to trust. I tried dropping the user and recreating the user.
I just wanted the title to include User to be more general, despite showing Nistic above.
I've pretty much tried everything else that I could find on SO.
Please help, thank you.
Screen below to show some of the oddness (please read each line before commenting - the issue is that after getting rid of Nistic, it still expects Nistic)
I just installed PostgreSQL 13 on Windows 11. When I run the command psql by default it uses the user aaron, the name of my Windows user account. However, it asks me for a password. I have tried all passwords associated with my Windows account as well as the default password I set for the user postgres, none of which worked. I was able to log in with psql -U postgres, and I ran the command \du, and there was only one role in the list, postgres. Later I created the role aaron without specifying a password, but it still asks for a password.
So, did the user aaron exist initially or not? If not, then how was it the default user when I ran the psql command? What is the password for this user?
So, did the user aaron exist initially or not
No, it did not. The only user that is created when installing Postgres (or more precisely: when running initdb) is postgres.
If not, then how was it the default user when I ran the psql command
Quote from the manual
The default user name is your operating-system user name, as is the default database name
psql simply uses the operating system user as the default username to connect to the server. It knows nothing about the database user(s) until it tries to connect with a specific username and potentially password.
You can set a different default through the (Windows) environment variable PGUSER
Later I created the role aaron without specifying a password, but it still asks for a password.
Whether or not a password is required is controlled through pg_hba.conf
When you run psql command and don't provide a username it considers (that the current system user which in your case is aaron) is the user you want to use to login and hence you see a user which really don't exists.
Now regarding the password you might want to check a file generally named as pg_hba.conf which hold the essentials of who can connect (IPs) what username can he have and should that user be asked for password.
Now generally you will find answers saying that find this file and write down trust everywhere (which basically means if some specific user from a specific IP access this database of replication then don't ask for a password and let him enter), which you should not do until and unless you are utterly sure the postgresql server is just just local and has no real-time purpose.
So concluding you want to create a user with some encrypted password and then provide necessary privilege.
P.S: I have tried all these on a linux machine, but the server configurations are more or less same.
It's worth pointing out that PostgreSQL has it's own users and permissions independent of the OS. Some installers will automatically create a postgres OS user. I'm not sure what Windows does.
It seems that PostgreSQL can do Windows authentication. See this question for details on how to configure that.
As #a_horse_with_no_name has said, connection configuration is controlled by pg_hba.conf
PostgreSQL tries not to leak information about its users, so the failed-authentication attempt is not given much information about why it failed.
If you look in the server's log file, rather than the clients, you should first see messages about 'aaron' failing to authenticate because the user does not existing, and then (after you create it) about it failing to authenticate because it has no password assigned.
When you created the user, you should have assigned it a password if you wanted to use a password. Or as a superuser in psql, create it without a password and then assign one with \password aaron That way the password won't be visible on the screen, or in the log files.
To give a concise, direct answer:
right click on Windows icon and click “System”.
scroll down to “Advanced System Settings”.
click Environment Variables.
in “System variables”, click “New”.
Set Variable Name to PGUSER and Variable Value to postgres.
Or, in cmd: set PGUSER=postgres, which also sets it globally.
go to "Services" (in Task Manager), and restart the "postgresql-X64" service.
Whenever I write psql in the cmd, it automatically asks the password for a user name 'Master'.
Now, I don't have a user named that way so I don't have a password for it.
I don't see it happening anywhere else.
What I do want is, whenever I write psql, it will use the 'postgres' user instead of the non-existing 'Master' one.
Also, I see people in tutorials just writing psql and it doesn't ask them for the password. So, I would like to do that as well.
Thanks in advance
How do I change a user's password in Postgresql (using PgAdmin) so that I can connect with Rails to the Postgres database using these credentials?
So far: In PgAdmin I right clicked the database name, clicked Create Script and then typed the command:
CREATE USER usr1 WITH PASSWORD 'pwd1!##$';
Question: where exactly in PgAdmin am I able to see the user and password or list of users and passwords? So far I am unable to see this in Db properties --> 'privileges'?? Any tips on other security elements? or something that can be improved in my current methods? Thanks a lot.
In the file "pgpass.conf" in this path:
C:\Users\[User's name]\AppData\Roaming\postgresql
Login roles are common for all databases in a server. You can see them in the bottom of the object browser (left panel).
To execute arbitrary SQL query open Query tool (Ctrl-E) from Tools in main menu or click on icon with 'SQL' (previously you have to select a database).
To change user password execute SQL:
ALTER ROLE username PASSWORD 'newpassword'
ALTER USER is an alias for ALTER ROLE. Read about it in documentation.
Run the query from pgadmin:
SELECT rolname, rolpassword FROM pg_authid;
This requires superuser privileges to protect the password.