patternsqlMajor
Forgotten PostgreSQL Windows password
Viewed 0 times
postgresqlforgottenwindowspassword
Problem
This morning I’ve been trying to connect the PostgreSQL database on my Windows 7 Professional desktop.
The default value is ‘postgres’, but sure enough I forgot what password I used when I originally installed it.
I have googled and found a post related to resetting your password. I followed the steps, but the end result is a bit different then mentioned in the post. I used—
to reset the password for my database but instead of a success message I am getting:
"System error 5 has occurred. Access is denied."
system error. How do I avoid this error and reset the password?
The default value is ‘postgres’, but sure enough I forgot what password I used when I originally installed it.
I have googled and found a post related to resetting your password. I followed the steps, but the end result is a bit different then mentioned in the post. I used—
net user postgres postgresto reset the password for my database but instead of a success message I am getting:
"System error 5 has occurred. Access is denied."
system error. How do I avoid this error and reset the password?
Solution
(Note: Not much of this is relevant to readers using PostgreSQL 9.2 or above from the EDB installers, which now have a greatly simplified default install using the
I have used
to reset the password for my database but instead of a success message I am getting
You've reset (or tried to reset) the service account password. PostgreSQL won't run as Administrator for security reasons and the installer generally sets it up with a "postgres" user account in PostgreSQL 9.1 and older1. On Windows you can't start a service as a user without saving the password of the user in the registry, so that's what the installer does.
If you change the password for the Windows user account
Thankfully I think another mistake prevented you from doing that. It looks like you're probably running your command prompt without using "Run as Administrator" on an unprivileged Windows user account or a machine with UAC, so it isn't running with the access permissions required to change the password for the
Before you try to change that password, make sure it's really what you want to do. What's the problem you're trying to solve here? Are you attempting to install a database update or something else that's asking for the password for the
Most likely you're just trying to log in to the database. For that, you use the (unfortunately completely unrelated) password stored in the database its self. Since you've lost/forgotten it you'll have to reset it:
-
Edit it to set the "host" line for user "postgres" on host "127.0.0.1/32" to "trust". You can add the line if it isn't there; just insert:
before any other lines. (You can ignore comments, lines beginning with
-
Restart the PostgreSQL service from the Services control panel (start->run->
See: How do I reset the postgres password for PostgreSQL on Windows?
NETWORK SERVICE, though you can still configure other accounts).I have used
net user postgres postgresto reset the password for my database but instead of a success message I am getting
"System error 5 has occurred. Access is denied."You've reset (or tried to reset) the service account password. PostgreSQL won't run as Administrator for security reasons and the installer generally sets it up with a "postgres" user account in PostgreSQL 9.1 and older1. On Windows you can't start a service as a user without saving the password of the user in the registry, so that's what the installer does.
If you change the password for the Windows user account
postgres, the PostgreSQL service can no longer start. So don't do that, you'll have to fix the service configuration to store the updated password.Thankfully I think another mistake prevented you from doing that. It looks like you're probably running your command prompt without using "Run as Administrator" on an unprivileged Windows user account or a machine with UAC, so it isn't running with the access permissions required to change the password for the
postgres user.Before you try to change that password, make sure it's really what you want to do. What's the problem you're trying to solve here? Are you attempting to install a database update or something else that's asking for the password for the
postgres Windows user? Most likely you're just trying to log in to the database. For that, you use the (unfortunately completely unrelated) password stored in the database its self. Since you've lost/forgotten it you'll have to reset it:
- Find your
pg_hba.conf, usually inC:\Program Files\PostgreSQL\9.1\data\pg_hba.conf
- If necessary, set the permissions on it so that you can modify it; your user account might not be able to do so until you use the security tab in the properties dialog to give yourself that right by using an admin override. Alternately, find notepad / notepad++ in your start menu, right click, choose "Run as administrator", then use File->Open to open
pg_hba.confthat way.
-
Edit it to set the "host" line for user "postgres" on host "127.0.0.1/32" to "trust". You can add the line if it isn't there; just insert:
host all postgres 127.0.0.1/32 trust
host all postgres ::1/128 trust # if IPv6 is in usebefore any other lines. (You can ignore comments, lines beginning with
#).-
Restart the PostgreSQL service from the Services control panel (start->run->
services.msc)- connect using psql or PgAdmin-III or whatever you prefer
ALTER USER postgres PASSWORD 'postgres'
- remove the line you added to
pg_hba.confor change it back
- restart PostgreSQL again.
See: How do I reset the postgres password for PostgreSQL on Windows?
- 9.2 now uses the
NETWORKSERVICEaccount, which doesn't require a password, so this problem goes away.
Code Snippets
host all postgres 127.0.0.1/32 trust
host all postgres ::1/128 trust # if IPv6 is in useContext
StackExchange Database Administrators Q#44586, answer score: 44
Revisions (0)
No revisions yet.