LearnThatStack Ace your next interview
Database Technologies

PostgreSQL.

Start free Change topic Change
Practice · Questions

All questions

Showing of 42
Beginner 9
01

Explain the ACID properties in PostgreSQL.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

ACID names four guarantees a transaction gives. PostgreSQL provides them with constraints, multiversion concurrency control (MVCC) snapshots and its write-ahead log (WAL).

  • Atomicity means a transaction is all or nothing. If any statement in it fails, PostgreSQL rolls the whole transaction back, and none of its changes ever become visible.
  • Consistency means every transaction leaves the data valid. PostgreSQL enforces this with constraints such as primary keys, foreign keys and CHECK.
  • Isolation means a transaction does not see the unfinished changes of others. PostgreSQL gives each statement an MVCC snapshot of the data.
  • Durability means a committed change survives a crash. PostgreSQL records the change in the WAL and flushes that log to disk before COMMIT returns.

Outside a BEGIN block, PostgreSQL runs each statement as its own transaction. Wrapping the transfer below in BEGIN and COMMIT makes its two updates one atomic unit.

BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT; -- Both operations succeed or both fail
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What are the main PostgreSQL data types?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

PostgreSQL's main types cover numbers, text, and dates and times. It also stores binary data and JSON. Arrays, UUIDs and network addresses have their own types too.

  • Whole numbers use integer or bigint. Exact decimals use numeric, also spelled decimal, and approximate values use real or double precision.
  • Text uses char, varchar or text. Unlike in some other database systems, char has no speed advantage in PostgreSQL.
  • Dates and times use date, time and timestamp, and spans of time use interval.
  • boolean holds true or false, and bytea holds binary data.
  • json keeps JSON as plain text, while jsonb stores it in a binary form that is faster to query.
  • Arrays can hold any data type, uuid stores universally unique identifiers, and inet and cidr store IP addresses.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is the difference between PRIMARY KEY and UNIQUE constraints?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Both reject duplicate values, but a primary key also forbids NULLs, and a table can have only one. A table can have many UNIQUE constraints, and their columns accept NULLs.

  • A primary key is the row's main identifier, and foreign keys usually point to it. PostgreSQL requires its values to be unique and not null.
  • A UNIQUE column accepts many NULLs by default, because two NULLs never count as equal. From PostgreSQL 15, declaring it UNIQUE NULLS NOT DISTINCT allows only one NULL.
  • Both create a unique B-tree index automatically, and a foreign key can reference either one.
CREATE TABLE users (
    id SERIAL PRIMARY KEY,        -- Cannot be NULL
    email VARCHAR(255) UNIQUE,    -- Can have many NULLs
    username VARCHAR(50) UNIQUE   -- Multiple unique constraints allowed
);
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

Explain the difference between DELETE, TRUNCATE, and DROP.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

DELETE removes chosen rows, TRUNCATE empties the whole table, and DROP removes the table itself.

  • DELETE removes the rows its WHERE clause matches and fires ON DELETE triggers. The deleted rows stay on disk as dead rows until VACUUM reclaims the space.
  • TRUNCATE removes every row without scanning the table, so it is faster and frees the disk space at once. It fires ON TRUNCATE triggers, not ON DELETE triggers, and it blocks all other access to the table.
  • DROP removes the table definition along with its data, indexes and constraints.

In PostgreSQL, all three can be rolled back inside a transaction, because schema changes such as DROP TABLE are transactional too. A ROLLBACK after BEGIN brings a dropped table back.

DELETE FROM users WHERE age < 18;  -- Removes specific rows
TRUNCATE TABLE users;              -- Removes all rows
DROP TABLE users;                  -- Removes table entirely
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is a foreign key and how does it work in PostgreSQL?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A foreign key is a column whose values must match a row in another table. PostgreSQL rejects any change that would break that link, which is called referential integrity.

CREATE TABLE departments (
    dept_id SERIAL PRIMARY KEY,
    dept_name VARCHAR(100)
);

CREATE TABLE employees (
    emp_id SERIAL PRIMARY KEY,
    emp_name VARCHAR(100),
    dept_id INTEGER REFERENCES departments(dept_id)
);

Here every employees.dept_id must name an existing department or be NULL. PostgreSQL enforces the link in three ways.

  • An INSERT or UPDATE that sets a dept_id with no matching department fails.
  • Deleting a department that employees still reference fails by default, which is ON DELETE NO ACTION.
  • ON DELETE CASCADE deletes the referencing employees instead, and ON DELETE SET NULL sets their dept_id to NULL.

The referenced column must be a primary key or have a unique constraint. PostgreSQL does not index the referencing column for you, so a delete from departments must search employees unless you index employees.dept_id.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What are indexes and why are they important?

Part of Pro
07

What is the difference between SERIAL and identity columns in PostgreSQL?

Part of Pro
08

Explain different types of JOINs in PostgreSQL with examples.

Part of Pro
09

Explain the difference between UNION and UNION ALL.

Part of Pro
Intermediate 13
10

What are Common Table Expressions (CTEs) and when would you use them?

Part of Pro
11

Explain window functions and provide practical examples.

Part of Pro Visual
12

What is the difference between a view and a materialized view?

Part of Pro
13

Explain PostgreSQL transaction isolation levels.

Part of Pro Visual
14

What are stored procedures and functions in PostgreSQL?

Part of Pro
15

Explain triggers and provide a practical example.

Part of Pro
16

What is MVCC and how does it work in PostgreSQL?

Part of Pro
17

What is PostgreSQL connection pooling and how does PgBouncer work?

Part of Pro
18

How do you add an index to a busy table without blocking writes?

Part of Pro Visual
19

What row-level locks does PostgreSQL offer, and when do you use SELECT FOR UPDATE?

Part of Pro
20

What are PostgreSQL extensions and name some important ones?

Part of Pro
21

Explain JSON and JSONB data types and their differences.

Part of Pro
22

What are database roles and how do you implement role-based access control?

Part of Pro
Expert 20
23

Explain PostgreSQL's query execution plan and how to optimize queries.

Part of Pro
24

What is table partitioning and when should you use it?

Part of Pro
25

Explain different types of indexes in PostgreSQL and their use cases.

Part of Pro
26

Explain PostgreSQL replication types and their use cases.

Part of Pro
27

What are the key considerations for PostgreSQL security?

Part of Pro
28

Explain VACUUM, ANALYZE, and REINDEX in PostgreSQL.

Part of Pro Visual
29

How do you handle deadlocks in PostgreSQL?

Part of Pro Visual
30

Explain Write-Ahead Logging (WAL) and its importance.

Part of Pro Visual
31

What are the best practices for PostgreSQL backup and recovery?

Part of Pro Visual
32

How do you monitor and troubleshoot PostgreSQL performance?

Part of Pro
33

Explain PostgreSQL's approach to handling large objects and binary data.

Part of Pro
34

Explain PostgreSQL's foreign data wrappers (FDW).

Part of Pro
35

How do you implement custom aggregates and operators in PostgreSQL?

Part of Pro Visual
36

What is logical decoding and how is it used?

Part of Pro
37

How do you implement database sharding strategies in PostgreSQL?

Part of Pro Visual
38

How do you implement audit logging in PostgreSQL?

Part of Pro
39

What is transaction ID wraparound in PostgreSQL, and how do you prevent it?

Part of Pro
40

What is a HOT update in PostgreSQL, and how does fillfactor help?

Part of Pro
41

What is an index-only scan, and what does it need to work?

Part of Pro
42

How do you upgrade PostgreSQL to a new major version?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for PostgreSQL? Send them this set.
Quick recap

PostgreSQL in pictures.

A quick recap of PostgreSQL in 31 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 27 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

37 of 42 PostgreSQL answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git