@@ -54,6 +54,9 @@ pub struct Server {
54
54
55
55
/// Reports various metrics, e.g. data sent & received.
56
56
stats : Reporter ,
57
+
58
+ /// Application name using the server at the moment.
59
+ application_name : String ,
57
60
}
58
61
59
62
impl Server {
@@ -210,7 +213,7 @@ impl Server {
210
213
211
214
let ( read, write) = stream. into_split ( ) ;
212
215
213
- return Ok ( Server {
216
+ let mut server = Server {
214
217
address : address. clone ( ) ,
215
218
read : BufReader :: new ( read) ,
216
219
write : write,
@@ -224,7 +227,12 @@ impl Server {
224
227
client_server_map : client_server_map,
225
228
connected_at : chrono:: offset:: Utc :: now ( ) . naive_utc ( ) ,
226
229
stats : stats,
227
- } ) ;
230
+ application_name : String :: new ( ) ,
231
+ } ;
232
+
233
+ server. set_name ( "pgcat" ) . await ?;
234
+
235
+ return Ok ( server) ;
228
236
}
229
237
230
238
// We have an unexpected message from the server during this exchange.
@@ -448,9 +456,14 @@ impl Server {
448
456
/// A shorthand for `SET application_name = $1`.
449
457
#[ allow( dead_code) ]
450
458
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
+ }
454
467
}
455
468
456
469
/// Get the servers address.
0 commit comments