-
Notifications
You must be signed in to change notification settings - Fork 637
support setting application_name for each session #10339
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
Comments
Unfortunately, JDBC will not send application_name if the server version is <= 9.0, see the screenshot. ![]() So the issue was likely blocked by #10099 |
A workaround: use |
When #10600 get merged, the only blocker is the version number #10099. I can pass the test with the simple Java program if the version number returned by the server is "9.0.0": The workaround: add package com.example;
import java.sql.*;
import java.util.Properties;
public class App {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Load the PostgreSQL driver class
Class.forName("org.postgresql.Driver");
// Create a connection to the dev database on localhost:4566 with username 'root'
String url = "jdbc:postgresql://localhost:4566/dev?ApplicationName=test111";
String user = "root";
String password = "";
conn = DriverManager.getConnection(url, user, password);
{
Properties prop = conn.getClientInfo();
System.out.println(prop);
}
// Create a statement to execute SQL queries
stmt = conn.createStatement();
// Execute a SELECT 1 query
rs = stmt.executeQuery("SELECT 1");
// Process the results of the query
while (rs.next()) {
int result = rs.getInt(1);
System.out.printf("Result: %d\n", result);
}
{
Properties prop = conn.getClientInfo();
System.out.println(prop);
}
} catch (SQLException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} finally {
// Close the ResultSet, Statement, and Connection objects to free up resources
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
} |
Fixed in latest main, tested. |
Is your feature request related to a problem? Please describe.
Required by DataGrip.
Upon establishing a session, the client will set
application_name
in the FeStartupMessage. For psql, the application name ispsql
. For DataGrip, it is "DataGrip 2023.1.2".In addition, Postgres allows dynamically setting the variable via
set application_name to my_application;
. We may also support it in the future.Describe the solution you'd like
No response
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: