feat(postgres): support PostgreSQL 19

PostgreSQL 19 was released on 19.11.2026, and TREK refused it at boot as
newer than the 14 to 18 it supported (discussion #3214). It now supports 14
to 19.

The image installs the version 19 client tools from PGDG's main component,
since the per-major component can trail a new release; a client handles
every server up to its own major, so pg_dump, pg_restore and psql 19 back up
and restore every supported server. The tools are looked for in the 19
directory first. Installs that pointed TREK_DB_PG_BIN_DIR at the old
/usr/lib/postgresql/18/bin keep working: the image keeps that path as a link
to the 19 tools. CI runs the Postgres lane on 14 and 19 instead of 14 and
18, so the job count stays the same, and the Docker job boots on 19. The
list of server functions and roles that reach the host was checked against
the release notes; PostgreSQL 19 adds none. The compose example stays on 18,
because an existing database stays on the major it was created with.
This commit is contained in:
Maurice
2026-11-26 23:36:36 +01:00
parent a9fd443b63
commit 39d2196a14
20 changed files with 102 additions and 65 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ DEMO_MODE=false # Demo mode: resets data hourly
# BACKUP_UPLOAD_LIMIT_MB=500 # Max size (MB) of a backup archive you can upload when restoring. Raise it if your backup exceeds 500 MB. If you sit behind a reverse proxy, raise its upload limit too (e.g. nginx client_max_body_size).
# TREK_DB_URL=postgres://trek:password@db:5432/trek # Run on a Postgres database instead of the SQLite file in data/. TREK creates its schema in an empty database and refuses one holding tables it did not create. sslmode=disable, require, verify-ca or verify-full (the last three always verify the certificate; sslrootcert= names the CA file). For a server that asks for a client certificate, sslcert= and sslkey= name the certificate and its key file, both together and only with a verifying sslmode. A Unix socket: postgresql://trek@localhost/trek?host=/var/run/postgresql (a host= or port= parameter takes the place of the URL's own, as in libpq). Cannot be combined with TREK_DB_FILE, TREK_DB_JOURNAL_MODE or TREK_DB_SYNCHRONOUS.
# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/bin # The directory holding pg_dump, pg_restore and psql, which back up and restore a Postgres database. Unset, TREK looks in /usr/lib/postgresql/<18..14>/bin, newest first, then /usr/local/bin and /usr/bin (the Docker image installs the version 18 tools, which work with every supported server; tools older than the server are refused). Unused on SQLite.
# TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/19/bin # The directory holding pg_dump, pg_restore and psql, which back up and restore a Postgres database. Unset, TREK looks in /usr/lib/postgresql/<19..14>/bin, newest first, then /usr/local/bin and /usr/bin (the Docker image installs the version 19 tools, which work with every supported server; tools older than the server are refused). Unused on SQLite.
# TREK_DB_POOL_MAX=10 # Most connections TREK opens to the Postgres database (1 to 100). Unused on SQLite. (default: 10)
# TREK_DB_JOURNAL_MODE=WAL # SQLite journal mode (DELETE, TRUNCATE, PERSIST, MEMORY, WAL, OFF). WAL is fastest and the right choice on local disk. Set DELETE if the data directory lives on network storage (Azure App Service, an SMB/NFS volume on a NAS) — WAL coordinates writers through a shared-memory file that those filesystems do not implement reliably. The mode is stored inside the database file, so it survives a restart; changing this applies on the next boot.
# TREK_DB_PRE_MIGRATE_SNAPSHOT=true # Copy the database to data/pre-migrate-<schema>-<time>.db (a .pgdump made with pg_dump on Postgres) before a startup migrates it, so the previous image can run on the copy again. A copy that cannot be written stops the startup; false migrates without one.
+3 -3
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -14,12 +14,13 @@ export type PgTool = 'pg_dump' | 'pg_restore' | 'psql';
/**
* Where the client tools are looked for when `TREK_DB_PG_BIN_DIR` is unset:
* Debian's versioned directories newest first (the Docker image installs 18),
* Debian's versioned directories newest first (the Docker image installs 19),
* then the usual prefixes. Newest first because a client dumps and restores
* every server up to its own major version and refuses a newer one. Never
* PATH: a binary is run by its absolute path.
*/
const DEFAULT_BIN_DIRS = [
'/usr/lib/postgresql/19/bin',
'/usr/lib/postgresql/18/bin',
'/usr/lib/postgresql/17/bin',
'/usr/lib/postgresql/16/bin',
@@ -38,7 +38,7 @@ import path from 'node:path';
*
* Which names are functions of `pg_catalog` is read from
* `assets/postgres/catalog-functions.txt`: every function name of every
* supported major (14 to 18; the boot refuses any other server). The Postgres
* supported major (14 to 19; the boot refuses any other server). The Postgres
* lane compares it with `pg_proc` on the server it runs on and fails on a
* name missing there (PGPLUG-021), so a new major cannot add a function a
* plugin may call without someone deciding whether it belongs here.
@@ -8,8 +8,8 @@ import { run } from './pg-process';
* psql then refuses every meta-command until the matching `\unrestrict`.
*
* RESTRICT_SINCE holds, per major, the first minor that carries the fix, for
* every major TREK supports (14 to 18; 18 has it from 18.0). Every major after
* the last one listed has it from its first release.
* the majors TREK supports from 14 to 18 (18 has it from 18.0). Every major after
* the last one listed (19 and later) has it from its first release.
*/
const RESTRICT_SINCE: Readonly<Partial<Record<number, number>>> = { 14: 19, 15: 14, 16: 10, 17: 6, 18: 0 };
const LAST_MAJOR_WITHOUT_IT = Math.max(...Object.keys(RESTRICT_SINCE).map(Number));
@@ -46,6 +46,6 @@ export async function refuseToolsWithoutRestrict(binDir: string | undefined): Pr
if (stale < 0) return;
throw new Error(
`${tools[stale]} is too old to restore safely (${versions[stale].trim()}): it must be at least ${minimumVersionsText()} ` +
'(the Docker image has 18). Upgrade the PostgreSQL client tools or point TREK_DB_PG_BIN_DIR at newer ones.',
'(the Docker image has 19). Upgrade the PostgreSQL client tools or point TREK_DB_PG_BIN_DIR at newer ones.',
);
}
@@ -8,7 +8,7 @@ import { REFUSAL } from '../../legacy-baseline';
*/
/** The PostgreSQL majors TREK supports and CI runs: the oldest and the newest. */
const SUPPORTED_SERVER_MAJORS = { oldest: 14, newest: 18 } as const;
const SUPPORTED_SERVER_MAJORS = { oldest: 14, newest: 19 } as const;
/**
* The `pg_catalog` functions that read, list or write files on the database
+1 -1
View File
@@ -28,7 +28,7 @@
* (tests/unit/nest-rpc/rpc-row-id-params.test.ts) for plugin RPC params.
*
* It boots the app on the real database module, so it runs in the SQLite
* suite and in the Postgres lane on 14 and 18.
* suite and in the Postgres lane on 14 and 19.
*/
import { buildApp } from '../../src/bootstrap';
import { Addons } from '../../src/db/entities/Addons.entity';
@@ -59,6 +59,21 @@ describe('pg-tools', () => {
expect(resolvePgTool('psql', bin)).toBeNull();
});
it('PGTOOLS-024: without a configured directory, the newest supported major is looked in first, then the older ones', () => {
const access = vi.spyOn(fs, 'accessSync').mockImplementation(() => {
throw new Error('not installed');
});
try {
expect(resolvePgTool('pg_dump', undefined)).toBeNull();
const looked = access.mock.calls.map(([candidate]) => String(candidate));
expect(looked.slice(0, 6)).toEqual(
[19, 18, 17, 16, 15, 14].map((major) => path.join(`/usr/lib/postgresql/${major}/bin`, 'pg_dump')),
);
} finally {
access.mockRestore();
}
});
it('PGTOOLS-002: the connection goes in the libpq environment, the password decoded and never an argument', () => {
expect(pgConnectionEnv(URL_WITH_SECRET)).toEqual({
PGHOST: 'db.example',
@@ -239,17 +239,17 @@ describe('bootstrapPostgresSchema', () => {
it.each([
{ id: 'PGBOOT-020a', version: '130016', major: 13 },
{ id: 'PGBOOT-020b', version: '190000', major: 19 },
])('$id: a server outside 14 to 18 is refused before anything is read or written', async ({ version, major }) => {
{ id: 'PGBOOT-020b', version: '200000', major: 20 },
])('$id: a server outside 14 to 19 is refused before anything is read or written', async ({ version, major }) => {
const { orm, db } = fakeOrm({ executed: [], pending: [M1, M2], tables: [], server: { version } });
await expect(bootstrapPostgresSchema(orm, deps())).rejects.toThrow(
`Refusing to boot: the Postgres server is version ${major}; TREK supports PostgreSQL 14 to 18.`,
`Refusing to boot: the Postgres server is version ${major}; TREK supports PostgreSQL 14 to 19.`,
);
expect(db.sql).toEqual([]);
expect(db.ensureTable).not.toHaveBeenCalled();
});
it.each(['140019', '180001'])(
it.each(['140019', '190001'])(
'PGBOOT-021: the oldest and the newest supported servers boot (%s)',
async (version) => {
const { orm, db } = fakeOrm({ executed: [], pending: [M1, M2], tables: [], server: { version } });
@@ -110,3 +110,14 @@ describe('entrypoint script', () => {
expect(source).not.toMatch(/^\s*exec gosu/m);
});
});
// Earlier images carried the version 18 client tools, and the old .env.example
// suggested TREK_DB_PG_BIN_DIR=/usr/lib/postgresql/18/bin. resolvePgTool looks
// only in a configured directory, so without the link such an install loses its
// backups and the mandatory pre-migrate snapshot after updating the image.
describe('postgres client tools in the image', () => {
it('installs the version 19 client and keeps the version 18 directory as a link to it', () => {
expect(dockerfile).toMatch(/\bpostgresql-client-19\b/);
expect(dockerfile).toContain('ln -s /usr/lib/postgresql/19/bin /usr/lib/postgresql/18/bin');
});
});