PostgreSQL flashcards
The open source relational database that does it all.
What is PostgreSQL, in one plain sentence?
PostgreSQL (often called Postgres) is a free program that stores an app's data in and answers questions about it, safely, for many people at once.
Tap to turn over. Swipe right if you know it, left to see it again.
What you will learn
Start from zero
- What PostgreSQL is and why it exists4 cards
- Tables and a first query2 cards
- Servers, data types and NULL2 cards
- Keys, constraints and indexes in plain words2 cards
- Before and after this topic2 cards
Core basics
- Connecting and psql5 cards
- Creating and changing tables5 cards
- Inserting, updating and deleting2 cards
- Filtering, NULL and expressions3 cards
- Keys, joins, grouping and subqueries6 cards
Next steps
- Transactions and ACID2 cards
- Indexes and query plans4 cards
- Modeling choices: JSON, arrays and enums4 cards
- Upserts and data movement2 cards
- Window functions and recursive queries2 cards
- Views, schemas and roles4 cards
- Full-text search and triggers2 cards
- Backups and safe operations3 cards
Go deeper
- MVCC, vacuum and bloat4 cards
- Isolation, locking and concurrency5 cards
- Partitioning, replication and pooling3 cards
- WAL and point-in-time recovery2 cards
- Special indexes2 cards
- Performance tuning2 cards
- Security and multi-tenancy2 cards
- Extensions and new releases3 cards
Final test and certificate
10 questions drawn fresh from the whole topic, about 15 minutes. Sign in, score 80% or more and get a free certificate with your name and a public check link anyone can open, such as an employer or a teacher. Not signed in? Try a practice test from the cards.
Take the final testAbout these cards
- Reviewed 26 October 2026
- CoversPostgreSQL 18 (18.6)PostgreSQL 19 release candidate, October 2026Supported majors 14 to 18; 14 ends November 2026
Checked against
PostgreSQL at a glance
PostgreSQL is a free database that keeps an app's data in tables and answers questions about it.
Like a strict, fast librarian: every fact on a labelled shelf, and any record found the moment you ask.
Words you will meet
- Table
- A grid of data, like one sheet in a spreadsheet
- Row
- One record in a table, such as one customer
- Column
- One kind of fact in a table, such as the city
- Query
- One question or command you send to the database
- Primary key
- The column that gives each row its own unique id
- Foreign key
- A column that points to a row in another table
- NULL
- No value or unknown, not the same as zero
- Index
- A shortcut that helps the database find rows fast
The steps
- 1. Start from zero (12 cards): What a database is, why it exists, and the words you need before Core basics.
- 2. Core basics (21 cards): psql, tables, types, keys and the everyday queries you run on day one.
- 3. Next steps (23 cards): Transactions, indexes, query plans, JSONB, upserts, roles and backups.
- 4. Go deeper (23 cards): MVCC, vacuum, locking, isolation, partitioning, replication and tuning at scale.
All 12 cards in Start from zero
- What is PostgreSQL, in one plain sentence?
- PostgreSQL (often called Postgres) is a free program that stores an app's data in tables and answers questions about it, safely, for many people at once.
- Before databases, how did a shop keep track of thousands of orders?
- In ledgers, spreadsheets or loose files. Two people editing at once overwrote each other, files got damaged, and finding one order among millions took ages.
- Where do you already meet a database like PostgreSQL in daily life?
- Your bank balance, a train ticket booking, your order history in a shopping app and your saved address are all rows in a database behind the app.
- What is a good everyday picture of a database?
- A very strict, very fast librarian. Every fact goes on a labelled shelf, he refuses anything that breaks the rules, and he finds any record the moment you ask.
- What are a table, a row and a column?
- A table is like one sheet in a spreadsheet, such as customers. Each row is one record (one customer) and each column is one kind of fact (name, city). Relational means tables can link to each other.
- Your first tiny win: what does this SQL ask?
- SQL is the language you talk to the database in, and one question is a query.
SELECTpicks which columns,FROMnames which table, andWHEREkeeps only which rows match. - What do server, client and connection mean for a database?
- PostgreSQL runs as a server, a program that waits for questions. You reach it with a client such as
psql, opening a connection with a user name, a password and a database name. - What is a data type, and what does NULL mean?
- Each column has a data type: text, a whole number, a decimal, a date and time, or true and false. NULL means no value or unknown, which is not the same as zero or empty text.
- What are a primary key and a foreign key?
- A primary key is a column that gives each row its own unique id, like a roll number in a class. A foreign key is a column that points to a row in another table, like an order pointing to its customer.
- What are a constraint and an index?
- A constraint is a rule the database enforces, such as 'price cannot be negative'. An index is like the index at the back of a book: it lets the database find rows fast without reading every one.
- What do you need before you start?
- Nothing to install to begin: read the cards and their example results. To try queries yourself, install PostgreSQL 18 on your computer, which also gives you the
psqltool. - After this topic, what will you be able to do?
- Connect to a database, create tables that refuse bad data, add, change and remove rows, join tables together and build simple reports with counts and totals.
PostgreSQL cheatsheet
psql
\l \c db \dnDatabases, connect, schemas\dt \d+ ordersTables, full table detail\di \df \duIndexes, functions, roles\x autoExpanded view for wide rows\timing onShow query time\eEdit last query in$EDITOR\copy t TO 'out.csv' CSV HEADERExport from the client side\watch 2Rerun the last query every 2 s
Postgres SQL
INSERT ... RETURNING idGet generated values backON CONFLICT (k) DO UPDATE SET v = EXCLUDED.vUpsertSELECT DISTINCT ON (k) ... ORDER BY k, ts DESCLatest row per keyFOR UPDATE SKIP LOCKEDJob queue pickgenerate_series('2026-10-01'::date, '2026-10-31', '1 day')Fill date gapsa IS DISTINCT FROM bNULL-safe comparex::int / now() - interval '7 days'Cast, date maths
JSONB and arrays
data->'a' / data->>'a'Get asjsonb/ astextdata #>> '{a,b}'Nested path as textdata @> '{"k":"v"}'Contains (GIN-indexable)data ? 'k'Key existsjsonb_set(data, '{a}', '1')Change one keydata - 'k'Remove a keytags @> ARRAY['rust']Array contains
Performance
EXPLAIN (ANALYZE, BUFFERS)Real plan with I/OCREATE INDEX CONCURRENTLYBuild without blocking writesCREATE INDEX ... WHERE condPartial indexUSING gin (col jsonb_path_ops)FastjsonbcontainmentUSING brin (created_at)Tiny index for append-only timepg_stat_statementsTop queries by total timeANALYZE ordersRefresh planner statistics
Admin and safety
SET lock_timeout = '3s'Fail fast in migrationsALTER ROLE r SET statement_timeout = '5s'Cap query timepg_dump -Fc / pg_restore -j 8Backup and parallel restoreSELECT pg_cancel_backend(pid)Cancel a querySELECT pg_terminate_backend(pid)Kill a sessionpg_stat_activity WHERE state <> 'idle'What is running nowSELECT pg_reload_conf()Reload config, no restart