microsoft / microsoft/aspire

Aspire Postgres postgres.AddDatabase("mydatabase") generates FATAL log entry using .WithCreationScript

Open
#11,980 0 comments 1 reaction 0 assignees View on GitHub
area-integrations
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

When using Aspire 9.5 .Net 10 PostgreSQL 18 to create a new database with an owner role using WithCreationScript a FATAL error is logged when the Postgres container starts saying "FATAL: database "mydatabase" does not exist".

Maybe postgres.AddDatabase("mydatabase") should be overload to take no database name if using .WithCreationScript as this can be used to create a new database with PgSQL statements (see below) as it is very normal to need to create a new database with a different owner user/role than the default Postgres user/role.

Everything still works but a FATAL error is being logged and could be a problem. If above fix it not possible, how about making this a WARNING log message.

var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddPostgres("postgres")
.WithImageTag("18.0-alpine")
.WithPgAdmin(pgAdmin => pgAdmin.WithImageTag("latest"));

var postgresdb = postgres.AddDatabase("mydatabase")
.WithCreationScript("BEGIN; CREATE ROLE my_user WITH LOGIN PASSWORD 'my_password'; COMMIT; CREATE DATABASE mydatabase WITH OWNER my_user;");

var cache = builder.AddRedis("cache");

**Postgres container log output**
2025-10-13 10:12:56.577 UTC [1] LOG: starting PostgreSQL 18.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 14.2.0) 14.2.0, 64-bit
2025-10-13 10:12:56.578 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2025-10-13 10:12:56.578 UTC [1] LOG: listening on IPv6 address "::", port 5432
2025-10-13 10:12:56.590 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-10-13 10:12:56.607 UTC [62] LOG: database system was shut down at 2025-10-13 10:12:56 UTC
**2025-10-13 10:12:56.611 UTC [65] FATAL: the database system is starting up
2025-10-13 10:12:56.611 UTC [63] FATAL: the database system is starting up
2025-10-13 10:12:56.611 UTC [64] FATAL: the database system is starting up**
2025-10-13 10:12:56.615 UTC [1] LOG: database system is ready to accept connections
**2025-10-13 10:12:58.670 UTC [71] **FATAL: database "mydatabase" does not exist****
Creating database 'mydatabase'
Database 'mydatabase' created successfully

### Expected Behavior

Not create a FATAL error in the log file.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version info

10.0.0-rc.1.25451.107

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.