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

Auto-configure the Postgres application_name #40772

Open
sdavids opened this issue May 16, 2024 · 2 comments
Open

Auto-configure the Postgres application_name #40772

sdavids opened this issue May 16, 2024 · 2 comments
Labels
type: enhancement A general enhancement
Milestone

Comments

@sdavids
Copy link

sdavids commented May 16, 2024

Spring Boot 3.2.5

Logs

$ docker compose logs db -f
...
db-1  | 2024-05-16 10:18:14.746 UTC [37] LOG:  connection received: host=192.168.65.1 port=42395
db-1  | 2024-05-16 10:18:14.766 UTC [37] LOG:  connection authenticated: identity="test" method=scram-sha-256 (/var/lib/postgresql/data/pg_hba.conf:128)
db-1  | 2024-05-16 10:18:14.766 UTC [37] LOG:  connection authorized: user=test database=test
db-1  | 2024-05-16 10:18:14.769 UTC [37] LOG:  execute <unnamed>: SET extra_float_digits = 3
db-1  | 2024-05-16 10:18:14.770 UTC [37] LOG:  execute <unnamed>: SET application_name = 'PostgreSQL JDBC Driver'

Setup

application.yaml

spring:
  application:
    name: application-name-test

compose.yaml

services:
  db:
    image: postgres
    restart: always
    ports:
      - '5432:5432'
    environment:
      POSTGRES_USER: test
      POSTGRES_PASSWORD: test
      POSTGRES_DB: test
    command: ["postgres", "-c", "log_statement=all", "-c", "log_connections=true"]

Currently one has to explicitly configure the application name via org.springframework.boot.jdbc.parameters:

services:
  db:
    image: postgres
...
    labels:
      org.springframework.boot.jdbc.parameters: 'ApplicationName=application-name-test'

db-1  | 2024-05-16 10:21:53.323 UTC [39] LOG:  execute <unnamed>: SET application_name = 'application-name-test'
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 16, 2024
@wilkinsona
Copy link
Member

wilkinsona commented May 16, 2024

Thanks for the suggestion. I can see how this is useful in production when, presumably, you're configuring the application name on the JDBC URL. What's the benefit at development time when using Docker Compose? Do you perhaps have multiple apps sharing a compose file and the name makes each app's queries easier to identify?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label May 16, 2024
@sdavids
Copy link
Author

sdavids commented May 16, 2024

It makes debugging easier if you have a setup with for example Keycloak, Spring Cloud Gateway, and Spring Cloud Vault all talking to the same Postgres instance provided by the compose file.

Or if you use Sharing services between multiple applications, for example two Spring Boot applications for two bounded contexts using the same Postgres instance but each with their own database.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 16, 2024
@wilkinsona wilkinsona added for: team-meeting An issue we'd like to discuss as a team to make progress and removed status: feedback-provided Feedback has been provided labels May 17, 2024
@philwebb philwebb added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels May 22, 2024
@philwebb philwebb added this to the 3.x milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants