vert-x3 / vertx-mysql-postgresql-client

This client is deprecated - use instead
https://github.com/eclipse-vertx/vertx-sql-client
Apache License 2.0
117 stars 59 forks source link

Support to set Application name #121

Closed shaykh-salman closed 6 years ago

shaykh-salman commented 6 years ago

Do we have any option to set application name on postgres like passing applicationName through jdbc url?

codepitbull commented 6 years ago

That won't work. We rely on the postgresql-async driver and that one removed the option to set the application_name:

https://github.com/mauricio/postgresql-async/issues/70

kaja78 commented 1 month ago

Can be set using connectHandler. This works for me in Quarkus:

import io.quarkus.reactive.pg.client.PgPoolCreator;
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.pgclient.PgPool;
import io.vertx.sqlclient.PoolOptions;
import jakarta.inject.Singleton;

@Singleton
public class CustomPgPoolCreator implements PgPoolCreator {

    @Override
    public PgPool create(Input input) {
        PgConnectOptions connectOptions = input.pgConnectOptionsList().get(0);
        PoolOptions poolOptions = input.poolOptions();
        return PgPool.pool(input.vertx(), connectOptions, poolOptions)
                .connectHandler(sqlConnection -> sqlConnection
                        .query("set application_name = 'my-app'")
                        .execute()
                        .onFailure(Throwable::printStackTrace)
                        .onComplete(rs -> sqlConnection.close()));
    }
}
codepitbull commented 1 month ago

Can be set using connectHandler. This works for me in Quarkus:

import io.quarkus.reactive.pg.client.PgPoolCreator;
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.pgclient.PgPool;
import io.vertx.sqlclient.PoolOptions;
import jakarta.inject.Singleton;

@Singleton
public class CustomPgPoolCreator implements PgPoolCreator {

    @Override
    public PgPool create(Input input) {
        PgConnectOptions connectOptions = input.pgConnectOptionsList().get(0);
        PoolOptions poolOptions = input.poolOptions();
        return PgPool.pool(input.vertx(), connectOptions, poolOptions)
                .connectHandler(sqlConnection -> sqlConnection
                        .query("set application_name = 'my-app'")
                        .execute()
                        .onFailure(Throwable::printStackTrace)
                        .onComplete(rs -> sqlConnection.close()));
    }
}

Wrong driver :)

You are using the new reactive driver which replaced the driver this repository was used for. The new driver supports the option, the old one doesn't.

If you check the current repository README you will se that the driver has been marked DEPRECATED several years ago.