-2

postgres user cannot connect to a database created by postgres user.

postgres=> CREATE DATABASE mydb  ENCODING 'UTF8' ;
CREATE DATABASE
postgres=> \connect "mydb";
FATAL:  Peer authentication failed for user "postgres"
Previous connection kept

Is this related to google cloud version of postgresql ?

terchris
  • 545
  • 6
  • 16
  • Have you tried searching for this error message? I found several results on various StackExchange sites regarding this error message. Have you tried any of the solutions there? In particular, have you looked here:[psql: FATAL: Ident authentication failed for user “postgres”](https://stackoverflow.com/questions/2942485/psql-fatal-ident-authentication-failed-for-user-postgres?noredirect=1&lq=1)? – J. Taylor Apr 14 '18 at 04:33
  • 1
    Possible duplicate of [psql: FATAL: Ident authentication failed for user "postgres"](https://stackoverflow.com/questions/2942485/psql-fatal-ident-authentication-failed-for-user-postgres) – J. Taylor Apr 14 '18 at 04:34
  • Try checking at the `pg_hba.conf` to get started – Jim Jones Apr 14 '18 at 12:12
  • Thanks to all of you that points out that I need to change the pg_hba.conf. The problem is that the google-cloud-sql postgres is hosted and I dont know how to find the file. – terchris Jun 20 '18 at 04:47

1 Answers1

0

When you create a new Cloud SQL for PostgreSQL instance, you must set a password for the default user account ‘postgres’ [1]. “Peer authentication is only available for local connections” [2]. The authentication method field ‘auth-method’ in pg_hba.conf file should be using ‘md5’ instead of ‘peer’ [2] as a password is set for the default user account. A similar error is answered here [3].

  1. https://cloud.google.com/sql/docs/postgres/create-manage-users#user-root
  2. https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
  3. Getting error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails
DaFois
  • 2,197
  • 8
  • 26
  • 43