Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Describe what happens inside PostgreSQL when a Java service opens a JDBC connection and runs an UPDATE that commits. Name the processes involved and where the changed row lives before and after commit.

The postmaster accepts the JDBC connection and forks a dedicated backend process for it, and that backend parses, plans and executes the UPDATE. The row's page is loaded into shared_buffers, where the backend writes a new row version and marks the page dirty, and it also writes a WAL record. At COMMIT the WAL is flushed to disk before success is returned (with synchronous_commit on), while the dirty page itself reaches the data file later, written by the background writer or the checkpointer.

Why this question is asked

When a Java service calls executeUpdate() and then commit(), it is easy to imagine the database simply changing a row in a file. What really happens involves several processes and two different paths to disk, and that difference explains why PostgreSQL is both durable and fast. Interviewers ask this question because it shows whether we understand the basis for tuning connections, memory and checkpoints. In this answer, we will follow the connection from the first packet to a backend process, follow the UPDATE into shared buffers and the WAL, see exactly what COMMIT waits for, and then look at the helper processes that finish the job later.

1Opening the Connection: Postmaster and Backend

PostgreSQL runs as a group of operating system processes. The first one, the postmaster, listens on port 5432. When the JDBC driver connects, the postmaster accepts the socket, checks authentication rules from pg_hba.conf, and then forks a new child process called a backend. From that moment, our connection talks only to its own backend; the postmaster goes back to waiting for the next connection.

So every connection is a separate process with its own memory for sorting, caching plans and catalog data. This is the reason connection pools such as HikariCP exist on the Java side: creating a process costs a few milliseconds, and keeping thousands of them alive costs memory.

Java
try (Connection c = DriverManager.getConnection(url, user, pass)) { // postmaster forks backend pid 48211
c.setAutoCommit(false);
try (PreparedStatement ps = c.prepareStatement(
"UPDATE accounts SET balance = balance - 100 WHERE id = ?")) {
ps.setLong(1, 7);
ps.executeUpdate(); // 1: the backend changed one row
}
c.commit(); // returns only after the WAL is on disk
}

We can see our backend from SQL with SELECT pg_backend_pid(), and it appears as one row in pg_stat_activity.

2Running the UPDATE: Parse, Plan, Execute

The backend receives the statement text, parses it into a tree, rewrites it (applying views and rules), and plans it: here the planner chooses an index scan on the primary key of accounts. Then the executor runs the plan and finds the row with id = 7.

To change the row, the backend first needs the 8 KB page that holds it. It looks in shared_buffers, the memory area all backends share as a cache of data pages. If the page is not there, the backend reads it from the table's data file into a free buffer. Then it makes the change in memory. Because of MVCC, PostgreSQL does not overwrite the old row. It writes a new row version (a tuple) with the new balance and marks the old version as replaced by our transaction. The page is now dirty, meaning the copy in memory differs from the copy on disk.

3The WAL Record and What COMMIT Waits For

Before the dirty page may ever be written to disk, PostgreSQL must record the change in the write-ahead log. So along with changing the page, the backend writes a WAL record describing the change into WAL buffers, another shared memory area.

At COMMIT, the backend writes a commit record and then flushes the WAL up to that record to disk with fsync, which waits until the storage confirms the data is durable. Only then does the client receive success. With synchronous_commit = on, the default, a crash after this point cannot lose the transaction, because the WAL on disk is enough to redo it.

Notice what COMMIT does not wait for: the data page. The new row version lives in shared_buffers, dirty, and the table's file on disk still holds the old version. That is safe, because the WAL can rebuild the page after a crash. And it is fast, because writing a few hundred bytes sequentially to the WAL is far cheaper than writing random 8 KB pages to many data files.

Step throughUPDATE and COMMIT inside PostgreSQL
JDBC clientBackendShared buffersWAL on diskData file
UPDATE accounts ... WHERE id = 7
read the page if it is not cached
write new row version, mark page dirty
add WAL record to WAL buffers
COMMIT
write and fsync WAL up to the commit record
COMMIT succeeded
later: bgwriter or checkpointer writes the page

8 messages in order. Play them, or step through them one at a time.

Only the WAL flush is on the commit path; the data page is written later.

4Where the Row Lives Before and After Commit

Before the UPDATE, the row exists as one tuple in the data file and possibly a cached copy of its page in shared_buffers. Right after the UPDATE but before COMMIT, there are two versions in the buffer page: the old one, still visible to every other transaction, and the new one, visible only to ours. After COMMIT, the new version becomes visible to transactions that start afterwards, but both versions still sit in shared memory and the data file still has only the old one.

Later, the dirty page is written to the data file, and much later vacuum removes the old version once no snapshot can see it. So a single UPDATE touches the page cache immediately, the WAL at commit, the data file at some later point, and vacuum later still.

Where the change is at each moment
Momentshared_buffersWAL on diskData file
Before UPDATEold version (if cached)nothing newold version
After UPDATEold and new versions, page dirtymaybe not yetold version
After COMMITboth versions, new one committedchange and commit recordold version
After checkpointpage cleancan be recycled laterboth versions
After vacuumold version removedvacuum recordspace reusable

5The Helper Processes

Several background processes keep this working. The background writer trickles dirty pages to disk so backends rarely have to write pages themselves when they need a free buffer. The checkpointer runs periodic checkpoints that write all dirty pages and mark a point from which crash recovery can start. The walwriter flushes WAL buffers regularly, which matters for asynchronous commits. The autovacuum launcher starts autovacuum workers that clean up old row versions and update statistics.

If there are replicas, a WAL sender process streams WAL to each one. Logical replication adds its own launcher and worker processes, and a cumulative statistics system (in shared memory since PostgreSQL 15) collects the numbers we read from views like pg_stat_user_tables. We can see all of them with ps on the database host or in pg_stat_activity, where the backend_type column names each one.

6Follow-up questions

Why is a process per connection expensive for a service with 2,000 pooled connections?

Each backend is a full operating system process with its own memory for catalog caches, plan caches and work_mem allocations, often several megabytes even when idle, and many more during sorts. Two thousand of them waste memory, increase context switching and contention on shared structures, and slow snapshot creation. Most of them sit idle at any moment. A better design is a smaller application pool per instance and a server-side pooler such as PgBouncer in transaction mode, so a few hundred backends serve thousands of client connections.

What does synchronous_commit = off risk?

With it off, COMMIT returns before the WAL is flushed; the walwriter flushes it shortly afterwards, by default within about three times wal_writer_delay, roughly 600 ms. A crash in that window loses the most recently committed transactions, even though the client was told they succeeded. It does not corrupt the database, because the WAL order is still respected. It can be set per transaction, so it suits data like click logs, not payments.

Does the backend ever write data pages itself?

Yes, when it needs a free buffer and the one it picks is dirty, it must write it first. If backends do this often, the background writer is not keeping up, which shows in pg_stat_io in PostgreSQL 16 and later.

7Conclusion

In this answer, we followed one UPDATE through PostgreSQL. The postmaster forks a backend per connection, and the backend parses, plans and executes the statement. It loads the page into shared_buffers, writes a new row version, marks the page dirty and writes a WAL record. COMMIT flushes the WAL to disk before returning, which makes the change durable, while the background writer and checkpointer write the data page later. Walwriter, autovacuum, WAL senders and replication workers complete the picture.

What to say in the interviewAbout 80 seconds aloud

Open with

When the JDBC driver connects, the postmaster accepts the connection, authenticates it and forks a dedicated backend process, so each connection is its own process. That backend parses the UPDATE, plans it, for example an index scan on the primary key, and executes it.

Then, if they want more

The page holding the row is read into shared_buffers if it is not already there, and because of MVCC the backend writes a new tuple version into that page and marks the old one as replaced, so the page becomes dirty. At the same time it writes a WAL record describing the change into the WAL buffers.

On COMMIT it writes a commit record and flushes the WAL to disk with fsync before telling the client it succeeded, assuming synchronous_commit is on.

The data page itself is not written at commit; it stays dirty in shared buffers until the background writer or the checkpointer writes it to the table file later, and that is safe because recovery can replay the WAL.

Other processes involved are the walwriter, the autovacuum launcher and workers that eventually remove the old row version, WAL senders streaming to replicas, and logical replication workers if we use them.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 15, PostgreSQL 16
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
PostgreSQL documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Describe what happens inside PostgreSQL when a Java service opens a JDBC connection and...": https://scrivio-interview-library.netlify.app/databases/postgresql/5c588052c2/