-
Notifications
You must be signed in to change notification settings - Fork 715
Description
Is there an existing issue for this?
- 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