Intro to SQL: 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
DATA, SQL & ROLES Q1 Your friend asks "what's the difference between data and information?" - give a one-line answer with an example. Q2 A non-technical hiring manager asks "what is SQL?" - describe it in 30 seconds. Q3 Explain why Excel is not enough once a company crosses ~1 million rows. Q4 Why is SQL called a "declarative" language? Contrast with imperative code. Q5 A new joiner asks: "do data engineers and data analysts use the same SQL?" - answer. Q6 Name three job roles where SQL is a daily-use skill, and what each uses it for. Q7 In an interview, you're asked: "is SQL still relevant in the AI era?" - argue yes. Q8 Your manager says "we use NoSQL, why should I care about SQL?" - give one counter-argument. Q9 Explain in plain English what a "query" is. Q10 Why do almost all BI tools (Power BI, Tableau, Looker, Metabase) speak SQL under the hood? Q11 Your team lead asks why we structure data into ROWS and COLUMNS instead of free text. Explain. Q12 What does it mean when someone says "SQL is the lingua franca of data"? Q13 A friend is comparing Python pandas vs SQL - name one strength of each. Q14 In a hiring panel, you're asked: "rank these by importance for a data analyst - Excel, SQL, Python, BI tool." Defend your order. Q15 Why does the same SQL query usually run faster on a database than the equivalent loop in Python? Q16 Explain to a junior - what's the difference between "structured" and "unstructured" data, with one example of each? Q17 Your CTO says "every analyst should learn SQL." Give two reasons that justify this rule. Q18 A bootcamp peer says "I'll just use ChatGPT to write SQL" - push back with one strong argument. Q19 Name 4 industries where SQL is core to the daily workflow. Q20 Explain how SQL skills transfer across MySQL, PostgreSQL, BigQuery, Snowflake - what stays constant? Q21 A student asks: "is SQL hard?" - answer honestly, naming the easy and the hard parts. Q22 Why do data scientists who "only care about ML" still need to know SQL? Q23 Your friend wonders why companies don't just dump everything into one giant Excel file. List two real problems with that. Q24 Explain what "data engineering" is in one sentence - and where SQL fits in that role. Q25 Name 5 things that are EASY in SQL but PAINFUL in Excel. DBMS vs RDBMS & DATABASE TYPES Q26 Your interviewer asks: "what does DBMS stand for, and what does it actually DO?" Answer in 2 sentences. Q27 Explain the R in RDBMS - what does "relational" mean? Q28 Give 3 examples of well-known relational databases used by Indian companies. Q29 Give 3 examples of well-known NON-relational (NoSQL) databases. Q30 A teammate confuses "database" and "DBMS" - explain the difference. Q31 Why does an RDBMS enforce a schema before you can insert data? Q32 Name two scenarios where a NoSQL database is a BETTER choice than an RDBMS. Q33 What does "ACID" stand for, and why does it matter for banking systems? Q34 Your CTO asks "why are we paying for Oracle instead of using free PostgreSQL?" - give one valid reason a big company might choose Oracle. Q35 Explain "concurrency" - why an RDBMS must handle many users writing at once. Q36 What's the difference between a "primary database" (OLTP) and a "data warehouse" (OLAP)? Q37 A junior asks: "why don't we use MongoDB for accounting?" - give one solid reason. Q38 Name 3 cloud-managed RDBMS services (Indian / global). Q39 In an interview, you're asked: "what's the difference between SQL and MySQL?" Answer. Q40 Why is PostgreSQL favored for analytics + data science over MySQL? Name two reasons. Q41 Your team is choosing between SQLite and PostgreSQL for a new app. Pick one and justify in 2 sentences. Q42 Explain "client-server" architecture in databases. Q43 Why can multiple users connect to the same RDBMS at the same time without corrupting data? Q44 Your friend opens an Excel file and asks "is this a database?" - answer with the distinction. Q45 Name 3 ways an RDBMS protects against data loss. Q46 What is "replication" in databases and why do banks use it? Q47 Explain "horizontal scaling" vs "vertical scaling" in your own words. Q48 Why are columnar databases (Snowflake, BigQuery, Redshift) preferred for analytics? Q49 Explain in 1 sentence what a "key-value store" is. Q50 Why are graph databases (Neo4j) useful for social-network and fraud-detection problems? SQL COMPONENTS - DDL/DML/DCL/TCL Q51 Expand each acronym: DDL, DML, DCL, TCL - and one sentence on what each is FOR. Q52 Classify: CREATE TABLE - DDL, DML, DCL, or TCL? Q53 Classify: INSERT INTO - DDL, DML, DCL, or TCL? Q54 Classify: UPDATE - DDL, DML, DCL, or TCL? Q55 Classify: DELETE - DDL, DML, DCL, or TCL? Q56 Classify: ALTER TABLE - DDL, DML, DCL, or TCL? Q57 Classify: DROP TABLE - DDL, DML, DCL, or TCL? Q58 Classify: TRUNCATE TABLE - DDL, DML, DCL, or TCL? Q59 Classify: GRANT - DDL, DML, DCL, or TCL? Q60 Classify: REVOKE - DDL, DML, DCL, or TCL? Q61 Classify: COMMIT - DDL, DML, DCL, or TCL? Q62 Classify: ROLLBACK - DDL, DML, DCL, or TCL? Q63 Classify: SAVEPOINT - DDL, DML, DCL, or TCL? Q64 Classify: SELECT - DML, DCL, or something else? Q65 Your teammate runs DROP TABLE in production by mistake. Can it be rolled back? Why or why not? Q66 Why is TRUNCATE faster than DELETE on a huge table - but riskier? Q67 What's the difference between DROP TABLE and DELETE FROM TABLE? Q68 In a banking system, why does a money transfer use BEGIN, COMMIT, ROLLBACK? Q69 A junior asks: "do I need to commit after every SELECT?" - answer. Q70 Explain why GRANT and REVOKE exist - what real-world problem do they solve? Q71 Which SQL command would you use to give the analytics team read-only access to a table? Q72 Which SQL command would you use to add a new column to an existing table? Q73 Which SQL command would you use to permanently remove a customer record? Q74 Which SQL command would you use to permanently destroy a whole table including its structure? Q75 Explain the difference between DELETE and TRUNCATE in two sentences. DATABASE / SCHEMA / TABLE & RETAILMART Q76 Define a "database" in your own words. Q77 Define a "schema" in your own words - and how it differs from a database. Q78 Define a "table" - what is the smallest meaningful unit of data inside it? Q79 Define a "row" and a "column" with a one-line example each. Q80 Your manager says "RetailMart has 16 schemas." What does that mean in practical terms? Q81 Why does RetailMart split data into schemas like sales, customers, products, hr - instead of dumping everything into one schema? Q82 Give two reasons a company would put customer data and HR data in SEPARATE schemas. Q83 Name 5 RetailMart schemas you remember from class. Q84 Why are dimension tables (dim_brand, dim_region, dim_category) separated from fact tables (orders, order_items)? Q85 Explain the difference between a fact table and a dimension table in plain English. Q86 What is a "primary key" - explain by pointing at any RetailMart table. Q87 What is a "foreign key" - explain how sales.orders.cust_id is one. Q88 Explain what "schema-qualified name" means - and why we write customers.customers, not just customers. Q89 Your script breaks because you wrote SELECT * FROM orders. What's missing? Q90 A teammate says "PostgreSQL is case-sensitive". When does that matter for SQL queries? Q91 Why do databases use NULL instead of empty string for missing values? Q92 RetailMart has 55 tables. Name 5 things you can do with that many tables that you can't do in one Excel sheet. Q93 The CTO asks "how many distinct schemas does RetailMart V3 have?" - answer the number and name 5 of them. Q94 Explain in one sentence what an "index" is - pretend you're teaching a class 10 student. Q95 A junior asks "what's the difference between a database and a table?" - answer. Q96 Explain why a query like SELECT * FROM customers might be slow on a table with 50 million rows. Q97 Name 2 reasons to use PostgreSQL 18 over PostgreSQL 12 for this course. Q98 What does "RetailMart V3" mean - what's the difference from V1 or V2? Q99 Your teammate asks "is pgAdmin the database?" - explain what pgAdmin actually is. Q100 By end of class today, what THREE things must you be able to explain about RetailMart to pass a quick verbal check? Combined ideas, multi-step thinking
SQL'S PLACE IN THE STACK - DEEPER Q1 Compare SQL vs pandas for analyzing a 100 GB dataset - which wins and why? Give 2 reasons per side. Q2 Your manager wants real-time dashboards. Argue for SQL on a database vs Python loading CSVs. Q3 When would you choose a graph database OVER SQL - give a concrete RetailMart-flavoured example. Q4 Defend the statement: "SQL skills are MORE valuable in the LLM era." Three concrete arguments. Q5 A startup founder says "we don't need SQL; MongoDB + ChatGPT can handle everything." Push back with 3 specific gaps. Q6 Explain to a non-technical CEO why analysts shouldn't share Excel files via email. Use the lens of correctness, audit, scale. Q7 Compare a Data Analyst's SQL work to a Data Engineer's SQL work - where do they overlap, where do they diverge? Q8 In an interview you're asked: "tell me about a time SQL beat a Python solution at your job." Make up a plausible scenario. Q9 Walk through what happens when you click "Send" on an order at amazon.in - how many SQL queries (roughly) and why? Q10 Why do some teams prefer DBT over hand-written SQL pipelines - what specific problem does it solve? Q11 Why does the same SQL query give different EXECUTION PLANS on PostgreSQL vs MySQL vs SQL Server? Q12 Compare "Excel for analysis" vs "SQL for analysis" using the four lenses: scale, correctness, repeatability, audit. Q13 A junior asks: "why do interviewers care about SQL when AI can write it?" - three real reasons. Q14 Defend why a data scientist who "only does ML" still must know SQL - three concrete examples from a typical workflow. Q15 List five industries where SQL knowledge translates directly into salary uplift - with one role per industry. Q16 Explain the difference between "data" and "information" using a RetailMart example. Q17 A business stakeholder asks: "give me yesterday's revenue." Walk through what an analyst's SQL workflow looks like end-to-end. Q18 Why is it harder to scale a TEAM of analysts on Excel than on SQL? Q19 Compare SQL declarative style vs Python imperative style with a "find top 10 customers" example. Q20 A teammate proposes storing everything in TEXT columns because "we can parse later." Counter-argue with three problems. Q21 Trace the path of a customer's purchase from app click -> database -> analyst dashboard. Where does SQL appear? Q22 Explain what a "data swamp" is and how disciplined SQL design prevents it. Q23 Why do most SaaS startups eventually consolidate to PostgreSQL even if they started on MongoDB? Q24 Define "OLTP" and "OLAP" - and where in RetailMart V3 are queries of each type likely to run? Q25 The CTO asks: "if we hired ONE engineer who knows EITHER Python OR SQL deeply, which is more valuable for our analyst team?" Defend your answer. DBMS TRADEOFFS & DATABASE TYPES - DEEPER Q26 Compare PostgreSQL vs MySQL for a fintech startup with strict accounting needs. Pick one and defend it. Q27 When would you choose SQLite over PostgreSQL? Two concrete cases. Q28 Why is Snowflake (columnar warehouse) chosen for analytics even though PostgreSQL also works? Q29 Compare an OLTP DB (handles online orders) vs an OLAP warehouse (handles BI reports). Give two architectural differences. Q30 A startup uses BigQuery for analytics + PostgreSQL for production. Explain why both exist. Q31 Why do banks insist on ACID - what specifically goes wrong if even one of the 4 properties is violated? Q32 Compare "primary database with read replicas" vs "shared-nothing distributed DB" - when does each win? Q33 Argue why Redis is NOT a replacement for PostgreSQL even though Redis is faster. Q34 Explain "eventual consistency" and why most analyst tools can't tolerate it well. Q35 RetailMart V3 has 16 schemas. What if all 55 tables were dumped in one 'public' schema - list 4 things that would get worse. Q36 Why is PostgreSQL preferred over MS SQL Server for an open-source-friendly startup? Three reasons. Q37 Compare row-oriented vs columnar storage with a "monthly revenue per category" query example. Q38 Why does PostgreSQL allow MULTIPLE NULLs in a UNIQUE column but only ONE PRIMARY KEY? Q39 Why do some DBs (Oracle, SQL Server) cost millions while PostgreSQL is free - what do you actually pay for? Q40 Compare DBaaS (AWS RDS) vs self-hosted PostgreSQL on EC2 - three tradeoffs. Q41 Why is "horizontal scaling" hard for relational databases compared to NoSQL ones? Q42 Explain in plain English what a "database transaction" is using a Paytm UPI transfer as the example. Q43 Argue: "All NoSQL adopters end up needing SQL eventually." Defend with two concrete startup case-types. Q44 Why do most analytics SQL queries run on a REPLICA of the OLTP DB instead of the OLTP DB itself? Q45 What is a "database view" - and why is it a useful primitive even though you could just paste the SELECT? Q46 Explain what "MVCC" means in PostgreSQL - a one-paragraph plain-English answer. Q47 Compare "logical replication" vs "physical replication" - when would you pick each? Q48 Why does almost every modern web app use a connection POOL (pgbouncer, RDS Proxy) instead of opening direct DB connections? Q49 A startup chooses NoSQL because "schemas slow them down." Six months later they regret it - what's the typical pain point? Q50 Why do some teams adopt "schema migrations" as a discipline even on small DBs? SQL DIALECT & COMPONENT TRADEOFFS Q51 Classify and EXPLAIN: which is more dangerous in production - DROP TABLE or TRUNCATE TABLE - and why? Q52 A junior runs DELETE FROM orders without WHERE. Walk through what could/should have stopped them. Q53 Defend the design choice that ALTER TABLE locks the table in older PostgreSQL versions - what tradeoff was being made? Q54 Why is GRANT/REVOKE at the SCHEMA level often more useful than at the TABLE level? Q55 Compare COMMIT and ROLLBACK with an INSERT example - what does each do at the byte level? Q56 Why do some teams BAN truncate in production scripts entirely? Q57 Compare SQL standard ANSI types vs PostgreSQL extensions (TEXT, JSONB, UUID, ARRAY). Which is portable, which is power? Q58 Explain why TRUNCATE doesn't fire row-level triggers but DELETE does. Q59 A team's INSERT is suddenly slow. List 5 things that could be the cause. Q60 Compare auto-commit mode vs explicit BEGIN/COMMIT - when does each surprise junior developers? Q61 Why is INSERT ... ON CONFLICT (upsert) more useful than try-catch-update flow in app code? Q62 Walk through what happens if you forget the WHERE on an UPDATE in a 5-million-row table. Q63 Compare "INSERT INTO ... SELECT" vs "COPY FROM file" for loading 1 million rows - when does each win? Q64 Why is "GRANT ALL TO PUBLIC" considered a security anti-pattern? Q65 Explain what SAVEPOINT does inside a transaction. Give a use case. Q66 Compare implicit (auto-commit) vs explicit transactions. Which is safer for analysts running ad-hoc queries? Q67 Why do schema-prefixed names (sales.orders) become essential as a company's database grows? Q68 A teammate insists on storing dates as VARCHAR. Convince them to use DATE/TIMESTAMP with 3 arguments. Q69 Defend why PostgreSQL allows quoted identifiers like "Customer" - and why most teams ban them anyway. Q70 Explain in plain English why a query that worked yesterday "suddenly" fails today - list 5 plausible causes. Q71 Compare CREATE TABLE AS SELECT vs CREATE TABLE then INSERT - when does each shine? Q72 Why is using a NUMERIC type more "correct" than FLOAT for money, even though FLOAT is faster? Q73 Explain "column ordering" in CREATE TABLE - does the order matter? Defend your answer. Q74 Compare CHECK constraints vs application-side validation. Where should the rule live? Q75 Why do most production DBs add CREATED_AT / UPDATED_AT columns to almost every table? RETAILMART V3 LEVEL-2 Q76 Defend the choice to split sales.orders (fact) from sales.order_items (fact detail) into two tables. Q77 Why is products.products kept separate from core.dim_brand AND core.dim_category? Defend this 3-table model. Q78 The RetailMart designer says "stores.employees + payroll.pay_slips is a deliberate split." What real problem does the split solve? Q79 Why is web_events.page_views in its OWN schema (not customers or sales)? Defend the design. Q80 RetailMart has both sales.payments AND finance.payments - why two tables for "payments"? Q81 customers.customers has a 'tier' column AND there's also loyalty.tiers + loyalty.members. Why both? Q82 Why does customers.addresses have an is_default boolean - what design problem does it solve? Q83 The hr.attendance table has check_in AND check_out as separate columns (not duration). Defend why. Q84 Why is core.dim_date pre-populated as a calendar dimension instead of just using EXTRACT()? Q85 The audit.application_logs table has a 'level' column - argue why this is better than a separate 'severity_id' FK. Q86 Compare denormalized sales.orders.gross_total vs computing it on the fly from order_items. Why does RetailMart keep both? Q87 Why does call_center.transcripts store transcript_text as TEXT - what tradeoff vs JSONB? Q88 Why is supply_chain.shipments a separate schema from sales.shipments? They have similar names - explain the design intent. Q89 Defend the use of TIMESTAMP without timezone in some V3 tables vs TIMESTAMPTZ in others. Q90 Why are dim_* tables (dim_brand, dim_region, dim_date) in 'core' but customers/products/sales aren't? Q91 The PK of supply_chain.inventory_snapshots is (warehouse_id, product_id, snapshot_date) - explain this composite key design. Q92 Why does products.products NOT have a "category" column directly - what's the design tradeoff? Q93 Compare the size of customers.customers (~50K rows) vs sales.orders (~150K rows) - why are they sized this way? Q94 Why does loyalty.members have customer_id AS its primary key, not a separate member_id? Q95 The CHRO asks: "should we add a dept_name VARCHAR to stores.employees?" Defend yes or no. Q96 RetailMart has 16 schemas. Explain why a single "permissions" table doesn't exist - instead, schemas ARE the permission boundary. Q97 Why does audit.api_requests have request_id as TEXT (not INT)? Q98 The data model has multiple "id" columns: cust_id (sales.orders) vs customer_id (customers.customers). Defend (or critique) this inconsistency. Q99 Why is core.dim_category just (category_id, category_name) - only 2 columns? Q100 By the end of your first month, what 5 RetailMart facts should an analyst know cold? Name them. Interview grade, edge cases
POSTGRESQL INTERNALS DEEP-DIVE Q1 Explain MVCC in PostgreSQL. Why doesn't UPDATE overwrite a row in place? Q2 What are xmin and xmax on every row - and why do they matter for visibility? Q3 Walk through what VACUUM does and why dead tuples accumulate without it. Q4 Difference between VACUUM, VACUUM FULL, and VACUUM ANALYZE - when to use each? Q5 What is the Write-Ahead Log (WAL) and why is it the foundation of durability? Q6 Explain a CHECKPOINT - what's flushed and when does it trigger? Q7 What is the shared_buffers cache vs OS page cache - why does PostgreSQL keep both? Q8 Describe how a backend process handles a single query end-to-end (parse -> plan -> execute). Q9 What does the planner_cost_constant family of GUCs control (seq_page_cost, random_page_cost)? Q10 Explain the difference between a logical replication slot and a physical replication slot. Q11 What is "transaction wraparound" and why is it catastrophic if VACUUM falls behind? Q12 How does HOT (Heap-Only Tuples) update optimization save work? Q13 What does the visibility map track - and how does it help index-only scans? Q14 Explain the role of the autovacuum daemon and when DBAs disable it on hot tables. Q15 What is the planner's "genetic query optimization" and when does it kick in? Q16 Why does ANALYZE matter for query plans - what statistics does it gather? Q17 Explain how pg_stat_statements helps find slow queries in production. Q18 What's the difference between a relfilenode and a relation OID - and when do they diverge? Q19 Describe the role of the wal_level GUC - what does each setting enable? Q20 What is logical decoding - how is it different from streaming replication? Q21 Explain how synchronous_commit interacts with WAL durability guarantees. Q22 What is the role of the postmaster process vs backend processes? Q23 How does PostgreSQL detect and resolve deadlocks (compared to MySQL)? Q24 What is a "bloated" table or index - how do you detect and fix it? Q25 Walk through how a SELECT sees a row inserted by an uncommitted concurrent transaction. ISOLATION, LOCKING & CONCURRENCY Q26 Define dirty read, non-repeatable read, phantom read - with a 2-transaction example each. Q27 Why is READ UNCOMMITTED treated as READ COMMITTED in PostgreSQL? Q28 Demonstrate a non-repeatable read at READ COMMITTED - and show why REPEATABLE READ fixes it. Q29 Explain why PostgreSQL's REPEATABLE READ is actually "snapshot isolation" - and how it differs from SQL standard. Q30 What is a serialization failure under SERIALIZABLE - give a real example. Q31 Explain Serializable Snapshot Isolation (SSI) and why it's more expensive than REPEATABLE READ. Q32 Walk through a write skew anomaly - show what isolation level prevents it. Q33 What is a "lost update" - and how do SELECT FOR UPDATE and SERIALIZABLE each prevent it? Q34 Difference between SELECT FOR UPDATE, FOR NO KEY UPDATE, FOR SHARE, and FOR KEY SHARE. Q35 Explain row-level locks vs predicate locks - why does SSI need predicate locks? Q36 What is a deadlock - show a 2-transaction example that deadlocks on row locks. Q37 How does deadlock_timeout work - and why is the default 1 second? Q38 Explain advisory locks (pg_advisory_lock) - when do you use them over row locks? Q39 What is an "intent lock" and why does PostgreSQL not expose them at the SQL level? Q40 Difference between session-level and transaction-level advisory locks. Q41 What does LOCK TABLE ... IN ACCESS EXCLUSIVE MODE block - give 3 examples. Q42 What is "lock escalation" - and why doesn't PostgreSQL do it (unlike SQL Server)? Q43 Explain "tuple-level lock contention" on a hot row - and how to design around it. Q44 What is a "queue table anti-pattern" - and why do row locks make it perform badly? Q45 How does SKIP LOCKED help build a queue table without contention? Q46 Explain why DDL takes ACCESS EXCLUSIVE - and how to do online schema changes safely. Q47 What is the role of pg_locks and pg_stat_activity in debugging contention? Q48 Walk through how SAVEPOINT interacts with subtransaction visibility. Q49 What is "transaction ID exhaustion" risk in long-running transactions? Q50 Why is two-phase commit (PREPARE TRANSACTION) rarely used outside distributed setups? STORAGE, CATALOGS, METADATA Q51 Walk through the PostgreSQL page layout (header + line pointers + tuples + special). Q52 What does FILLFACTOR do - and when do you tune it down to 70% or 80%? Q53 Explain TOAST - when does a value get TOASTed and what are the four storage modes? Q54 Difference between EXTERNAL and EXTENDED storage modes on a TEXT column. Q55 What is a "tuple header" and why does every row have at least 23 bytes of overhead? Q56 Explain how COLUMN order affects on-disk size (the alignment padding trick). Q57 What is the difference between pg_catalog and information_schema - and which is portable? Q58 Why is pg_class.reltuples just an estimate - and what updates it? Q59 Walk through pg_attribute - how is it different from information_schema.columns? Q60 What is a "system column" (ctid, xmin, xmax, tableoid) - and when do you query them? Q61 Explain how partitioning is stored - is a partitioned table itself a heap? Q62 Difference between LIST, RANGE, and HASH partitioning - give a RetailMart example for each. Q63 What is a "partition pruning" and how does the planner decide? Q64 Why are global indexes not supported on partitioned tables - what's the workaround? Q65 Explain TABLESPACE - when do you create one (and why most setups don't need them). Q66 What is a foreign table (FDW) - give a real RetailMart use case for postgres_fdw. Q67 Walk through how a unique constraint differs internally from a unique index. Q68 What is an exclusion constraint - give an example (booking system overlap prevention). Q69 Explain partial indexes - give 2 RetailMart cases where they save 80% of index size. Q70 What is an expression index - when would you index lower(email) or date_trunc('day', ts)? Q71 Difference between B-tree, Hash, GiST, GIN, BRIN, SP-GiST - pick the right one for 5 scenarios. Q72 Why is BRIN ideal for time-series tables - and what's its tradeoff? Q73 What does CLUSTER do - and why is it not maintained automatically? Q74 Walk through how DROP TABLE and TRUNCATE differ in WAL volume and lock duration. Q75 Explain what gets written to disk during CREATE INDEX CONCURRENTLY - and why it's slower. PRODUCTION, HA, SCALING Q76 Compare physical streaming replication vs logical replication - pick the right one for 3 scenarios. Q77 What is a "hot standby" - what queries can run on it and what cannot? Q78 Explain replica lag - what causes it and how do you monitor it? Q79 What is synchronous_standby_names - and what's the durability tradeoff vs async? Q80 Walk through how a failover happens - what tools (Patroni, repmgr) automate it? Q81 What is connection pooling - why is pgBouncer essential at high concurrency? Q82 Difference between session pooling, transaction pooling, statement pooling in pgBouncer. Q83 Why do prepared statements break under transaction-pooling mode - and what's the fix? Q84 What is a "thundering herd" on a connection pool - give a real RetailMart scenario. Q85 Explain horizontal vs vertical scaling - when does sharding actually win? Q86 Walk through the Citus extension's approach to distributed PostgreSQL. Q87 What is the role of read replicas - and the read-after-write consistency trap. Q88 Explain why ORDER BY id DESC LIMIT 1 on a huge table can be slow without the right index. Q89 What is the "N+1 query" problem - give a RetailMart order-display example. Q90 Walk through a backup strategy: pg_dump vs pg_basebackup vs WAL archiving - when each is right. Q91 What is PITR (point-in-time recovery) - and what does it depend on? Q92 Explain why upgrades use pg_upgrade vs pg_dump/restore - speed and downtime tradeoffs. Q93 What is a "rolling upgrade" using logical replication - when is this needed? Q94 Walk through a real production incident: long-running transaction caused 100GB of bloat. How to recover? Q95 What is the "noisy neighbor" problem on a managed Postgres (RDS/Cloud SQL) - how do you detect? Q96 Explain pg_repack and pg_squeeze - when is VACUUM FULL not enough? Q97 What is "index bloat" - how do you measure it and when do you REINDEX CONCURRENTLY? Q98 Walk through why autovacuum can fall behind on tables with very high churn - and what to tune. Q99 Explain "row-level security" (RLS) - give a real multi-tenant RetailMart case. Q100 Design question: RetailMart hits 1B orders/year. What architectural shifts do you make? Production scenarios, optimisation
DISTRIBUTED, SHARDING, CONSENSUS Q1 Design RetailMart for 100M monthly active users - what becomes the bottleneck first? Q2 Walk through a sharding strategy for sales.orders - pros/cons of customer_id vs order_id vs date as shard key. Q3 Explain Citus's distribution table types: distributed, reference, local - when each. Q4 Why is "cross-shard JOIN" a planning nightmare - and how do you avoid it? Q5 How do you maintain referential integrity across shards (or do you)? Q6 Compare 2-phase commit vs Saga pattern for distributed transactions. Q7 What is "eventual consistency" - give a RetailMart scenario where it's OK. Q8 Explain the CAP theorem in the context of a multi-region Postgres deployment. Q9 When does linearizability matter for sales.orders - checkouts, deductions, audit? Q10 Walk through a "split-brain" scenario during failover - what prevents it? Q11 Explain RAFT consensus - and how Patroni uses it for leader election. Q12 Why is "quorum read/write" the foundation of distributed correctness? Q13 Compare strong vs eventual consistency for a customer's "lifetime spend" counter. Q14 Walk through how Aurora / Spanner / CockroachDB differ from vanilla Postgres replication. Q15 Why is logical replication the right tool for "blue-green" upgrade - but not for HA? Q16 Design a "hot replica routing" strategy: connection pool decides primary vs replica. Q17 Compare statement-level vs read-your-writes consistency for a checkout flow. Q18 What is "fence token" - and where does it appear in distributed locks? Q19 Walk through a "thundering herd" caused by cache eviction in a 4-shard cluster. Q20 Design a cross-region "global" customer table with regional sales.orders. Q21 Compare ISO/SQL standards for distributed semantics vs Postgres-specific guarantees. Q22 How does Vitess (MySQL) compare to Citus (Postgres) for OLTP scaling? Q23 Walk through CRDT-based counters - when can they replace Postgres SUM aggregations? Q24 What is "isolation downgrade" in distributed systems - give a real example. Q25 Design a "global feature flag" service that serves 100k QPS - Postgres backend? TIME-SERIES AT SCALE Q26 Design ingestion for 1B page_views per day - what's the schema, partitioning, retention? Q27 Walk through TimescaleDB vs vanilla Postgres partitioning - when each pays off. Q28 Why is BRIN ideal for time-series, but useless after VACUUM FULL? Q29 Design a "rolling window" retention policy: keep 90 days hot, 1 year warm, 7 years cold. Q30 Walk through a continuous aggregate (materialized view refreshed incrementally). Q31 Compare downsampling strategies: per-minute -> per-hour -> per-day rollups. Q32 Design a "real-time analytics" pipeline: orders -> Kafka -> ClickHouse, with Postgres as ledger. Q33 Why does ORDER BY ts DESC LIMIT 1 on a TB-scale table need a B-tree even if BRIN exists? Q34 Design index strategy for "hot last 24h" vs "cold last 5y" queries. Q35 Walk through autovacuum tuning for a 50M rows/day inserts table. Q36 Explain why HOT updates are critical for telemetry tables. Q37 Design partition pruning verification - automated test for SLA breach detection. Q38 Walk through "cold partition" archival to S3 via foreign data wrapper. Q39 Why is partition-wise JOIN important - when does PG12+ do it automatically? Q40 Compare "fact table denormalized" vs "star schema" for analytic queries. Q41 Design a "log compaction" job that deduplicates a high-churn event table. Q42 Walk through "Lambda architecture" - batch + stream + serving layers. Q43 Why is timezone-aware time-series tricky - design a single-tz solution. Q44 Design a "time-bucket sliding" query for last 24h, last 7d, last 30d, served in <100ms. Q45 Walk through "data tiering" - automated movement from hot SSD -> warm SSD -> cold S3. Q46 Compare ORC vs Parquet vs Postgres for analytic time-series. Q47 Why is "out-of-order ingest" hard to handle in partitioned time-series? Q48 Design a "late-arriving event" merge into existing partitions. Q49 Walk through "schema evolution" in append-only time-series tables. Q50 Design a "tagged time-series" table for IoT-like events (metric_name, tags, value, ts). MULTI-TENANT ISOLATION Q51 Compare row-level vs schema-level vs database-level isolation for multi-tenant. Q52 Walk through Postgres RLS (Row-Level Security) - show a complete tenant rule. Q53 Why is "tenant_id column on every table" the standard pattern? Q54 Design noisy-neighbor mitigation when one tenant runs 10x the queries of others. Q55 Walk through per-tenant connection pool exhaustion - how to limit. Q56 Compare statement_timeout vs idle_in_transaction_timeout per role. Q57 Design a "tenant onboarding" flow that creates schema, seeds tables, sets RLS in <1s. Q58 Walk through "tenant exit / GDPR delete" - cascading deletes across 50 tables. Q59 Why is pg_dump --schema=tenant_001 a bad idea at scale? Q60 Design a logical replication setup for cross-region tenant isolation. Q61 Compare workspace isolation in BigQuery vs Postgres schemas. Q62 Walk through "shared schema, separate database" tradeoffs. Q63 Design "noisy tenant detection" - auto-throttle by query count + CPU. Q64 Walk through pg_hint_plan for tenant-specific plan tuning. Q65 Design a billing/usage accounting system based on pg_stat_statements. Q66 Compare RLS vs application-side WHERE - security audit risk. Q67 Walk through column-level access control with grants + views. Q68 Design an "export tenant data" pipeline that hits replicas only. Q69 Walk through "tenant tier sizing" - small/medium/large with different SLAs. Q70 Design a "tenant compaction" job that merges small tenants into shared schema for cost. Q71 Walk through encryption-at-rest options (TDE) - and column-level encryption (pgcrypto). Q72 Design a "tenant audit log" that survives DROP DATABASE. Q73 Walk through "data residency" requirements - design region-pinned tenants. Q74 Compare AWS RDS multi-tenant patterns vs Aurora Serverless. Q75 Design a "tenant migration" plan that moves a tenant from one region to another with zero downtime. DISASTER, SCALE, COST Q76 Design a backup strategy that supports 5min RPO + 30min RTO. Q77 Walk through PITR drill - recover to "5 minutes before that bug shipped". Q78 Why is "Schrodinger's backup" common - backups exist but recovery untested? Q79 Design a "logical backup + WAL streaming" hybrid. Q80 Walk through a real "100GB bloat from long transaction" recovery. Q81 Compare pg_repack vs VACUUM FULL - production vs midnight tradeoffs. Q82 Design a "schema migration" pipeline using pg_repack to avoid downtime. Q83 Walk through "zero-downtime ADD COLUMN with default" pre-PG11 vs PG11+. Q84 Design a "zero-downtime rename" of a hot column. Q85 Walk through "zero-downtime FK addition" using NOT VALID + VALIDATE. Q86 Walk through dropping a column on a billion-row table without locking. Q87 Compare RDS / Aurora / Cloud SQL / Crunchy / Neon pricing tradeoffs. Q88 Design a "cost-aware" indexing policy: bytes-per-query justified. Q89 Walk through "ghost" indexes - created, never used, but still cost write amplification. Q90 Design an "index audit" job that flags unused indexes weekly. Q91 Walk through "WAL bloat" caused by replication slot held by dead subscriber. Q92 Design "automatic failover with sanity check" - what conditions block promotion? Q93 Walk through "data divergence after failover" - how do you reconcile? Q94 Design an "audit trail" that survives data corruption. Q95 Compare "synchronous_commit = local" vs "remote_apply" for write-heavy workloads. Q96 Walk through a "wal_size_runaway" - when does WAL refuse to recycle? Q97 Design a "checkpoint storm" mitigation strategy. Q98 Walk through "max_wal_senders saturation" - how to detect and fix. Q99 Compare Postgres 16 vs 17 vs 18 release-note highlights you'd care about as a DBA. Q100 Design RetailMart's "next-3-year scale plan": today=10K orders/day, target=10M/day. Specific architectural milestones at 100K, 1M, 10M.