Skip to content

Instantly share code, notes, and snippets.

@dvcolgan
dvcolgan / main.py
Last active March 2, 2023 15:17
For the Python Tenacity library, mock the retry decorator for faster tests that don't actually wait
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(reraise=True, stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=4, max=10))
def do_something_flaky(succeed):
print('Doing something flaky')
if not succeed:
print('Failed!')
raise Exception('Failed!')
with table_stats as (
select psut.relname,
psut.n_live_tup,
1.0 * psut.idx_scan / greatest(1, psut.seq_scan + psut.idx_scan) as index_use_ratio
from pg_stat_user_tables psut
order by psut.n_live_tup desc
),
table_io as (
select psiut.relname,
sum(psiut.heap_blks_read) as table_page_read,