Repository navigation
feat(postgres): Support postgres:18, fixes #7661 - #7662
Conversation
006cdc3 to
99b8a5b
Compare
|
postgres:18 is out now, but doesn't work. I think it's because the data directory has a data symlink in it, broken. |
|
Download the artifacts for this pull request:
See Testing a PR. |
|
Requires rebase after #7665 goes in. |
rfay
left a comment
There was a problem hiding this comment.
Thank you for sorting this out!
| templateVars.DBMountDir = "/var/lib/postgresql/data" | ||
| } else { | ||
| // Postgres 18+ changed the default mount point | ||
| // See https://github.com/docker-library/postgres/pull/1259 |
There was a problem hiding this comment.
This is great, thank you for figuring it out. Is it possible that we could use PGDATA instead of this? check? If not, the logic might be easier to look at if reversed, but I'm sure you already thought about that. (dbmountdir=/var/lib/postgresql; if ver < 18 dbmountdir=/var/lib/postgresql/data)
There was a problem hiding this comment.
I don't think PGDATA can change anything here. The change is in the volume (and we can't change this):
VOLUME /var/lib/postgresqlPreviously, it was:
VOLUME /var/lib/postgresql/datathe logic might be easier to look at if reversed
Yes, but in this case, we need to convert app.Database.Version to a number.
That leads to using a magic number in the code.
It would be shorter, but using constants is better.
121f520 to
4f954b4
Compare
|
Rebased |
PostgreSQL 18 changed the directory structure from `/var/lib/postgresql/data` to `/var/lib/postgresql/[version]/docker`, requiring updates to the database type detection logic. ## Changes - Refactored `GetExistingDBType()` to be more readable and maintainable - Extracted database version detection logic to `getDBVersionFromVolume()` - Added support for PostgreSQL 18+ directory structure detection - Maintains backward compatibility with pre-18 PostgreSQL versions - Added comprehensive unit tests for all database scenarios ## Testing - Tests cover MySQL/MariaDB, PostgreSQL 17 (pre-18), PostgreSQL 18+ (new structure) - Shell script logic is directly tested using Docker containers - All existing tests continue to pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Generalizes PostgreSQL 18+ directory path handling across the DDEV codebase by creating a GetPostgresDataDir() helper function that returns the correct data directory path based on PostgreSQL version. Changes: - Add GetPostgresDataDir() helper in db.go that returns: - /var/lib/postgresql/data for PostgreSQL ≤17 - /var/lib/postgresql for PostgreSQL 18+ - Update snapshot restore to use GetPostgresDataDir() instead of hardcoded paths - Update PostgreSQL volume chown operation to use GetPostgresDataDir() - Update default working directory mapping to use GetPostgresDataDir() - Simplify Docker Compose template generation to use GetPostgresDataDir() - Add comprehensive tests for GetPostgresDataDir() helper function This ensures consistent PostgreSQL directory handling across database type detection, snapshot/restore operations, volume management, and container configuration while maintaining full backward compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…PostgreSQL 18 compatibility
Fixes the final hardcoded PostgreSQL paths that were preventing PostgreSQL 18
compatibility in snapshot restore operations:
- Update PostgreSQL Dockerfile template to use {{ .DBMountDir }} template variable
instead of hardcoded /var/lib/postgresql path
- Fix recovery.conf path in snapshot restore command to use dynamic postgresDataDir
instead of hardcoded /var/lib/postgresql/recovery.conf
This resolves the "cat: /var/lib/postgresql/recovery.conf: No such file or directory"
error that occurred during PostgreSQL 18 snapshot restore operations.
All PostgreSQL paths now correctly use the GetPostgresDataDir() helper function
across database detection, snapshot/restore, volume management, container configuration,
and Dockerfile templates, ensuring full PostgreSQL 18+ compatibility.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
…ixes snapshot/restore compatibility PostgreSQL 18 changed the default mount point from /var/lib/postgresql/data to /var/lib/postgresql with actual database files stored in /var/lib/postgresql/18/docker/. This change: - Adds GetPostgresDataDir() for mount point logic (compatible with both ≤17 and 18+) - Adds GetPostgresDataPath() for actual data file location (version-specific for 18+) - Updates snapshot creation to preserve PostgreSQL 18+ directory structure using mkdir/cp - Fixes snapshot restore to use correct paths and recovery configuration - Updates template system to use DBDataPath variable for PostgreSQL data file paths - Adds comprehensive tests for both helper functions and PostgreSQL 18+ compatibility - Ensures recovery.signal is placed in correct location for PostgreSQL 18+ - Adds restore_command parameter for PostgreSQL 18+ archive recovery compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
| // PostgreSQL 18+: backup from actual data path and create tar preserving directory structure | ||
| // Create the full directory structure (e.g., 18/docker/) that matches the container layout | ||
| versionDir := filepath.Base(filepath.Dir(postgresDataPath)) // Extract "18" from "/var/lib/postgresql/18/docker" | ||
| c = fmt.Sprintf("cd %s && rm -rf /var/tmp/pgbackup && pg_basebackup -c fast -D /var/tmp/pgbackup 2>/tmp/snapshot_%s.log && mkdir -p /var/tmp/pgstructure/%s/docker && cp -a /var/tmp/pgbackup/* /var/tmp/pgstructure/%s/docker/ && tar -czf %s -C /var/tmp/pgstructure/ .", postgresDataPath, path.Base(targetFile), versionDir, versionDir, targetFile) |
There was a problem hiding this comment.
Impossible to understand or debug, maybe we can figure out how to improve this one and its friends.
| targetConfName = path.Join(nodeps.PostgresConfigDir, "recovery.conf") | ||
| } | ||
| restoreCmd = fmt.Sprintf(`bash -c 'chmod 700 /var/lib/postgresql/data && mkdir -p %s && rm -rf /var/lib/postgresql/data/* && tar -C /var/lib/postgresql/data -zxf /mnt/snapshots/%s && touch /var/lib/postgresql/data/recovery.signal && cat /var/lib/postgresql/recovery.conf >>%s && postgres -c config_file=%s/postgresql.conf -c hba_file=%s/pg_hba.conf'`, confdDir, snapshotFile, targetConfName, nodeps.PostgresConfigDir, nodeps.PostgresConfigDir) | ||
| restoreCmd = fmt.Sprintf(`bash -c 'chmod 700 %s && mkdir -p %s && rm -rf %s/* && tar -C %s -zxf /mnt/snapshots/%s && chmod 700 %s && touch %s/recovery.signal && postgres -c config_file=%s/postgresql.conf -c hba_file=%s/pg_hba.conf -c restore_command=true'`, postgresDataDir, confdDir, postgresDataDir, postgresDataDir, snapshotFile, postgresDataPath, postgresDataPath, nodeps.PostgresConfigDir, nodeps.PostgresConfigDir) |
There was a problem hiding this comment.
Also impossible to understand or debug. Maybe can be simplified.
|
I guess there's a regression on snapshots on postgres:10, https://github.com/ddev/ddev/actions/runs/18046729502/job/51359198731#step:17:8312 |
|
Last commit doesn't work at all, but suggests the path. Just bad Dockerfile layer building, invalid. |
How This PR Solves The Issue: Adjusts Go-side Dockerfile template generation to resolve restore_command path for Postgres 10-18 and ensures target directory exists before writing recovery.conf. Manual Testing Instructions: Rebuild db image then run ddev start and snapshot restore against Postgres 10 and Postgres 18 projects. Automated Testing Overview: Not run; golangci-lint/go test blocked in sandbox. Release/Deployment Notes: None. Co-authored-by: ChatGPT <[email protected]>
|
The problem with test failures of lima and colima here is they don't allow mounts on anything but the home directory by default, and the test is assuming a mount from elsewhere. Fiddling with it. |
stasadev
left a comment
There was a problem hiding this comment.
Looks good to me, I have a small suggestion to make it simpler to check the PG_VERSION.
| mkdir -p %[2]s | ||
| echo "restore_command = 'true'" >>%[1]s |
There was a problem hiding this comment.
Nice, I didn't know about this syntax.
Co-authored-by: Stanislav Zhuk <[email protected]>
|
I manually tested (WSL2), seems fine. |
The Issue
Postgres:18 is out today, https://www.postgresql.org/about/news/postgresql-18-released-3142/
It breaks our builds because we get the wrong client (TestWebserverPostgresDBClient )
https://github.com/ddev/ddev/actions/runs/18019471809/job/51272939982#step:17:8534
How This PR Solves The Issue
It's not quite ready yet, but should work when there's a docker image.
Manual Testing Instructions
Automated Testing Overview
Release/Deployment Notes