Basic Queries: practice questions
400 questions in four levels, all on RetailMart, the practice database of this course. Write every query yourself, get it wrong, read the error, fix it. That is how it sticks.
Answers are coming soon. Post your query in the WhatsApp Community or Discord and we will check it together.
Easy 100 questions Medium 100 questions Hard 100 questions Crazy 100 questions
Core syntax, applied directly
SETUP & POSTGRESQL ARCHITECTURE - CONCEPTUAL Q1 Your friend asks "is PostgreSQL the same as pgAdmin?" - explain the difference. Q2 Explain what psql is in one sentence. Q3 In the client-server model, what runs where: PostgreSQL, pgAdmin, your queries? Q4 What is the default port PostgreSQL listens on, and why does it matter? Q5 Why do you need both PostgreSQL AND pgAdmin? Can't you use just one? Q6 A teammate types psql in terminal and gets "command not found". Name 2 likely causes. Q7 Explain why a fresh PostgreSQL installation usually has a 'postgres' superuser. Q8 What is the 'public' schema in PostgreSQL - is it the same as RetailMart's schemas? Q9 Name 3 SQL clients besides pgAdmin you could use (any platform). Q10 Why do we use VS Code AND pgAdmin in this course - what does each do better? Q11 Your study buddy asks "what does \dt do in psql?" - answer. Q12 Explain what \l lists in psql. Q13 Explain what \dn lists in psql. Q14 What does \c some_db do in psql? Q15 Your friend says "Git is for code, not databases" - counter-argue why we use Git in this course. Q16 Explain what setup_retailmart.sql does in one sentence. Q17 Why does the setup script use \copy instead of COPY for loading CSVs? Q18 What command in psql exits the session cleanly? Q19 A junior asks "do I need to run psql with sudo?" - answer with the trade-off. Q20 Why is PostgreSQL preferred over MySQL for this analytics course? Name two reasons. Q21 In an interview, you're asked "what's the difference between TCP and Unix-socket connections in PostgreSQL?" - short answer. Q22 What is a "connection string" - give the typical Postgres format. Q23 Your teammate forgot the postgres password. Name one safe way to reset it on macOS. Q24 Why does this course use a SEPARATE practice DB (practice) AND the RetailMart V3 DB? Q25 After installation, what THREE smoke-test queries should you always run to verify everything works? SETUP VERIFICATION QUERIES (25) Topics: version, identity, basic system info Q26 Return the PostgreSQL server version (single column). Q27 Return the name of the database you're currently connected to. Q28 Return your current login user. Q29 Return the current date (server-side). Q30 Return the current timestamp (server-side, with timezone). Q31 Return the IP address of the server you're connected to (use inet_server_addr()). Q32 Return the current schema (search_path top entry). Q33 Return all schemas the user has access to from information_schema.schemata. Q34 Count how many schemas exist in the database. Q35 List all table names in the 'sales' schema using information_schema.tables. Q36 List all table names in the 'customers' schema. Q37 List all table names in the 'core' schema. Q38 Count how many tables exist in the 'sales' schema. Q39 Count how many tables exist across all schemas in this database. Q40 Return the size of the database in human-readable form (use pg_size_pretty + pg_database_size). Q41 List columns of customers.customers (use information_schema.columns). Q42 List columns of sales.orders. Q43 List columns of products.products. Q44 Return the data type of every column in stores.employees from information_schema. Q45 Return the count of distinct schemas owned by the postgres user. Q46 Return a list of all table names that start with 'order' across any schema. Q47 Return a list of all table names that contain 'employee' across any schema. Q48 Return all schema names alphabetically sorted. Q49 Show the search_path setting for the current session. Q50 Return the server's timezone setting. SCHEMA TOUR - ROW COUNTS & PEEKS (25) Topics: SELECT count(*), SELECT * LIMIT N for every major table Q51 Count rows in customers.customers - how many customers does RetailMart have? Q52 Count rows in sales.orders - total order volume. Q53 Count rows in sales.order_items - line items across all orders. Q54 Count rows in products.products - product catalog size. Q55 Count rows in stores.stores - number of retail outlets. Q56 Count rows in stores.employees - total headcount. Q57 Count rows in core.dim_brand - number of brands. Q58 Count rows in core.dim_category - number of categories. Q59 Count rows in core.dim_region - number of regions. Q60 Count rows in core.dim_department - number of departments. Q61 Count rows in support.tickets - total support cases ever. Q62 Count rows in marketing.campaigns - campaigns run. Q63 Count rows in hr.attendance - attendance records. Q64 Count rows in finance.expenses - expense entries. Q65 Count rows in payroll.pay_slips - pay slips issued. Q66 Count rows in loyalty.members - loyalty program enrollment. Q67 Count rows in audit.application_logs - system logs captured. Q68 Count rows in audit.api_requests - API hits logged. Q69 Count rows in web_events.page_views - total page-view events. Q70 Count rows in call_center.calls - calls handled. Q71 Count rows in manufacture.work_orders - production work orders. Q72 Count rows in supply_chain.warehouses - number of warehouses. Q73 Count rows in sales.returns - return records. Q74 Count rows in sales.shipments - shipment records. Q75 Count rows in customers.reviews - product reviews submitted. FIRST PEEK AT THE DATA - SELECT * LIMIT (25) Topics: SELECT * LIMIT 5 to feel each table's shape Q76 The DBA wants you to "peek" at customers.customers - show the first 5 rows of every column. Q77 Peek at the first 5 rows of sales.orders. Q78 Peek at the first 5 rows of products.products. Q79 Peek at the first 5 rows of stores.employees. Q80 Peek at the first 5 rows of stores.stores. Q81 Peek at the first 5 rows of core.dim_brand. Q82 Peek at the first 5 rows of core.dim_category. Q83 Peek at the first 5 rows of core.dim_region. Q84 Peek at the first 5 rows of support.tickets. Q85 Peek at the first 5 rows of marketing.campaigns. Q86 Peek at the first 5 rows of hr.attendance. Q87 Peek at the first 5 rows of finance.expenses. Q88 Peek at the first 5 rows of payroll.pay_slips. Q89 Peek at the first 5 rows of loyalty.members. Q90 Peek at the first 5 rows of loyalty.tiers. Q91 Peek at the first 5 rows of audit.application_logs. Q92 Peek at the first 5 rows of audit.api_requests. Q93 Peek at the first 5 rows of web_events.page_views. Q94 Peek at the first 5 rows of call_center.calls. Q95 Peek at the first 5 rows of manufacture.work_orders. Q96 Peek at the first 5 rows of supply_chain.warehouses. Q97 Peek at the first 5 rows of supply_chain.shipments. Q98 Peek at the first 5 rows of customers.addresses. Q99 Peek at the first 5 rows of customers.reviews. Q100 Peek at the first 5 rows of customers.wallets. Combined ideas, multi-step thinking
SETUP & PSQL POWER-USE Q1 In psql, what does \dt+ show that \dt does not? Q2 How would you list ALL tables across ALL schemas in psql in one command? Q3 In psql, how do you set your output format to expanded (\x) - and when is it useful? Q4 How do you turn ON timing in psql to see query execution time? Q5 How do you redirect psql output to a file (one command)? Q6 Your pgAdmin server connection fails with "could not connect" - list 3 things you'd check. Q7 In psql, how do you load a SQL file from disk? Q8 What does \df show? Q9 How do you describe a specific table's columns in psql? Q10 How do you exit psql cleanly? Q11 In VS Code with SQLTools, you can't see RetailMart V3 schemas. List 3 likely causes. Q12 Your psql prompt shows 'practice=#' - what does the '#' mean? Q13 How do you change passwords for the postgres user via psql? Q14 What does the .psql_history file contain and where is it? Q15 How do you run a single SQL command from the shell WITHOUT entering an interactive psql session? Q16 Your study buddy has PostgreSQL but no psql command. What likely went wrong with install? Q17 How do you check the disk size of EACH database on the server? Q18 How do you find which user owns the customers.customers table? Q19 Inside psql, how would you view the actual DDL of the sales.orders table? Q20 How do you view PostgreSQL's configured shared_buffers value via psql? SCHEMA / CATALOG EXPLORATION Q21 Count how many tables exist per schema (top 10) using information_schema.tables. Q22 List all schemas WITH count of tables in each, sorted descending. Q23 List all columns of type 'numeric' across the entire database. Q24 List all columns of type 'date' across all schemas. Q25 List all columns of type 'jsonb' across all schemas. Q26 Find every table that has a column literally named 'cust_id'. Q27 Find every table that has a column literally named 'customer_id'. Q28 Find every table whose name contains 'log'. Q29 Find every table whose name contains 'order'. Q30 Show columns of customers.customers with their data type AND whether nullable. Q31 Show columns of sales.orders with their data type AND character_maximum_length where applicable. Q32 List all PRIMARY KEY constraints across the database from information_schema.table_constraints. Q33 List all FOREIGN KEY constraints. Q34 List all CHECK constraints. Q35 List all UNIQUE constraints. Q36 Show tables in 'sales' schema and the number of columns in each. Q37 Find every table that has a column named 'email'. Q38 Find every column whose name contains 'date' across all schemas. Q39 Find columns whose name contains 'amount'. Q40 Show all sequences in the database (information_schema.sequences). Q41 Show all VIEWS in the database. Q42 Show the data type of customers.customers.tier specifically. Q43 Show the longest VARCHAR column in the database (highest character_maximum_length). Q44 List tables in the 'core' schema sorted by table_name. Q45 List tables in the 'audit' schema. Q46 Show server version + database name + current user in one row. Q47 Show the database size for practice + retailmart_v3 (if both exist) in human-readable form. Q48 Show how many connections are currently open to this DB (pg_stat_activity). Q49 Show the OS user the database server is running as (use current_setting('cluster_name') or similar). Q50 List all installed extensions (pg_extension). FILTERED COUNTS / DISTINCT EXPLORATION Q51 How many customers are in tier 'Gold'? Q52 How many customers are in tier 'Platinum'? Q53 How many products have a price greater than 5000? Q54 How many orders are 'Cancelled'? Q55 How many tickets have priority 'Critical'? Q56 How many tickets are currently 'Open'? Q57 How many tickets are 'In Progress'? Q58 How many tickets have NEVER been resolved (resolved_date IS NULL)? Q59 How many sales.shipments are still in transit (delivered_date IS NULL)? Q60 How many web_events.page_views are from anonymous users (customer_id IS NULL)? Q61 How many orders did RetailMart place in calendar year 2025? Q62 How many orders happened in Q1 2025 (Jan-Mar)? Q63 How many customers registered in 2024? Q64 How many distinct cities are in customers.addresses? Q65 How many distinct store cities are there? Q66 How many distinct courier_name values in sales.shipments? Q67 How many distinct call_reason values in call_center.calls? Q68 How many distinct categories in support.tickets? Q69 How many distinct brands have at least one product? Q70 How many distinct payment_mode values are in sales.payments? Q71 How many ads_spend rows are for platform = 'Google'? Q72 How many ads_spend rows are for platform = 'Meta' (returns 0 - value isn't in V3 data; verify by checking distinct values). Q73 How many employees work as 'Store Manager'? Q74 How many employees work as 'Cashier'? Q75 How many api_requests had status_code = 500? Q76 How many api_requests had status_code = 200? Q77 How many application_logs are at level 'ERROR'? Q78 How many application_logs are at level 'FATAL'? Q79 How many page_views are from 'Mobile' devices? Q80 How many calls have call_duration_seconds = exactly 60 (probable timeout)? DIAGNOSTIC / MULTI-STEP QUERIES Q81 Are there any orders with NULL net_total? Find them. Q82 Are there any customers with NULL first_name? Q83 Are there any products with NULL brand_id? Q84 Are there any employees with NULL dept_id? Q85 Are there any reviews with NULL rating? Q86 Are there orders with order_date in the FUTURE (after CURRENT_DATE)? Q87 Are there shipments with delivered_date EARLIER than shipped_date (data quality bug)? Q88 Are there tickets with resolved_date EARLIER than created_date? Q89 Are there products with price = 0 or negative? Q90 Are there employees with salary = 0 or negative? Q91 Show the date range of sales.orders (MIN and MAX order_date). Q92 Show the date range of hr.attendance. Q93 Show the date range of web_events.page_views (view_timestamp). Q94 Show the date range of marketing.campaigns (start_date min/max). Q95 Show how many DISTINCT customer_ids appear in sales.orders. Q96 Show how many DISTINCT product_ids appear in sales.order_items. Q97 Show how many DISTINCT employee_ids appear in hr.attendance. Q98 Show how many DISTINCT brand_ids appear in products.products. Q99 Show how many DISTINCT cust_ids appear in support.tickets. Q100 Show how many DISTINCT campaign_ids appear in marketing.ads_spend. Interview grade, edge cases
CATALOG INTROSPECTION DEEP-DIVE Q1 What's the difference between pg_class.relkind values 'r', 'i', 'S', 'v', 'm', 'p', 't', 'f'? Q2 Explain why pg_class.relnamespace is an OID - and how to resolve it to a schema name. Q3 How would you list every table in RetailMart V3 with its schema name (skip system schemas)? Q4 Why does pg_attribute.attnum < 0 for system columns? Q5 What is pg_index.indkey - and how do you decode a "1 3 2" key list? Q6 How do you tell from pg_constraint whether a constraint is PK, FK, UNIQUE, CHECK, or EXCLUSION? Q7 Explain pg_depend - what is it used for during DROP CASCADE? Q8 Why is pg_proc joined to pg_namespace to find functions in a specific schema? Q9 What's stored in pg_type - and how does it model composite/array/range/domain types? Q10 How would you find all extensions installed and their version (pg_extension)? Q11 Explain pg_authid vs pg_roles - why are they different views? Q12 How do you list every sequence in RetailMart V3 with its last_value? Q13 Walk through how an IDENTITY column appears in pg_attribute (attidentity column). Q14 Compare information_schema.tables vs pg_class for portability. Q15 What's in pg_stat_user_tables that pg_stat_all_tables hides? Q16 How would you find all foreign-key relationships across all RetailMart schemas? Q17 What does pg_stat_user_indexes.idx_scan = 0 indicate - and how do you act on it? Q18 Explain pg_locks columns: locktype, mode, granted - what does waiting look like? Q19 How would you find the longest-running transaction right now (pg_stat_activity)? Q20 Explain pg_stat_database - what's the cache hit ratio formula? Q21 What does pg_stat_bgwriter tell you about checkpoint pressure? Q22 Walk through pg_settings - how do you find which GUC values were set by the user vs default? Q23 What does pg_tablespace store - and what's the default tablespace OID? Q24 How would you list all roles and their attributes (CREATEDB, SUPERUSER, etc.)? Q25 What is pg_publication / pg_subscription - when do you query them? SCHEMA AUDIT QUERIES Q26 List every table in RetailMart V3 with row count estimate (pg_class.reltuples). Q27 List every table with PK column name(s) (join pg_constraint + pg_attribute). Q28 List every foreign key with source/target tables and columns. Q29 Find tables WITHOUT a primary key. Q30 Find every column with a NOT NULL constraint in customers schema. Q31 List every CHECK constraint in sales schema and its expression text. Q32 List every UNIQUE constraint (not PK) across all schemas. Q33 Find tables with > 5 indexes (potential over-indexing). Q34 List every index along with the columns indexed (use pg_get_indexdef). Q35 Find duplicate indexes (same columns, same order, on the same table). Q36 List columns whose data type is TEXT but could be CHAR/VARCHAR with a length limit. Q37 Find every table with a column named 'id' that is NOT a primary key. Q38 Find every table that has both 'created_at' and 'updated_at' timestamp columns. Q39 List every NUMERIC/DECIMAL column with its precision and scale. Q40 Find columns of type JSON (legacy) vs JSONB - should any be migrated? Q41 List every column with a DEFAULT value across the products schema. Q42 List every generated column (GENERATED ALWAYS AS ...) in V3. Q43 Find tables that have no foreign key references pointing INTO them (isolated tables). Q44 Find tables referenced by 5+ other tables (highly central tables). Q45 List every view across V3 with its underlying SELECT (pg_views). Q46 List every materialized view with its definition + ispopulated flag. Q47 Find every column in V3 named like '%email%' across all schemas. Q48 List every trigger across V3 with target table and trigger function. Q49 List every function in RetailMart V3 with its return type and argument types. Q50 List every schema in V3 with the count of tables, views, and functions. STORAGE, SIZE & PARTITION AUDIT Q51 List every table with its total size (heap + indexes + TOAST) using pg_total_relation_size. Q52 List every table with heap size, index size, TOAST size separately. Q53 List the top 10 largest tables in RetailMart V3 by total size. Q54 List the top 10 largest indexes in RetailMart V3. Q55 Compute the index-to-heap ratio per table and flag ratios > 1.0. Q56 Find tables with significant n_dead_tup (potential bloat). Q57 Compare reltuples (catalog estimate) vs actual COUNT(*) for sales.orders - how big is the drift? Q58 List every table with its last_vacuum, last_autovacuum, last_analyze timestamp. Q59 Find tables that have NEVER been analyzed (last_analyze IS NULL). Q60 List every partitioned table in V3 with its partition strategy (LIST/RANGE/HASH). Q61 List the child partitions of any partitioned table in V3 (pg_inherits + pg_class). Q62 For each partition, show its partition bound expression (pg_get_expr). Q63 Compute total size of each partition group (parent + children sum). Q64 Find every table with a TOAST table (pg_class.reltoastrelid <> 0) and its TOAST size. Q65 Find columns with EXTENDED storage that might benefit from EXTERNAL (already-compressed content). Q66 List every tablespace with the count of objects stored in it. Q67 Find the relation with the highest pg_relation_filenode churn (proxy: many VACUUM FULL runs). Q68 Compute total V3 database size - sum of all schemas + per-schema breakdown. Q69 Find every table with FILLFACTOR != 100 (custom storage parameter). Q70 List every index that is invalid (pg_index.indisvalid = false). Q71 List every index that is unique (pg_index.indisunique = true) - and confirm count matches PK + UNIQUE constraints. Q72 Find every duplicate row-count estimate (reltuples) > 1M across V3 - production-scale tables. Q73 List every sequence in V3 with its last_value and is_cycled. Q74 Find tables where reltuples is more than 20% off from actual count(*) - stats stale. Q75 List every relation with an unusual relpersistence (TEMP or UNLOGGED). DIAGNOSTIC & HEALTH-CHECK QUERIES Q76 Show cache hit ratio for the entire database (heap_blks_hit / heap_blks_hit + heap_blks_read). Q77 Show per-table cache hit ratio - rank worst 10 tables. Q78 Show per-index cache hit ratio - find indexes living entirely on disk. Q79 List unused indexes (idx_scan = 0 AND not part of unique constraint) - candidates to drop. Q80 List most-scanned indexes (top 10 by idx_scan). Q81 List most-accessed tables (top 10 by seq_scan + idx_scan combined). Q82 List tables with high seq_scan + large size (missing index suspects). Q83 Show current activity: pid, user, state, query - sorted by query_start (oldest first). Q84 Show backends in 'idle in transaction' state - and how long they've been idle. Q85 Show current locks with blocking pid (use pg_blocking_pids). Q86 Compute index hit rate per index from pg_statio_user_indexes. Q87 Show TOP 10 queries by total_exec_time from pg_stat_statements. Q88 Show TOP 10 queries by mean_exec_time from pg_stat_statements. Q89 Show TOP 10 queries by calls (most frequently executed). Q90 Show queries that have spilled to disk (temp_blks_read > 0) - work_mem may be too low. Q91 List all replication slots and their lag (pg_replication_slots). Q92 Show pg_stat_replication - current state of all connected replicas. Q93 Compute checkpoint statistics: checkpoints_timed vs checkpoints_req from pg_stat_bgwriter. Q94 Find the most bloated index by approximate bloat ratio (pgstattuple if installed). Q95 List databases ranked by size (pg_database_size). Q96 Find the count of WAL files on disk (pg_ls_waldir if PG10+). Q97 Show user privileges on schemas (has_schema_privilege checks across roles). Q98 Find every role that has SUPERUSER and warn (security audit). Q99 List every table where REFERENCES grant has been issued - and to whom. Q100 Build a "health summary" single-row query: total tables, total indexes, DB size, cache hit ratio, longest active query duration. Production scenarios, optimisation
PG_STAT_STATEMENTS DEEP Q1 Top 10 by total_exec_time with normalized queries. Q2 Top 10 by mean_exec_time (with min calls threshold). Q3 Queries with the worst p95 latency. Q4 Queries with the largest temp file IO. Q5 Queries with the highest shared_blks_read (cache miss). Q6 Queries doing the most WAL bytes. Q7 Queries with the worst rows_per_call (overflow). Q8 Queries spawned by autovacuum (filter by userid). Q9 Compare current run vs last reset baseline. Q10 Build a "slow query bulletin": top 20 with summary per app. Q11 Find a query that suddenly slowed down (planid change). Q12 Track query frequency per hour via pg_stat_statements snapshots. Q13 Identify "N+1" patterns: query with calls > 1M and tiny rows. Q14 Identify "kitchen sink" patterns: query with rows_per_call > 1M. Q15 Find queries with high jit_functions but no benefit. Q16 Reset pg_stat_statements; rerun 24h later for a clean window. Q17 Compare CPU vs IO bound queries by ratio. Q18 Diagnose a "cliff" - sudden 10x slowdown. Q19 Walk through tracking "regression after deploy" via the stats. Q20 Find queries that always use temp files. Q21 Find queries with very different mean vs max (variance flag). Q22 Aggregate by application_name. Q23 Find connection-pool-killer queries. Q24 Find dead-code queries: in code but never called. Q25 Top 5 queries per role/user. LOCKING & CONTENTION Q26 List the longest-running transactions right now. Q27 List who holds AccessExclusiveLock. Q28 Build a blocking chain (root blocker -> cascade). Q29 Detect long-waiting backends (wait_event_type = 'Lock'). Q30 Detect 'idle in transaction' >5 min. Q31 Find tables most contended (lock waits). Q32 Find advisory locks held longer than 1 hour. Q33 Find autovacuum that's been running >10 min. Q34 Detect deadlocks since cluster start. Q35 Detect WAL writer falling behind. Q36 Find connections by application_name + idle duration. Q37 Track active SLA breaches (query >30s). Q38 pg_terminate_backend the offender - safer wrapper script. Q39 Use pg_signal_backend grants for safer terminate. Q40 Lock conflict matrix: which lock type blocks which. Q41 Find SubtransControlLock contention (subtransaction storm). Q42 Tune deadlock_timeout vs lock_timeout. Q43 Find row-level locks holding back vacuum. Q44 Detect xmin horizon stuck (long-running transaction). Q45 Calculate transaction age (txid_current - txid_started). Q46 Build a "stuck VACUUM" report. Q47 Detect SELECT FOR UPDATE traffic jams (queue table pattern). Q48 Show the longest backend by transaction_age. Q49 Find tables that frequently appear in pg_locks (hotspots). Q50 Show parallel worker count per active query. INDEX FORENSICS Q51 Index size per table - ratio to heap. Q52 Duplicate indexes - same columns on same table. Q53 Redundant indexes - covered by another. Q54 Unused indexes (no scans since reset). Q55 Rarely-used indexes (idx_scan / idx_tup_fetch low). Q56 Index bloat estimate (using pgstattuple or pgstattuple_approx). Q57 Find INVALID indexes (CONCURRENTLY failed). Q58 Find FOR-only indexes that should be partial (most rows match). Q59 Find BTREE indexes that should be GIST/GIN. Q60 Index columns with very low cardinality (Boolean index = waste). Q61 Find tables where every query does seq scan despite indexes. Q62 Reorder index columns for better hits (cardinality analysis). Q63 Build a "best index for this query" suggestion. Q64 List partition-local vs partition-global indexes. Q65 Schedule REINDEX CONCURRENTLY for top-10 bloated indexes. Q66 Find indexes never written to (unused). Q67 Find indexes on FK columns that are missing. Q68 Index health overall - average scan rate. Q69 Top-N indexes by total IO. Q70 Drift between pg_stat_user_indexes and pgstattuple_approx. Q71 Build a "candidate index" report from missed index opportunities. Q72 Find HASH indexes (legacy, often unused). Q73 Find BRIN indexes - confirm they're matched to time-correlated cols. Q74 Compare statistics target per indexed column. Q75 Build an "index lineage" report - when each was last rebuilt. AUTO-AUDIT SCRIPTS Q76 Auto-audit: tables without PK. Q77 Auto-audit: columns referenced by FK that lack an index. Q78 Auto-audit: tables not vacuumed in >30 days. Q79 Auto-audit: stats stale (last_analyze > 7 days). Q80 Auto-audit: top 20 largest tables. Q81 Auto-audit: tables with > 30% bloat (pgstattuple). Q82 Auto-audit: indexes > 1 GB never used. Q83 Auto-audit: tables with very high seq_scan ratio. Q84 Auto-audit: tables with autovacuum frequently triggered. Q85 Auto-audit: tables with high churn (n_tup_upd + n_tup_del). Q86 Auto-audit: connections per application_name. Q87 Auto-audit: slow queries (mean_exec_time > 1s). Q88 Auto-audit: queries spilling to disk. Q89 Auto-audit: replication slot lag. Q90 Auto-audit: cache hit ratio per table - flag <0.95. Q91 Auto-audit: xid age per table. Q92 Auto-audit: wraparound risk (txid_age > 1B). Q93 Auto-audit: WAL volume per hour. Q94 Auto-audit: checkpoint pressure (forced vs timed ratio). Q95 Auto-audit: SUPERUSER count + warning. Q96 Auto-audit: tables granted to PUBLIC (security flag). Q97 Auto-audit: NOT NULL violations in audit views. Q98 Auto-audit: orphan FK rows (data integrity). Q99 Auto-audit: extensions installed + version mismatch. Q100 Build a single "DB health dashboard" query - 20 KPIs in one row.