|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | +#set -x |
| 5 | + |
| 6 | +PSQL="$PG_INSTALL_DIR/bin/psql -X -h $PG_DATA_DIR postgres" |
| 7 | +PGBENCH="$PG_INSTALL_DIR/bin/pgbench -h $PG_DATA_DIR" |
| 8 | + |
| 9 | +PGBENCH_SCALE=50 |
| 10 | +PGBENCH_CLIENTS=8 |
| 11 | +PGBENCH_JOBS=4 |
| 12 | +PGBENCH_TIME=120 |
| 13 | + |
| 14 | +echo "=== Setting up test environment ===" |
| 15 | +$PSQL -f setup.sql |
| 16 | + |
| 17 | +echo "=== Setup the benchmark ===" |
| 18 | +$PGBENCH -i -s $PGBENCH_SCALE postgres |
| 19 | + |
| 20 | +echo "=== Post-setup configuration ===" |
| 21 | +$PSQL -f post_setup.sql |
| 22 | + |
| 23 | +echo "=== Pre-loading data to create page pressure ===" |
| 24 | +$PSQL -c " |
| 25 | +-- Create more update activity to fill pages with large tuples |
| 26 | +UPDATE pgbench_accounts |
| 27 | +SET notes = 'preload_' || (random() * 10000)::int || '_' || repeat('large_data_chunk', 50), |
| 28 | + update_count = update_count + 1, |
| 29 | + last_updated = now() |
| 30 | +WHERE aid IN ( |
| 31 | + SELECT (random() * (100000 * $PGBENCH_SCALE))::int + 1 |
| 32 | + FROM generate_series(1, 20000) |
| 33 | +); |
| 34 | +
|
| 35 | +-- Create some dead tuples by updating again |
| 36 | +UPDATE pgbench_accounts |
| 37 | +SET notes = 'dead_preload_' || (random() * 10000)::int || '_' || repeat('dead_data_chunk', 60), |
| 38 | + update_count = update_count + 2 |
| 39 | +WHERE aid IN ( |
| 40 | + SELECT (random() * (100000 * $PGBENCH_SCALE))::int + 1 |
| 41 | + FROM generate_series(1, 10000) |
| 42 | +); |
| 43 | +" |
| 44 | + |
| 45 | +echo "=== Capturing baseline statistics ===" |
| 46 | +$PSQL -c "SELECT 'BASELINE' as phase, * FROM capture_prune_stats();" >results.log |
| 47 | +$PSQL -c "SELECT 'BASELINE_EXIT_ANALYSIS' as phase, * FROM analyze_exit_reasons();" >>results.log |
| 48 | + |
| 49 | +echo "=== Running pgbench HOT update workload ===" |
| 50 | +$PGBENCH -c $PGBENCH_CLIENTS -j $PGBENCH_JOBS -T $PGBENCH_TIME -f prune_test.sql -P 10 postgres |
| 51 | + |
| 52 | +echo "=== Capturing mid-test statistics ===" |
| 53 | +$PSQL -c "SELECT 'MID_TEST' as phase, * FROM capture_prune_stats();" >>results.log |
| 54 | +$PSQL -c "SELECT 'MID_TEST_EXIT_ANALYSIS' as phase, * FROM analyze_exit_reasons();" >>results.log |
| 55 | + |
| 56 | +echo "=== Running standard TPC-B workload for comparison ===" |
| 57 | +$PGBENCH -c $PGBENCH_CLIENTS -j $PGBENCH_JOBS -T 30 -P 10 postgres |
| 58 | + |
| 59 | +echo "=== Capturing post-test statistics ===" |
| 60 | +$PSQL -c "SELECT 'POST_TEST' as phase, * FROM capture_prune_stats();" >>results.log |
| 61 | +$PSQL -c "SELECT 'POST_TEST_EXIT_ANALYSIS' as phase, * FROM analyze_exit_reasons();" >>results.log |
| 62 | + |
| 63 | +echo "=== Exit Reason Analysis and Recommendations ===" |
| 64 | +$PSQL -c " |
| 65 | +SELECT |
| 66 | + 'EXIT_REASON_SUMMARY' as report_type, |
| 67 | + context, |
| 68 | + calls_total, |
| 69 | + success_rate_pct, |
| 70 | + main_failure_reason, |
| 71 | + failure_count, |
| 72 | + failure_pct |
| 73 | +FROM analyze_exit_reasons() |
| 74 | +ORDER BY calls_total DESC; |
| 75 | +" >>results.log |
| 76 | + |
| 77 | +$PSQL -c " |
| 78 | +SELECT |
| 79 | + 'RECOMMENDATIONS' as report_type, |
| 80 | + context, |
| 81 | + main_failure_reason, |
| 82 | + recommendation, |
| 83 | + failure_pct |
| 84 | +FROM get_pruning_recommendations() |
| 85 | +ORDER BY failure_pct DESC; |
| 86 | +" >>results.log |
| 87 | + |
| 88 | +echo "=== HOT Update Effectiveness ===" |
| 89 | +$PSQL -c " |
| 90 | +SELECT |
| 91 | + schemaname, relname, |
| 92 | + n_tup_ins, n_tup_upd, n_tup_hot_upd, |
| 93 | + CASE WHEN n_tup_upd > 0 |
| 94 | + THEN round(100.0 * n_tup_hot_upd / n_tup_upd, 2) |
| 95 | + ELSE 0 |
| 96 | + END as hot_update_pct, |
| 97 | + pg_size_pretty(pg_total_relation_size(schemaname||'.'||relname)) as table_size |
| 98 | +FROM pg_stat_user_tables |
| 99 | +WHERE relname = 'pgbench_accounts'; |
| 100 | +" >>results.log |
| 101 | + |
| 102 | +echo "=== Page-level analysis ===" |
| 103 | +$PSQL -c " |
| 104 | +SELECT |
| 105 | + relpages, |
| 106 | + reltuples, |
| 107 | + n_dead_tup, |
| 108 | + last_vacuum, |
| 109 | + last_autovacuum, |
| 110 | + pg_size_pretty(pg_relation_size('pgbench_accounts')) as heap_size |
| 111 | +FROM pg_stat_user_tables |
| 112 | +JOIN pg_class ON pg_class.relname = pg_stat_user_tables.relname |
| 113 | +WHERE pg_stat_user_tables.relname = 'pgbench_accounts'; |
| 114 | +" >>results.log |
| 115 | + |
| 116 | +echo "=== Detailed Statistics Breakdown ===" |
| 117 | +$PSQL -c " |
| 118 | +SELECT |
| 119 | + context, |
| 120 | + calls_total, |
| 121 | + pages_pruned, |
| 122 | + tuples_pruned, |
| 123 | + space_freed, |
| 124 | + exit_success, |
| 125 | + exit_invalid_xact_xid, |
| 126 | + exit_no_removable_xids, |
| 127 | + exit_page_not_prunable, |
| 128 | + exit_lock_failed, |
| 129 | + exit_other, |
| 130 | + prune_success_rate_pct, |
| 131 | + avg_time_per_call_us |
| 132 | +FROM capture_prune_stats() |
| 133 | +WHERE calls_total > 0 |
| 134 | +ORDER BY calls_total DESC; |
| 135 | +" >>results.log |
| 136 | + |
| 137 | +echo "=== Test complete. Results in results.log ===" |
| 138 | +cat results.log |
0 commit comments