@@ -184,7 +184,7 @@ fn run<'a>(args: &'a cli::Args, muxer: &'a mut PgMuxer) -> Result<(), Error<'a>>
184184 . map_err ( |e| ( & args. directory as & ' a Path , e) ) ?;
185185 if !args. use_existing_dir {
186186 muxer. init_db ( & args. directory ) ?;
187- tweak_postgresql_conf ( & args. directory , args. port ) . unwrap ( ) ;
187+ tweak_postgresql_conf ( & args. directory , args. auto_explain , args . port ) . unwrap ( ) ;
188188 }
189189 muxer. run_postgres ( & args. directory , args. port ) ?;
190190 if !args. use_existing_dir {
@@ -227,7 +227,7 @@ fn run<'a>(args: &'a cli::Args, muxer: &'a mut PgMuxer) -> Result<(), Error<'a>>
227227 Ok ( ( ) )
228228}
229229
230- fn tweak_postgresql_conf ( db_path : & Path , port : Option < u16 > ) -> io:: Result < ( ) > {
230+ fn tweak_postgresql_conf ( db_path : & Path , auto_explain : bool , port : Option < u16 > ) -> io:: Result < ( ) > {
231231 let mut conf_path = PathBuf :: from ( db_path) ;
232232 conf_path. push ( "postgresql.conf" ) ;
233233 let file = OpenOptions :: new ( ) . append ( true ) . open ( conf_path) ?;
@@ -236,14 +236,28 @@ fn tweak_postgresql_conf(db_path: &Path, port: Option<u16>) -> io::Result<()> {
236236 None => & [ ( "listen_addresses" , "" ) ] ,
237237 Some ( _) => & [ ] ,
238238 } ;
239+ for ( k, v) in port_options {
240+ writeln ! ( file, "{k} = '{v}'" ) ?;
241+ }
239242 let options: & [ ( & str , & str ) ] = & [
240243 ( "unix_socket_directories" , db_path. to_str ( ) . unwrap ( ) ) ,
241244 ( "log_connections" , "on" ) ,
242245 ( "log_disconnections" , "on" ) ,
243246 ] ;
244- for options in [ port_options, options] {
245- for ( k, v) in options {
246- writeln ! ( file, "{k} = '{v}'" ) ?;
247+ for ( k, v) in options {
248+ writeln ! ( file, "{k} = '{v}'" ) ?;
249+ }
250+ if auto_explain {
251+ let auto_explain_options: & [ ( & str , & str ) ] = & [
252+ ( "session_preload_libraries" , "'auto_explain'" ) ,
253+ ( "auto_explain.log_min_duration" , "0" ) ,
254+ ( "auto_explain.log_analyze" , "true" ) ,
255+ ( "auto_explain.log_buffers" , "true" ) ,
256+ ( "auto_explain.log_triggers" , "true" ) ,
257+ ( "auto_explain.log_nested_statements" , "true" ) ,
258+ ] ;
259+ for ( k, v) in auto_explain_options {
260+ writeln ! ( file, "{k} = {v}" ) ?;
247261 }
248262 }
249263 file. flush ( ) ?;
0 commit comments