@@ -107,10 +107,10 @@ impl StreamInner {
107
107
108
108
#[ derive( Copy , Clone ) ]
109
109
struct CleanupState {
110
- /// If server connection requires DISCARD ALL before checkin because of set statement
110
+ /// If server connection requires RESET ALL before checkin because of set statement
111
111
needs_cleanup_set : bool ,
112
112
113
- /// If server connection requires DISCARD ALL before checkin because of prepare statement
113
+ /// If server connection requires DEALLOCATE ALL before checkin because of prepare statement
114
114
needs_cleanup_prepare : bool ,
115
115
}
116
116
@@ -296,7 +296,7 @@ pub struct Server {
296
296
/// Is the server broken? We'll remote it from the pool if so.
297
297
bad : bool ,
298
298
299
- /// If server connection requires DISCARD ALL before checkin
299
+ /// If server connection requires reset statements before checkin
300
300
cleanup_state : CleanupState ,
301
301
302
302
/// Mapping of clients and servers used for query cancellation.
@@ -982,7 +982,7 @@ impl Server {
982
982
// We don't detect set statements in transactions
983
983
// No great way to differentiate between set and set local
984
984
// As a result, we will miss cases when set statements are used in transactions
985
- // This will reduce amount of discard statements sent
985
+ // This will reduce amount of reset statements sent
986
986
if !self . in_transaction {
987
987
debug ! ( "Server connection marked for clean up" ) ;
988
988
self . cleanup_state . needs_cleanup_set = true ;
@@ -1304,12 +1304,21 @@ impl Server {
1304
1304
// Client disconnected but it performed session-altering operations such as
1305
1305
// SET statement_timeout to 1 or create a prepared statement. We clear that
1306
1306
// to avoid leaking state between clients. For performance reasons we only
1307
- // send `DISCARD ALL` if we think the session is altered instead of just sending
1307
+ // send `RESET ALL` if we think the session is altered instead of just sending
1308
1308
// it before each checkin.
1309
1309
if self . cleanup_state . needs_cleanup ( ) && self . cleanup_connections {
1310
1310
info ! ( target: "pgcat::server::cleanup" , "Server returned with session state altered, discarding state ({}) for application {}" , self . cleanup_state, self . application_name) ;
1311
- self . query ( "DISCARD ALL" ) . await ?;
1312
- self . query ( "RESET ROLE" ) . await ?;
1311
+ let mut reset_string = String :: from ( "RESET ROLE;" ) ;
1312
+
1313
+ if self . cleanup_state . needs_cleanup_set {
1314
+ reset_string. push_str ( "RESET ALL;" ) ;
1315
+ } ;
1316
+
1317
+ if self . cleanup_state . needs_cleanup_prepare {
1318
+ reset_string. push_str ( "DEALLOCATE ALL;" ) ;
1319
+ } ;
1320
+
1321
+ self . query ( & reset_string) . await ?;
1313
1322
self . cleanup_state . reset ( ) ;
1314
1323
}
1315
1324
@@ -1336,7 +1345,7 @@ impl Server {
1336
1345
self . last_activity
1337
1346
}
1338
1347
1339
- // Marks a connection as needing DISCARD ALL at checkin
1348
+ // Marks a connection as needing cleanup at checkin
1340
1349
pub fn mark_dirty ( & mut self ) {
1341
1350
self . cleanup_state . set_true ( ) ;
1342
1351
}
0 commit comments