Search code examples
node.jspostgresqlpasswords

PostgresQL password being asked for and not working, despite re-installation


NOTE I'm running Windows 7 and postgres version 9.3.

I'm having the frustrating problem that I misplaced my password for postgresQL. After trying to discover how to recover the password, to no avail, I decided that I should uninstall and then re-install postgres. The installation process went smoothly, and I was prompted for a password towards the end of the process.

However, after this re-installation and new password, I typed psql into the terminal and was prompted for password:, but the password that I enter, the new one that I just created, doesn't work. I'm not sure if perhaps the old password is stored somewhere? I've tried other things, like using su before typing in postgres or psql (which doesn't work on windows..."'su' is not recognized as an internal or external command").

The main issue is that I actually need the password, because I'm using node-postgres, and need to connect using var conString = "postgres://username:password@localhost/database";. I tried putting in my post-re-install username and password in there, but I get the error message error fetching client from pool { [error: password authentication failed for user "myUserName"]

Any ideas of why the new password isn't working or how to get the password and get postgres running?

Thanks!


Solution

  • GOT IT!

    What you have to do is

    1) type in psql -U postgres to the console. This will get you through to postgresQL (hopefully - if not, maybe your pg_hba.conf file, or something else, needs to be changed).

    2)Type CREATE USER whateverUsernameYouWant; (obviously setting your own username)

    3)Type ALTER USER whateverUsernameYouWant WITH PASSWORD 'thisIsMyNewPassword' (again, setting your password and using the username you entered earlier);

    4) In the node.js file that I'm working on, I set var conString = "postgres://whateverUsernameYouWant:thisIsMyNewPassword@localhost/database";

    5) After you create a database (using create DATABASE yourDatabaseName OWNER yourUsername;), to access the database AFTER EXITING postgres simply type in psql yourDatabaseName yourUsername and everything should be peachy :)