@@ -54,6 +54,9 @@ pub struct Server {
5454
5555 /// Reports various metrics, e.g. data sent & received.
5656 stats : Reporter ,
57+
58+ /// Application name using the server at the moment.
59+ application_name : String ,
5760}
5861
5962impl Server {
@@ -210,7 +213,7 @@ impl Server {
210213
211214 let ( read, write) = stream. into_split ( ) ;
212215
213- return Ok ( Server {
216+ let mut server = Server {
214217 address : address. clone ( ) ,
215218 read : BufReader :: new ( read) ,
216219 write : write,
@@ -224,7 +227,12 @@ impl Server {
224227 client_server_map : client_server_map,
225228 connected_at : chrono:: offset:: Utc :: now ( ) . naive_utc ( ) ,
226229 stats : stats,
227- } ) ;
230+ application_name : String :: new ( ) ,
231+ } ;
232+
233+ server. set_name ( "pgcat" ) . await ?;
234+
235+ return Ok ( server) ;
228236 }
229237
230238 // We have an unexpected message from the server during this exchange.
@@ -448,9 +456,14 @@ impl Server {
448456 /// A shorthand for `SET application_name = $1`.
449457 #[ allow( dead_code) ]
450458 pub async fn set_name ( & mut self , name : & str ) -> Result < ( ) , Error > {
451- Ok ( self
452- . query ( & format ! ( "SET application_name = '{}'" , name) )
453- . await ?)
459+ if self . application_name != name {
460+ self . application_name = name. to_string ( ) ;
461+ Ok ( self
462+ . query ( & format ! ( "SET application_name = '{}'" , name) )
463+ . await ?)
464+ } else {
465+ Ok ( ( ) )
466+ }
454467 }
455468
456469 /// Get the servers address.
0 commit comments