Skip to main content

Module postgres

Module postgres 

Source
Expand description

A throwaway Postgres for the lifetime of one command.

Replaces the sqlx-cli shell-out: the database is created and migrated in-process through sqlx, using the same migrations/ directory the server embeds via server::db::MIGRATOR. One set of migrations, one migrator, no second implementation that can drift.

initdb and pg_ctl remain external programs because they are external programs; there is no library form of them.

The cluster inherits the scheduling priority of xtask postgres itself, and a non-root process cannot lower its nice value again. Callers must not nice xtask postgres, only the command it runs.

ModulesΒ§

sweep πŸ”’
Removal of throwaway clusters a killed xtask postgres left in RAM.

StructsΒ§

Postgres
A running cluster that stops itself when dropped.

ConstantsΒ§

CLUSTER_PREFIX πŸ”’
CONNECTIONS πŸ”’
A full workspace test run at default parallelism holds well over the stock 100 connections.
DURABILITY_OFF πŸ”’
Durability is off on purpose. This cluster is initdb’d moments earlier and dies with the container, so there is nothing for it to protect β€” every fsync is pure cost, paid on cloud block storage, and 275 of the tests create and migrate a database of their own. Measured worth ~2m30s of a test run.
PORT_RANGE πŸ”’
Ports tried in order. No allocator to lean on: a port that cannot be bound is skipped without starting a server, and pg_ctl -w exiting non-zero covers a port taken between the probe and the start.
RAM_DISK πŸ”’
Where the cluster lives when there is room: in RAM. Every test database is created and dropped, and each DROP DATABASE waits for an immediate checkpoint; on a disk shared with other runs one such checkpoint was seen to spend 17 s in write() while every new connection queued behind it.
RAM_DISK_MIN_FREE πŸ”’
A full workspace run peaks well under this.
SETUP_DURATIONS_SINCE πŸ”’
First server major version whose log_connections accepts setup_durations; earlier ones take only a boolean and refuse to start on the string.
SOCKET_PATH_MAX πŸ”’
Longest unix socket path the kernel accepts, sun_path less its NUL.
TIMEOUTS πŸ”’
Bounds on how long the server will let a client misbehave.

StaticsΒ§

MIGRATOR πŸ”’
The project’s migrations, embedded at compile time from the same directory server::db::MIGRATOR reads. Embedding needs no database, which is what lets this binary be built before the server it goes on to test.

FunctionsΒ§

check_socket_path πŸ”’
cluster_root πŸ”’
create_and_migrate πŸ”’
first_started πŸ”’
Tries each probed-free port in order. A port refused by probe costs no server start; one that attempt fails on (taken since the probe, or a server that cannot start at all) moves on to the next.
log_tail πŸ”’
parse_major πŸ”’
port_is_free πŸ”’
ram_disk_has_room πŸ”’
run πŸ”’
Children run in their own group so a terminal Ctrl-C cannot kill them half-way and be mistaken for a failure; xtask’s own termination handling decides instead.
server_major πŸ”’
server_options πŸ”’
The socket directory lives inside PGDATA: a shared /tmp is not writable the same way in every container, and its lock file is where that first shows up.
start
initdb, start, create the database, migrate it.
start_on_free_port πŸ”’