Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] JDBC URL connection using db_username instead of db_name for accessing DB #8650

Open
gusthavosouza opened this issue Sep 17, 2023 · 1 comment
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. samples Issues that are directly related to samples. type: question Request for information or clarification. Not an issue.

Comments

@gusthavosouza
Copy link

gusthavosouza commented Sep 17, 2023

Hey, I am setting up an application on Google Cloud tech stack:

GCP SQL Postgress 15
Spring JPA 3.0.1
Google App Engine

followed the examples on: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java

My configs:

spring:
    cloud:
        appId: my-app-id
    datasource:
        hikari:
            data-source-properties:
                socketFactory: "com.google.cloud.sql.postgres.SocketFactory"
                cloudSqlInstance: ${INSTANCE_CONNECTION_NAME}
                sslmode: disable
        url: jdbc:postgresql://${DB_NAME}/
        password: ${DB_PASSWORD}
        username: ${DB_USERNAME}
    jpa:
        hibernate:
            ddl-auto: update
        properties:
            hibernate:
                dialect: org.hibernate.dialect.PostgreSQLDialect
    gcp:
        sql:
            database-name: ${DB_NAME}

My app.yaml


runtime: java17
instance_class: F1
env_variables:
  SPRING_PROFILES_ACTIVE: "prod"
  INSTANCE_CONNECTION_NAME: postgress_connection_name
  DB_NAME: db_name_anything
  DB_USERNAME: db_user_anything
  DB_PASSWORD: "_my_pass"
handlers:
  - url: /.*
    script: this field is required, but ignored
automatic_scaling:
  min_idle_instances: automatic
  max_idle_instances: 1
  min_pending_latency: automatic
  max_pending_latency: 0.030s
  max_instances: 1

Error:


o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 3D000
2023-09-17 12:43:26 default[v1]  2023-09-17T12:43:26.201Z ERROR 12 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : FATAL: database "db_name_anything" does not exist
2023-09-17 12:43:26 default[v1]  2023-09-17T12:43:26.208Z ERROR 12 --- [           main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution [FATAL: database "db_name_anything" does not exist] [n/a]

I have solved the problem with creating the user as the name of the db, however, this seems like a bug to me.

Thank you!

@gusthavosouza gusthavosouza added priority: p2 Moderately-important priority. Fix may not be included in next release. triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 17, 2023
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 17, 2023
@minherz minherz added type: question Request for information or clarification. Not an issue. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 17, 2024
@minherz minherz self-assigned this Jan 17, 2024
@minherz minherz removed the triage me I really want to be triaged. label Jan 17, 2024
@minherz
Copy link
Contributor

minherz commented Jan 17, 2024

The code sample in question is explained in the following documentation:

You can also look how to set up connection to Postgre.

Can you please follow the instructions and validate that if you cannot connect with a DB user that has a custom ID not matching the database name? If you follow these instructions and is able to reproduce the behavior, please share the detailed step-by-step reproduction scenario so we can troubleshoot the problem.

Thank you

@minherz minherz assigned gusthavosouza and unassigned minherz Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. samples Issues that are directly related to samples. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

6 participants
@gusthavosouza @minherz @kweinmeister @GabeWeiss and others