Skip to content

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

Closed
Tracked by #10347
neverchanje opened this issue Jun 14, 2023 · 5 comments
Closed
Tracked by #10347

support setting application_name for each session #10339

neverchanje opened this issue Jun 14, 2023 · 5 comments
Assignees
Labels
type/feature Type: New feature.
Milestone

Comments

@neverchanje
Copy link
Contributor

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 is psql. 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

@TennyZhuang
Copy link
Contributor

Unfortunately, JDBC will not send application_name if the server version is <= 9.0, see the screenshot.

image

So the issue was likely blocked by #10099

@TennyZhuang
Copy link
Contributor

A workaround: use assumeMinServerVersion=9.0.0 in the connection string, and wait #10356 to be merged.

@TennyZhuang
Copy link
Contributor

TennyZhuang commented Jun 26, 2023

The JDBC behavior

The JDBC behavior

@TennyZhuang
Copy link
Contributor

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 assumeMinServerVersion=9.0.0 to the end of the connection string, then it can directly pass now.

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();
            }
        }
    }
}

@TennyZhuang TennyZhuang modified the milestones: release-1.0, release-1.1 Jul 14, 2023
@TennyZhuang
Copy link
Contributor

Fixed in latest main, tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Type: New feature.
Projects
None yet
Development

No branches or pull requests

2 participants