|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use PostgresNode; |
| 5 | +use TestLib; |
| 6 | +use Test::More tests => 4; |
| 7 | + |
| 8 | +my $node = get_new_node('main'); |
| 9 | +$node->init; |
| 10 | +$node->append_conf('postgresql.conf', |
| 11 | + "shared_preload_libraries = 'auto_explain'"); |
| 12 | +$node->append_conf('postgresql.conf', "auto_explain.log_min_duration = 0"); |
| 13 | +$node->append_conf('postgresql.conf', "auto_explain.log_analyze = on"); |
| 14 | +$node->start; |
| 15 | + |
| 16 | +# run a couple of queries |
| 17 | +$node->safe_psql("postgres", "SELECT * FROM pg_class;"); |
| 18 | +$node->safe_psql("postgres", |
| 19 | + "SELECT * FROM pg_proc WHERE proname = 'int4pl';"); |
| 20 | + |
| 21 | +# emit some json too |
| 22 | +$node->append_conf('postgresql.conf', "auto_explain.log_format = json"); |
| 23 | +$node->reload; |
| 24 | +$node->safe_psql("postgres", "SELECT * FROM pg_proc;"); |
| 25 | +$node->safe_psql("postgres", |
| 26 | + "SELECT * FROM pg_class WHERE relname = 'pg_class';"); |
| 27 | + |
| 28 | +$node->stop('fast'); |
| 29 | + |
| 30 | +my $log = $node->logfile(); |
| 31 | + |
| 32 | +my $log_contents = slurp_file($log); |
| 33 | + |
| 34 | +like( |
| 35 | + $log_contents, |
| 36 | + qr/Seq Scan on pg_class/, |
| 37 | + "sequential scan logged, text mode"); |
| 38 | + |
| 39 | +like( |
| 40 | + $log_contents, |
| 41 | + qr/Index Scan using pg_proc_proname_args_nsp_index on pg_proc/, |
| 42 | + "index scan logged, text mode"); |
| 43 | + |
| 44 | +like( |
| 45 | + $log_contents, |
| 46 | + qr/"Node Type": "Seq Scan"[^}]*"Relation Name": "pg_proc"/s, |
| 47 | + "sequential scan logged, json mode"); |
| 48 | + |
| 49 | +like( |
| 50 | + $log_contents, |
| 51 | + qr/"Node Type": "Index Scan"[^}]*"Index Name": "pg_class_relname_nsp_index"/s, |
| 52 | + "index scan logged, json mode"); |
0 commit comments