liveBook · Manning

PostgreSQL

As explained in Latency

PostgreSQL is an open-source relational database management system that operates as a database server.

PostgreSQL is an open-source relational database management system that runs as a database server. A REST API can connect to it through a pooled client connection and use SQL to produce HTTP responses. section 3.5

REST API request path

A Rust Actix Web handler obtains a connection from a mobc pool, executes SELECT 'hello world', and returns the first result. Running the service with DATABASE_URL and measuring /hello with wrk makes database and network latency observable. section 3.5

Listing 3.2 The HTTP request handler with PostgreSQL
async fn say_hello(
    pool: web::Data<DatabasePool>,
) -> anyhow::Result<String, Error> {
    let conn = pool
        .get()
        .await
        .map_err(ErrorInternalServerError)?;
    let result = conn
        .query_one("SELECT 'hello world'", &[])
        .await
        .map_err(ErrorInternalServerError)?;
    Ok(result.get(0))
}

Inspect the handler that acquires a pooled PostgreSQL connection, executes a query, maps failures to HTTP errors, and returns the result. section 3.5

Compared with an embedded SQLite database, PostgreSQL introduces network-access variability: the measured REST API showed higher latency and lower throughput, while retaining the client-server deployment model. section 3.5

How Latency covers it

How deep it goes
Demonstrates installation, connectivity, pooled access, query execution, and latency measurement, but does not develop database internals.
Examples
Uses a /hello endpoint, SELECT 'hello world', Docker, psql, Rust, mobc, Actix Web, and wrk.
What it assumes
Assumes basic Rust and HTTP development, while providing commands to install PostgreSQL, verify it with psql, and run the service.
What you can do after
Operate PostgreSQL for a Rust REST API and benchmark its latency against SQLite using wrk.
How it connects
Connects PostgreSQL with REST APIs, SQL, connection pooling, SQLite, network access, and HTTP benchmarking.

Also explained in

Compare how 11 books explain PostgreSQL →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.