Pass application_name to server (#73)

* Pass application_name to server

* fmt
This commit is contained in:
Lev Kokotov
2022-06-03 00:15:50 -07:00
committed by GitHub
parent 61db13f614
commit 37e3a86881
2 changed files with 10 additions and 1 deletions

View File

@@ -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.

View File

@@ -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'