From 37e3a868819a1b991cd61c5cdbeb30f30c27d6c9 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Fri, 3 Jun 2022 00:15:50 -0700 Subject: [PATCH] Pass application_name to server (#73) * Pass application_name to server * fmt --- src/client.rs | 8 ++++++++ tests/ruby/tests.rb | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 047a3ac..45934fd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -342,6 +342,14 @@ impl Client { server.address() ); + // Set application_name if any. + // TODO: investigate other parameters and set them too. + if self.parameters.contains_key("application_name") { + server + .set_name(&self.parameters["application_name"]) + .await?; + } + // Transaction loop. Multiple queries can be issued by the client here. // The connection belongs to the client until the transaction is over, // or until the client disconnects if we are in session mode. diff --git a/tests/ruby/tests.rb b/tests/ruby/tests.rb index 5b032a9..983619f 100644 --- a/tests/ruby/tests.rb +++ b/tests/ruby/tests.rb @@ -16,6 +16,7 @@ ActiveRecord::Base.establish_connection( username: 'sharding_user', password: 'sharding_user', database: 'rails_dev', + application_name: 'testing_pgcat', prepared_statements: false, # Transaction mode advisory_locks: false # Same ) @@ -116,7 +117,7 @@ end # Test evil clients def poorly_behaved_client - conn = PG::connect("postgres://sharding_user:sharding_user@127.0.0.1:6432/rails_dev") + conn = PG::connect("postgres://sharding_user:sharding_user@127.0.0.1:6432/rails_dev?application_name=testing_pgcat") conn.async_exec 'BEGIN' conn.async_exec 'SELECT 1'