Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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 reset your password-

http://www.postgresql.org/message-id/6BCB9D8A16AC4241919521715F4D8BCE476A42@algol.sollentuna.se

I followed the same. but the end result is a bit different then mentioned in the post.

I have used-

net user postgres postgres

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. Please guide me if I have missed or approaching wrong to get the end result. Any help will be really appreciated.

Thanks!

share|improve this question
    
You can try to visit recoverlostpassword.com to find out your answer, I think. –  Jason Whitle Jun 25 '13 at 4:15
add comment

migrated from stackoverflow.com Jun 15 '13 at 13:40

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 3 down vote accepted

(Note: Not much of this is relevant to readers using PostgreSQL 9.2 or above, which has a greatly simplified install).

I have used net user postgres postgres to 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 in C:\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.conf that 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
    

    before 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.conf or change it back
  • restart PostgreSQL again.

See: http://dba.stackexchange.com/q/19643/7788


1. 9.2 now uses the NETWORKSERVICE account, which doesn't require a password, so this problem goes away.

share|improve this answer
1  
You may also need an ip6 entry as well: "host all postgres ::1/128 trust" –  Ted Elliott Jan 3 at 17:46
add comment

You need to distinguish between your system (Windows) user called "postgres" and the database user with the same name.

Find your pg_hba.conf file - this controls access to the PostgreSQL server. You will need to edit it as a user with Administrator rights. Look for lines that mention user "postgres" and temporarily set the mode to "trust". Restart postgresql and then you should be able to connect without a password. Reset the password, then restore the file to its original settings and restart PostgreSQL.

The manual has details on authentication methods and the pg_hba.conf file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.