PostgresBuilderExtensions Methods
Hosting.IDistributedApplicationBuilder. AddDatabase(IResourceBuilder<PostgresServerResource>, string, string?)Section titled AddDatabase(IResourceBuilder<PostgresServerResource>, string, string?)extensionIResourceBuilder<PostgresDatabaseResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresDatabaseResource> AddDatabase( this IResourceBuilder<PostgresServerResource> builder, string name, string? databaseName = null) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The PostgreSQL server resource builder.namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.databaseNamestring?optionalThe name of the database. If not provided, this defaults to the same value as name.Returns
IResourceBuilder<PostgresDatabaseResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Postgres database is available.
Note that calling PostgresBuilderExtensions.AddDatabase will result in the database being created on the Postgres server when the server becomes ready. The database creation happens automatically as part of the resource lifecycle.
AddPostgres(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?)Section titled AddPostgres(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> AddPostgres( this IDistributedApplicationBuilder builder, string name, IResourceBuilder<ParameterResource>? userName = null, IResourceBuilder<ParameterResource>? password = null, int? port = null) { // ... }}Parameters
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.userNameIResourceBuilder<ParameterResource>optionalThe parameter used to provide the user name for the PostgreSQL resource. If null a default value will be used.passwordIResourceBuilder<ParameterResource>optionalThe parameter used to provide the administrator password for the PostgreSQL resource. If null a random password will be generated.portint?optionalThe host port used when launching the container. If null a random port will be assigned.Returns
IResourceBuilder<PostgresServerResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
This resource includes built-in health checks. When this resource is referenced as a dependency using the ResourceBuilderExtensions.WaitFor extension method then the dependent resource will wait until the Postgres resource is able to service requests.
WithCreationScript(IResourceBuilder<PostgresDatabaseResource>, string)Section titled WithCreationScript(IResourceBuilder<PostgresDatabaseResource>, string)extensionIResourceBuilder<PostgresDatabaseResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresDatabaseResource> WithCreationScript( this IResourceBuilder<PostgresDatabaseResource> builder, string script) { // ... }}Parameters
builderIResourceBuilder<PostgresDatabaseResource>The builder for the PostgresDatabaseResource.scriptstringThe SQL script used to create the database.Returns
IResourceBuilder<PostgresDatabaseResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
CREATE DATABASE "<QUOTED_DATABASE_NAME>"WithDataBindMount(IResourceBuilder<PostgresServerResource>, string, bool)Section titled WithDataBindMount(IResourceBuilder<PostgresServerResource>, string, bool)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithDataBindMount( this IResourceBuilder<PostgresServerResource> builder, string source, bool isReadOnly = false) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.sourcestringThe source directory on the host to mount into the container.isReadOnlybooloptionalA flag that indicates if this is a read-only mount.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.Remarks
The data directory location varies by PostgreSQL version:
- PostgreSQL 17 and earlier:
/var/lib/postgresql/data - PostgreSQL 18 and later:
/var/lib/postgresql
This method automatically selects the correct path based on the configured container image tag.
WithDataVolume(IResourceBuilder<PostgresServerResource>, string?, bool)Section titled WithDataVolume(IResourceBuilder<PostgresServerResource>, string?, bool)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithDataVolume( this IResourceBuilder<PostgresServerResource> builder, string? name = null, bool isReadOnly = false) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.isReadOnlybooloptionalA flag that indicates if this is a read-only volume.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.Remarks
The data directory location varies by PostgreSQL version:
- PostgreSQL 17 and earlier:
/var/lib/postgresql/data - PostgreSQL 18 and later:
/var/lib/postgresql
This method automatically selects the correct path based on the configured container image tag.
WithHostPort(IResourceBuilder<PgAdminContainerResource>, int?)Section titled WithHostPort(IResourceBuilder<PgAdminContainerResource>, int?)extensionIResourceBuilder<PgAdminContainerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PgAdminContainerResource> WithHostPort( this IResourceBuilder<PgAdminContainerResource> builder, int? port) { // ... }}Parameters
builderIResourceBuilder<PgAdminContainerResource>The resource builder for PGAdmin.portint?The port to bind on the host. If null is used random port will be assigned.Returns
IResourceBuilder<PgAdminContainerResource>The resource builder for PGAdmin.WithHostPort(IResourceBuilder<PgWebContainerResource>, int?)Section titled WithHostPort(IResourceBuilder<PgWebContainerResource>, int?)extensionIResourceBuilder<PgWebContainerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PgWebContainerResource> WithHostPort( this IResourceBuilder<PgWebContainerResource> builder, int? port) { // ... }}Parameters
builderIResourceBuilder<PgWebContainerResource>The resource builder for pgweb.portint?The port to bind on the host. If null is used random port will be assigned.Returns
IResourceBuilder<PgWebContainerResource>The resource builder for pgweb.WithHostPort(IResourceBuilder<PostgresServerResource>, int?)Section titled WithHostPort(IResourceBuilder<PostgresServerResource>, int?)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithHostPort( this IResourceBuilder<PostgresServerResource> builder, int? port) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.portint?The port to bind on the host. If null is used random port will be assigned.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.WithInitBindMount(IResourceBuilder<PostgresServerResource>, string, bool)Section titled WithInitBindMount(IResourceBuilder<PostgresServerResource>, string, bool)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithInitBindMount( this IResourceBuilder<PostgresServerResource> builder, string source, bool isReadOnly = true) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.sourcestringThe source directory on the host to mount into the container.isReadOnlybooloptionalA flag that indicates if this is a read-only mount.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.Remarks
PostgresBuilderExtensions.WithInitFiles instead.WithInitFiles(IResourceBuilder<PostgresServerResource>, string)Section titled WithInitFiles(IResourceBuilder<PostgresServerResource>, string)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithInitFiles( this IResourceBuilder<PostgresServerResource> builder, string source) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.sourcestringThe source directory or files on the host to copy into the container.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.WithPassword(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)Section titled WithPassword(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithPassword( this IResourceBuilder<PostgresServerResource> builder, IResourceBuilder<ParameterResource> password) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.passwordIResourceBuilder<ParameterResource>The parameter used to provide the password for the PostgreSQL resource.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.WithPgAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PgAdminContainerResource>>, string?)Section titled WithPgAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PgAdminContainerResource>>, string?)extensionIResourceBuilder<T>public static class PostgresBuilderExtensions{ public static IResourceBuilder<T> WithPgAdmin<T>( this IResourceBuilder<T> builder, Action<IResourceBuilder<PgAdminContainerResource>>? configureContainer = null, string? containerName = null) { // ... }}Parameters
builderIResourceBuilder<T>The PostgreSQL server resource builder.configureContainerAction<IResourceBuilder<PgAdminContainerResource>>optionalCallback to configure PgAdmin container resource.containerNamestring?optionalThe name of the container (Optional).Returns
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
WithPgWeb(IResourceBuilder<PostgresServerResource>, Action<IResourceBuilder<PgWebContainerResource>>, string?)Section titled WithPgWeb(IResourceBuilder<PostgresServerResource>, Action<IResourceBuilder<PgWebContainerResource>>, string?)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithPgWeb( this IResourceBuilder<PostgresServerResource> builder, Action<IResourceBuilder<PgWebContainerResource>>? configureContainer = null, string? containerName = null) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The Postgres server resource builder.configureContainerAction<IResourceBuilder<PgWebContainerResource>>optionalConfiguration callback for pgweb container resource.containerNamestring?optionalThe name of the container (Optional).Returns
IResourceBuilder<PostgresServerResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
WithPostgresMcp(IResourceBuilder<PostgresDatabaseResource>, Action<IResourceBuilder<PostgresMcpContainerResource>>, string?)Section titled WithPostgresMcp(IResourceBuilder<PostgresDatabaseResource>, Action<IResourceBuilder<PostgresMcpContainerResource>>, string?)extensionIResourceBuilder<PostgresDatabaseResource>builder. public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresDatabaseResource> WithPostgresMcp( this IResourceBuilder<PostgresDatabaseResource> builder, Action<IResourceBuilder<PostgresMcpContainerResource>>? configureContainer = null, string? containerName = null) { // ... }}Parameters
builderIResourceBuilder<PostgresDatabaseResource>The Postgres database resource builder.configureContainerAction<IResourceBuilder<PostgresMcpContainerResource>>optionalConfiguration callback for the Postgres MCP container resource.containerNamestring?optionalThe name of the container (optional).Returns
IResourceBuilder<PostgresDatabaseResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
WithUserName(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)Section titled WithUserName(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<PostgresServerResource>public static class PostgresBuilderExtensions{ public static IResourceBuilder<PostgresServerResource> WithUserName( this IResourceBuilder<PostgresServerResource> builder, IResourceBuilder<ParameterResource> userName) { // ... }}Parameters
builderIResourceBuilder<PostgresServerResource>The resource builder.userNameIResourceBuilder<ParameterResource>The parameter used to provide the user name for the PostgreSQL resource.Returns
IResourceBuilder<PostgresServerResource>The ApplicationModel.IResourceBuilder`1.