# PostgresBuilderExtensions

- Kind: `class`
- Package: [Aspire.Hosting.PostgreSQL](/reference/api/csharp/aspire.hosting.postgresql.md)
- Version: `13.4.0`
- Namespace: `Aspire.Hosting`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.PostgreSQL/PostgresBuilderExtensions.cs)

Provides extension methods for adding PostgreSQL resources to an `Hosting.IDistributedApplicationBuilder`.

## Definition

```csharp
namespace Aspire.Hosting;

public static class PostgresBuilderExtensions
{
    // ...
}
```

## Methods

- [AddDatabase(IResourceBuilder<PostgresServerResource>, string, string?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#adddatabase-iresourcebuilder-postgresserverresource-string-string) : `IResourceBuilder<PostgresDatabaseResource>` `extension` `ats export` -- Adds a PostgreSQL database to the application model.
- [AddPostgres(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, IResourceBuilder<ParameterResource>, int?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#addpostgres-idistributedapplicationbuilder-string-iresourcebuilder-parameterresource-iresourcebuilder-parameterresource-int) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Adds a PostgreSQL resource to the application model. A container is used for local development.
- [WithCreationScript(IResourceBuilder<PostgresDatabaseResource>, string)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withcreationscript-iresourcebuilder-postgresdatabaseresource-string) : `IResourceBuilder<PostgresDatabaseResource>` `extension` `ats export` -- Defines the SQL script used to create the database.
- [WithDataBindMount(IResourceBuilder<PostgresServerResource>, string, bool)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withdatabindmount-iresourcebuilder-postgresserverresource-string-bool) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Adds a bind mount for the data folder to a PostgreSQL container resource.
- [WithDataVolume(IResourceBuilder<PostgresServerResource>, string?, bool)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withdatavolume-iresourcebuilder-postgresserverresource-string-bool) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Adds a named volume for the data folder to a PostgreSQL container resource.
- [WithHostPort(IResourceBuilder<PgAdminContainerResource>, int?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withhostport-iresourcebuilder-pgadmincontainerresource-int) : `IResourceBuilder<PgAdminContainerResource>` `extension` `ats export` -- Configures the host port that the PGAdmin resource is exposed on instead of using randomly assigned port.
- [WithHostPort(IResourceBuilder<PgWebContainerResource>, int?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withhostport-iresourcebuilder-pgwebcontainerresource-int) : `IResourceBuilder<PgWebContainerResource>` `extension` `ats export` -- Configures the host port that the pgweb resource is exposed on instead of using randomly assigned port.
- [WithHostPort(IResourceBuilder<PostgresServerResource>, int?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withhostport-iresourcebuilder-postgresserverresource-int) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Configures the host port that the PostgreSQL resource is exposed on instead of using randomly assigned port.
- [WithInitBindMount(IResourceBuilder<PostgresServerResource>, string, bool)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withinitbindmount-iresourcebuilder-postgresserverresource-string-bool) : `IResourceBuilder<PostgresServerResource>` `extension` `obsolete` `ats ignored` -- Adds a bind mount for the init folder to a PostgreSQL container resource.
- [WithInitFiles(IResourceBuilder<PostgresServerResource>, string)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withinitfiles-iresourcebuilder-postgresserverresource-string) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Copies init files to a PostgreSQL container resource.
- [WithPassword(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withpassword-iresourcebuilder-postgresserverresource-iresourcebuilder-parameterresource) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Configures the password that the PostgreSQL resource is used.
- [WithPgAdmin(IResourceBuilder<T>, Action<IResourceBuilder<PgAdminContainerResource>>, string?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withpgadmin-iresourcebuilder-t-action-iresourcebuilder-pgadmincontainerresource-string) : `IResourceBuilder<T>` `extension` `ats export` -- Adds a pgAdmin 4 administration and development platform for PostgreSQL to the application model.
- [WithPgWeb(IResourceBuilder<PostgresServerResource>, Action<IResourceBuilder<PgWebContainerResource>>, string?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withpgweb-iresourcebuilder-postgresserverresource-action-iresourcebuilder-pgwebcontainerresource-string) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Adds an administration and development platform for PostgreSQL to the application model using pgweb.
- [WithPostgresMcp(IResourceBuilder<PostgresDatabaseResource>, Action<IResourceBuilder<PostgresMcpContainerResource>>, string?)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withpostgresmcp-iresourcebuilder-postgresdatabaseresource-action-iresourcebuilder-postgresmcpcontainerresource-string) : `IResourceBuilder<PostgresDatabaseResource>` `extension` `experimental` `ats export` -- Adds a Postgres MCP server container and configures it to connect to the database represented by `builder`.
- [WithUserName(IResourceBuilder<PostgresServerResource>, IResourceBuilder<ParameterResource>)](/reference/api/csharp/aspire.hosting.postgresql/postgresbuilderextensions/methods.md#withusername-iresourcebuilder-postgresserverresource-iresourcebuilder-parameterresource) : `IResourceBuilder<PostgresServerResource>` `extension` `ats export` -- Configures the user name that the PostgreSQL resource is used.
