Pick a topic — languages & databases — 100+ questions and answers in the center column.
PostgreSQL
Advanced SQL, MVCC, extensions, WAL, and tuning.
102 questions
Question 1
Advanced open-source RDBMS (object-relational). Strong SQL standard support, extensible types, MVCC concurrency, rich indexing—including GiST/GIN—and popular for analytics with extensions.
Example code
SELECT version()Question 2
Readers don’t block writers; old row versions kept until vacuumed—long transactions bloat tables and delay visibility.
Example code
VACUUM ANALYZE tQuestion 3
Reclaims dead tuple space and updates visibility map—tune autovacuum for high-churn tables; VACUUM FULL locks heavily.
Example code
SELECT relname, n_dead_tup FROM pg_stat_user_tablesQuestion 4
Accumulated dead tuples increasing table/index size—monitor with pg_stat_user_tables; consider fillfactor and vacuum tuning.
Example code
SELECT pg_current_wal_lsn()Question 5
Durability log applied after crash—archive for PITR; synchronous_commit trades safety vs latency.
Example code
CHECKPOINTQuestion 6
Periodic WAL flush points—checkpoint_timeout and max_wal_size tune IO spikes vs recovery time.
Example code
SHOW transaction_isolationQuestion 7
Read committed default; repeatable read and serializable use snapshot + SSI for anomalies—serializable may retry transactions.
Example code
SELECT * FROM pg_locks WHERE NOT grantedQuestion 8
Row-level FOR UPDATE/SHARE; also relation and advisory locks—deadlocks detected and one transaction aborted.
Example code
CREATE SEQUENCE sQuestion 9
SERIAL/BIGSERIAL are sequences; GENERATED ALWAYS AS IDENTITY is SQL standard—watch ownership on table drops.
Example code
CREATE TABLE t (id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY)Question 10
PK implies NOT NULL and clustered default via heap TID—unique allows NULL multiples unless constrained.
Example code
CREATE UNIQUE INDEX u ON t(email)Question 11
Runs query with timing and actual rows—BUFFERS option shows cache hits—gold standard for tuning.
Example code
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM t WHERE id=1Question 12
B-tree default; GIN for full text/jsonb containment; GiST for ranges/geo; BRIN for very large naturally ordered data.
Example code
CREATE INDEX ON t USING gin (j)Question 13
CREATE INDEX … WHERE predicate—smaller and faster for filtered hot queries.
Example code
CREATE INDEX ON t WHERE activeQuestion 14
Index on function—must match query expression exactly.
Example code
CREATE INDEX ON t (lower(email))Question 15
INCLUDE columns add payload without entering sort key—helps index-only scans when visibility map allows.
Example code
CREATE INDEX ON t (a) INCLUDE (b)Question 16
JSONB binary with operators @>, ?, path queries—GIN indexes common; JSON preserves whitespace/text.
Example code
SELECT data->>'x' FROM t WHERE data @> '{"k":1}'Question 17
First-class array types—unnest/lateral joins for normalization in queries.
Example code
SELECT * FROM t, unnest(arr) AS u(x)Question 18
Previously always optimization fence; now inliner can merge—test behavior per version.
Example code
WITH x AS (SELECT 1) SELECT * FROM xQuestion 19
Subquery can reference preceding FROM items—powerful top-N per group patterns.
Example code
SELECT * FROM t, LATERAL (SELECT * FROM u WHERE u.tid=t.id) sQuestion 20
Full support—frame clauses, RANGE/ROWS—watch sort cost on large partitions.
Example code
SELECT sum(x) OVER (PARTITION BY g) FROM tQuestion 21
to_tsvector/to_tsquery with GIN—dictionaries and ranking ts_rank; not Elasticsearch-scale but solid.
Example code
SELECT to_tsvector('simple', body) @@ to_tsquery('simple', 'foo')Question 22
Industry-standard spatial extension—geometry types, indexes, and functions.
Example code
SELECT ST_DWithin(geom, ST_MakePoint(0,0), 1000)Question 23
Query remote SQL/NoSQL/HTTP sources from Postgres—pushdown varies by wrapper.
Example code
CREATE EXTENSION postgres_fdwQuestion 24
Declarative RANGE/LIST/HASH—partition pruning in planner; unique constraints need partition key.
Example code
CREATE TABLE t (...) PARTITION BY RANGE (d)Question 25
Publish/subscribe row changes—upgrade and selective replication; not a full physical HA story alone.
Example code
CREATE PUBLICATION p FOR ALL TABLESQuestion 26
Physical standby applies WAL—sync/async replicas; hot standby for reads.
Example code
SELECT pg_is_in_recovery()Question 27
Retain WAL for consumers—prevent deletion until consumed; monitor disk if consumer stalls.
Example code
SELECT * FROM pg_replication_slotsQuestion 28
ROLE LOGIN inheritance; RLS further filters rows—defense in depth with app user separation.
Example code
GRANT SELECT ON t TO appQuestion 29
CREATE POLICY per table—must enable RLS; superuser bypass—test as app role.
Example code
ALTER TABLE t ENABLE ROW LEVEL SECURITYQuestion 30
CREATE EXTENSION loads contrib modules—versioned in share/extension; some need superuser.
Example code
CREATE EXTENSION IF NOT EXISTS citextQuestion 31
Pub/sub channel notifications—not durable; good for cache invalidation signals.
Example code
LISTEN ch; NOTIFY ch, 'payload'Question 32
Application-level mutexes pg_advisory_lock—avoid deadlocks with consistent lock order.
Example code
SELECT pg_advisory_lock(12345)Question 33
COPY fastest bulk load—FORMAT csv FREEZE requires care; triggers still fire unless disabled.
Example code
COPY t FROM STDIN WITH (FORMAT csv)Question 34
Gather nodes split scans/aggregates—controlled by max_parallel_workers and cost thresholds.
Example code
SET max_parallel_workers_per_gather = 4Question 35
PgBouncer transaction vs session pooling—prepared statements and temp tables have mode constraints.
Example code
SET jit = offQuestion 36
Normalized query stats extension—find regressions and hotspots; requires shared_preload_libraries.
Example code
-- PgBouncer: session vs transaction poolingQuestion 37
pg_basebackup + WAL archive—restore to timestamp with recovery_target.
Example code
SELECT * FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 5Question 38
pg_upgrade in-place, logical dump/restore, or replication cutover—choose by size and extensions.
Example code
pg_basebackup -D /backup -Fp -Xs -PQuestion 39
Out-of-line large values—transparent; extreme wide rows have performance implications.
Example code
-- PostgreSQL: toast storage
SELECT 1Question 40
Leave page free space for HOT updates—tune on append-mostly vs update-heavy tables.
Example code
-- PostgreSQL: fillfactor
SELECT 1Question 41
Heap-only tuple updates when indexed columns unchanged—reduces index churn.
Example code
-- PostgreSQL: HOT updates
SELECT 1Question 42
Helps index-only scans and vacuum—corruption rare but serious.
Example code
-- PostgreSQL: Visibility map
SELECT 1Question 43
Tracks page space for inserts—vacuum maintains.
Example code
-- PostgreSQL: Free space map
SELECT 1Question 44
Very old xmin/xmax horizons block vacuum—watch long transactions and replication slots.
Example code
-- PostgreSQL: Multi-version snapshot limits
SELECT 1Question 45
Cancel runaway queries at server or role level—pair with pool timeouts.
Example code
-- PostgreSQL: Statement timeout
SELECT 1Question 46
Fail fast on lock wait—better UX than indefinite hangs.
Example code
-- PostgreSQL: Lock timeout
SELECT 1Question 47
How long before deadlock check runs—usually small.
Example code
-- PostgreSQL: deadlock_timeout
SELECT 1Question 48
Cap disk sorts/hash spills—prevent runaway disk from one query.
Example code
-- PostgreSQL: temp_file_limit
SELECT 1Question 49
Per-sort/hash operator memory—high global * concurrency can OOM.
Example code
-- PostgreSQL: work_mem
SELECT 1Question 50
VACUUM CREATE INDEX memory—raise for index builds carefully.
Example code
-- PostgreSQL: maintenance_work_mem
SELECT 1Question 51
Planner hint about OS cache—not reserved memory.
Example code
-- PostgreSQL: effective_cache_size
SELECT 1Question 52
Tune for SSD vs HDD—SSDs often lower random cost.
Example code
-- PostgreSQL: random_page_cost vs seq_page_cost
SELECT 1Question 53
More samples for skewed columns—increase on important predicates.
Example code
-- PostgreSQL: default_statistics_target
SELECT 1Question 54
CREATE STATISTICS for correlated columns—helps planner on multi-column filters.
Example code
-- PostgreSQL: Extended statistics
SELECT 1Question 55
Trigram similarity and GIST/GIN ops for LIKE patterns—better than naive btree for contains.
Example code
-- PostgreSQL: pg_trgm extension
SELECT 1Question 56
Hybrid opclasses—combined conditions on mixed types.
Example code
-- PostgreSQL: btree_gin / btree_gist
SELECT 1Question 57
Case-insensitive text—simpler than lower() indexes for emails.
Example code
-- PostgreSQL: citext type
SELECT 1Question 58
UUID generation—prefer gen_random_uuid() in core when available.
Example code
-- PostgreSQL: uuid-ossp / pgcrypto
SELECT 1Question 59
hstore flat string map—jsonb richer; choose by access patterns.
Example code
-- PostgreSQL: hstore vs jsonb
SELECT 1Question 60
tstzrange, int4range with GiST indexes—scheduling and exclusion constraints.
Example code
-- PostgreSQL: Range types
SELECT 1Question 61
Prevent overlapping bookings—EXCLUDE USING gist.
Example code
-- PostgreSQL: Exclusion constraints
SELECT 1Question 62
Rules rewrite queries pre-plan—triggers per row; prefer triggers for clarity.
Example code
-- PostgreSQL: Rules vs triggers
SELECT 1Question 63
DDL hooks—migration guardrails and auditing.
Example code
-- PostgreSQL: Event triggers
SELECT 1Question 64
Change capture for CDC tools—wal2json, pgoutput plugin.
Example code
-- PostgreSQL: Logical decoding
SELECT 1Question 65
Online bloat cleanup without heavy locks—alternative to CLUSTER.
Example code
-- PostgreSQL: pg_repack
SELECT 1Question 66
Scheduled jobs inside DB—convenient but operational discipline needed.
Example code
-- PostgreSQL: pg_cron
SELECT 1Question 67
Time-series hypertable extension—chunking and retention policies.
Example code
-- PostgreSQL: TimescaleDB
SELECT 1Question 68
Distributed Postgres—sharding and parallel queries across nodes.
Example code
-- PostgreSQL: Citus
SELECT 1Question 69
auth_query pattern for dynamic users—complex but scalable.
Example code
-- PostgreSQL: pgBouncer auth
SELECT 1Question 70
Default password auth—ensure clients support; md5 legacy.
Example code
-- PostgreSQL: SCRAM auth
SELECT 1Question 71
verify-full for prod—prevent MITM to DB.
Example code
-- PostgreSQL: SSL modes
SELECT 1Question 72
Host-based auth rules—order matters; reload not restart for many changes.
Example code
-- PostgreSQL: pg_hba.conf
SELECT 1Question 73
External name mapping—Kerberos/SSPI integrations.
Example code
-- PostgreSQL: pg_ident.conf
SELECT 1Question 74
Place objects on different disks—backup/restore paths must include all.
Example code
-- PostgreSQL: Tablespaces
SELECT 1Question 75
Fast, not crash-safe—staging only.
Example code
-- PostgreSQL: Unlogged tables
SELECT 1Question 76
Session-scoped; ON COMMIT DROP—watch bloat in long sessions.
Example code
-- PostgreSQL: Temporary tables
SELECT 1Question 77
REFRESH CONCURRENTLY needs unique index—snapshot reporting pattern.
Example code
-- PostgreSQL: Materialized views
SELECT 1Question 78
Planner joins matching partitioned tables per partition—big wins when stats good.
Example code
-- PostgreSQL: Partition-wise join
SELECT 1Question 79
FK referencing partitioned table limitations improved over versions—verify docs.
Example code
-- PostgreSQL: Declarative partitioning pitfalls
SELECT 1Question 80
Huge time-series append-only—tiny index size with correlation.
Example code
-- PostgreSQL: BRIN index use case
SELECT 1Question 81
Not WAL-logged historically—now safer; still niche vs btree.
Example code
-- PostgreSQL: Hash indexes pre-10
SELECT 1Question 82
Fast insert deferred merge—gin_pending_list_limit tuning.
Example code
-- PostgreSQL: GIN pending list
SELECT 1Question 83
storage_parameters—aggressive settings for append-heavy fact tables.
Example code
-- PostgreSQL: Autovacuum per table
SELECT 1Question 84
Custom -Fc parallel restore friendly—directory format for parallel pg_restore.
Example code
-- PostgreSQL: pg_dump formats
SELECT 1Question 85
Hardlinks fast upgrade—cannot revert easily; have backups.
Example code
-- PostgreSQL: pg_upgrade link mode
SELECT 1Question 86
HA failover managers—etcd/consul coordination common.
Example code
-- PostgreSQL: repmgr / Patroni
SELECT 1Question 87
Alternative HA controller—Kubernetes friendly patterns.
Example code
-- PostgreSQL: Stolon
SELECT 1Question 88
Backup tool with parallel, encryption, S3—popular in enterprise Postgres ops.
Example code
-- PostgreSQL: pgBackRest
SELECT 1Question 89
archive_command to object storage—lifecycle policies for cost.
Example code
-- PostgreSQL: WAL archiving to cloud
SELECT 1Question 90
DDL not replicated—sequences need manual handling; conflict strategies on subscribers.
Example code
-- PostgreSQL: Logical replication limitations
SELECT 1Question 91
Expression JIT for analytics—jit=off in postgresql.conf for predictable OLTP latency.
Example code
-- PostgreSQL: JIT compilation
SELECT 1Question 92
Inspect WAL records for deep debugging—niche DBA tool.
Example code
-- PostgreSQL: pg_waldump
SELECT 1Question 93
initdb --data-checksums detects corruption—slight overhead; enable on new clusters.
Example code
-- PostgreSQL: checksums on data pages
SELECT 1Question 94
Offline verification tool—part of data integrity drills.
Example code
-- PostgreSQL: pg_verify_checksums
SELECT 1Question 95
Verify B-tree structural integrity—find silent corruption early.
Example code
-- PostgreSQL: amcheck extension
SELECT 1Question 96
Emergency repair—last resort with backups.
Example code
-- PostgreSQL: pg_surgery extension
SELECT 1Question 97
IO timing visibility—identifies backend vs vacuum IO.
Example code
-- PostgreSQL: pg_stat_io (Postgres 16+)
SELECT 1Question 98
CREATE SUBSCRIPTION on replica—publication name and copy_data options matter.
Example code
-- PostgreSQL: subscription (logical)
SELECT 1Question 99
Selective logical replication—WHERE on published tables.
Example code
-- PostgreSQL: publication row filter
SELECT 1Question 100
Track upstream for bidirectional setups—conflict avoidance is hard.
Example code
-- PostgreSQL: slot replication origins
SELECT 1Question 101
Progress bars for VACUUM, CREATE INDEX, CLUSTER—estimate ETA.
Example code
-- PostgreSQL: pg_stat_progress_*
SELECT 1Question 102
Shared-memory buffers for WAL before fsync—usually auto-tuned; adjust only with measurement.
Example code
-- PostgreSQL: wal_buffers
SELECT 1