Skip to content

Instantly share code, notes, and snippets.

@0xNord
Last active March 7, 2021 12:01
Show Gist options
  • Save 0xNord/e504a50220c00e0402698f15ea2cbbdd to your computer and use it in GitHub Desktop.
Save 0xNord/e504a50220c00e0402698f15ea2cbbdd to your computer and use it in GitHub Desktop.
authFailedForUser(node_heroku_postgres_localhost)FIXED
  • heroku postgres db,
  • installed postgres on local,
  • nodejs

/db route -> Error error: password authentication failed for user "username"

HOW TO FIX:

###################################### 1) create db user ################################

  • sudo -u postgres psql
  • CREATE USER new_username;
  • ALTER USER new_username SUPERUSER CREATEDB;
  • check with \du

__________________________________________ links _____________________________________ https://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist/18708583#18708583 https://stackoverflow.com/questions/16973018/createuser-could-not-connect-to-database-postgres-fatal-role-tom-does-not-e/16974197#16974197

___________________________________ fix for peer problem if needed!!! ________________________

https://stackoverflow.com/questions/12720967/postgresql-how-to-change-postgresql-user-password https://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge https://askubuntu.com/questions/725985/postgres-pg-hba-conf-configuration https://gist.github.com/AtulKsol/4470d377b448e56468baef85af7fd614 peer auth fix

################################## 2) dump db from heroku ####################################

https://devcenter.heroku.com/articles/heroku-postgres-import-export

################################### 3) connect to your db for test ###############################

  • psql -h localhost -d your_db -U username
  • check with \d

https://stackoverflow.com/questions/12720967/postgresql-how-to-change-postgresql-user-password

############################### 4) change node.js server code ##########################

to fix the problem just replace "connectionString" with:

  • postgres://user:password@localhost:5432/yourlocaldb_name" (ONLY FOR DEV)

"connectionString" SHOULD BE process.env.DATABASE_URL (FOR HEROKU ON PROD)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment