File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -161,11 +161,12 @@ impl Metrics {
161161 }
162162}
163163
164- pub fn run_database_metrics_work ( db : Postgres ) {
164+ pub fn run_database_metrics_work ( db : Postgres , run_analyze : bool ) {
165165 let span = tracing:: info_span!( "database_metrics" ) ;
166- // Spawn the task for updating large table statistics
167- tokio:: spawn ( update_large_tables_stats ( db. clone ( ) ) . instrument ( span. clone ( ) ) ) ;
168-
166+ if run_analyze {
167+ // Spawn the task for updating large table statistics
168+ tokio:: spawn ( update_large_tables_stats ( db. clone ( ) ) . instrument ( span. clone ( ) ) ) ;
169+ }
169170 // Spawn the task for database metrics
170171 tokio:: task:: spawn ( database_metrics ( db) . instrument ( span) ) ;
171172}
Original file line number Diff line number Diff line change @@ -173,17 +173,22 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
173173 . await
174174 . unwrap ( ) ;
175175
176- let db_read = if let Some ( db_read_url) = args. db_read_url
176+ let ( db_read, run_analyze ) = if let Some ( db_read_url) = args. db_read_url
177177 && args. db_write_url != db_read_url
178178 {
179- Postgres :: new ( db_read_url. as_str ( ) , args. insert_batch_size )
180- . await
181- . expect ( "failed to create read replica database" )
179+ (
180+ Postgres :: new ( db_read_url. as_str ( ) , args. insert_batch_size )
181+ . await
182+ . expect ( "failed to create read replica database" ) ,
183+ // If the DB is in read-only mode, running ANALYZE is not possible and will trigger and
184+ // error https://www.postgresql.org/docs/current/hot-standby.html
185+ false ,
186+ )
182187 } else {
183- db_write. clone ( )
188+ ( db_write. clone ( ) , true )
184189 } ;
185190
186- crate :: database:: run_database_metrics_work ( db_read. clone ( ) ) ;
191+ crate :: database:: run_database_metrics_work ( db_read. clone ( ) , run_analyze ) ;
187192
188193 let http_factory = HttpClientFactory :: new ( & args. http_client ) ;
189194 let web3 = shared:: ethrpc:: web3 (
You can’t perform that action at this time.
0 commit comments