# PostgresServerResource

- Module: [Aspire.Hosting.PostgreSQL](/reference/api/typescript/aspire.hosting.postgresql.md)
- Version: `13.4.0`
- Kind: `handle`
- Source: [GitHub](https://github.com/microsoft/aspire)

A resource that represents a PostgreSQL container.

## Definition

```typescript
interface PostgresServerResource
  extends IComputeResource,
    IExpressionValue,
    IManifestExpressionProvider,
    IResource,
    IResourceWithArgs,
    IResourceWithConnectionString,
    IResourceWithEndpoints,
    IResourceWithEnvironment,
    IResourceWithProbes,
    IResourceWithWaitSupport,
    IValueProvider,
    IValueWithReferences {
  readonly connectionStringExpression: ReferenceExpression;
  readonly databases: Dict<string,string>;
  readonly host: EndpointReferenceExpression;
  readonly jdbcConnectionString: ReferenceExpression;
  passwordParameter: ParameterResource;
  readonly port: EndpointReferenceExpression;
  readonly primaryEndpoint: EndpointReference;
  readonly uriExpression: ReferenceExpression;
  userNameParameter: ParameterResource;
  readonly userNameReference: ReferenceExpression;
  addDatabase(
      name: string,
      databaseName?: string): PostgresDatabaseResource;
  withDataBindMount(
      source: string,
      isReadOnly?: boolean): PostgresServerResource;
  withDataVolume(
      name?: string,
      isReadOnly?: boolean): PostgresServerResource;
  withHostPort(port: number): PostgresServerResource;
  withInitFiles(source: string): PostgresServerResource;
  withPassword(password: ParameterResource): PostgresServerResource;
  withPgAdmin(configureContainer?: (obj: PgAdminContainerResource) => Promise<void>, containerName?: string): PostgresServerResource;
  withPgWeb(configureContainer?: (obj: PgWebContainerResource) => Promise<void>, containerName?: string): PostgresServerResource;
  withUserName(userName: ParameterResource): PostgresServerResource;
}
```

## Properties

- `connectionStringExpression`: `ReferenceExpression` `get` -- Gets the connection string expression for the PostgreSQL server.
- `databases`: `Dict<string,string>` `get` -- A dictionary where the key is the resource name and the value is the database name.
- `host`: `EndpointReferenceExpression` `get` -- Gets the host endpoint reference for this service.
- `jdbcConnectionString`: `ReferenceExpression` `get` -- Gets the JDBC connection string for the PostgreSQL server.
- `passwordParameter`: `ParameterResource` `get - set` -- Gets or sets the parameter that contains the PostgreSQL server password.
- `port`: `EndpointReferenceExpression` `get` -- Gets the endpoint reference expression that identifies the port for this endpoint.
- `primaryEndpoint`: `EndpointReference` `get` -- Gets the primary endpoint for the PostgreSQL server.
- `uriExpression`: `ReferenceExpression` `get` -- Gets the connection URI expression for the PostgreSQL server.
- `userNameParameter`: `ParameterResource` `get - set` -- Gets or sets the parameter that contains the PostgreSQL server user name.
- `userNameReference`: `ReferenceExpression` `get` -- Gets a reference to the user name for the PostgreSQL server.

## Methods

- [addDatabase](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/adddatabase.md) -- `method` -- Adds a PostgreSQL database to the application model.
    ```typescript
  addDatabase(name: string, databaseName?: string): PostgresDatabaseResource
  ```
- [withDataBindMount](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withdatabindmount.md) -- `method` -- Adds a bind mount for the data folder to a PostgreSQL container resource.
    ```typescript
  withDataBindMount(source: string, isReadOnly?: boolean): PostgresServerResource
  ```
- [withDataVolume](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withdatavolume.md) -- `method` -- Adds a named volume for the data folder to a PostgreSQL container resource.
    ```typescript
  withDataVolume(name?: string, isReadOnly?: boolean): PostgresServerResource
  ```
- [withHostPort](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withhostport.md) -- `method` -- Configures the host port that the PostgreSQL resource is exposed on instead of using randomly assigned port.
    ```typescript
  withHostPort(port: number): PostgresServerResource
  ```
- [withInitFiles](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withinitfiles.md) -- `method` -- Copies init files to a PostgreSQL container resource.
    ```typescript
  withInitFiles(source: string): PostgresServerResource
  ```
- [withPassword](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withpassword.md) -- `method` -- Configures the password that the PostgreSQL resource is used.
    ```typescript
  withPassword(password: ParameterResource): PostgresServerResource
  ```
- [withPgAdmin](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withpgadmin.md) -- `method` -- Adds a pgAdmin 4 administration and development platform for PostgreSQL to the application model.
    ```typescript
  withPgAdmin(configureContainer?: (obj: PgAdminContainerResource) => Promise<void>, containerName?: string): PostgresServerResource
  ```
- [withPgWeb](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withpgweb.md) -- `method` -- Adds an administration and development platform for PostgreSQL to the application model using pgweb.
    ```typescript
  withPgWeb(configureContainer?: (obj: PgWebContainerResource) => Promise<void>, containerName?: string): PostgresServerResource
  ```
- [withUserName](/reference/api/typescript/aspire.hosting.postgresql/postgresserverresource/withusername.md) -- `method` -- Configures the user name that the PostgreSQL resource is used.
    ```typescript
  withUserName(userName: ParameterResource): PostgresServerResource
  ```
