Skip to content

Add Support for Postgres v18 and DataVolume #11710

@maperz

Description

@maperz

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Last week, version 18 of Postgres was released, and with it, exciting new features.
When trying to integrate the specific new version with Aspire (e.g. via .WithImageTag("18.0-alpine"))
Issues occur when trying to persist the database via WithDataVolume.

The specific error is the following:

Failed to start Container {"Container": "/app-db-a5f7ed39", "Reconciliation": 9, "ContainerID": "6abfc32df9b3", "ContainerName": "app-db-a5f7ed39", "error": "status of container 'app-db-a5f7ed39' is 'created' (was expecting 'running'), error: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/docker/volumes/apphost-a5f7ed3973-app-db-data/_data" to rootfs at "/var/lib/postgresql/data": change mount propagation through procfd: open o_path procfd: open /var/lib/docker/overlay2/565bae96a29896f38a93152422eb700cb397ae3e46172720b7ed0b37fc8e3ea7/merged/var/lib/postgresql/data: no such file or directory: unknown\ndocker command 'StartContainers' returned with non-zero exit code 1\nnot all requested objects were returned\nonly 0 out of 1 containers were successfully started"}

AFAIK this happens because the new Postgres folder structure and storing database data under a version specific /var/lib/postgresql/18/docker (notice the new /18/docker part of the path). (See docker-library/postgres#1259, https://hub.docker.com/_/postgres/#pgdata)

A current workaround for now is simply extending the resource builder with a version-specific volume mapping:

public static class Postgres18BuilderExtensions
{
    public static IResourceBuilder<PostgresServerResource> WithDataVolumeForV18(
        this IResourceBuilder<PostgresServerResource> builder, string? name = null, bool isReadOnly = false)
    {
        ArgumentNullException.ThrowIfNull(builder);

        return builder.WithVolume(name ?? VolumeNameGenerator.Generate(builder, "data"),
            "/var/lib/postgresql/18/docker", isReadOnly);
    }
}

Moving on, it will be required to either override the default WithDataVolume with a specific version or let Aspire infer the version from the image tag used.

Describe the solution you'd like

Postgres 18+ should support .WithDataVolume() as previous versions did.

The correct data volume shall be used with Postgres versions 18+.
With the new version, the path should be "/var/lib/postgresql/18/docker".

Additional context

No response

Metadata

Metadata

Assignees

Labels

area-integrationsIssues pertaining to Aspire Integrations packagespostgresIssues related to Postgres integrations

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions