> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Postgres Cluster

> Create a Managed Postgres cluster for the organization named in the request body. Provisioning is asynchronous: poll `GET /v1/postgres/{id}` until `status == ready` before calling database, user, extension, or credential endpoints.



## OpenAPI

````yaml /machines-api/openapi.json post /v1/postgres
openapi: 3.0.1
info:
  title: Machines API
  description: >-
    This site hosts documentation generated from the Fly.io Machines API OpenAPI
    specification. Visit our complete [Machines API
    docs](https://fly.io/docs/machines/api/) for how to get started, more
    information about each endpoint, parameter descriptions, and examples.
  contact: {}
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: '1.0'
servers:
  - url: https://api.machines.dev
security: []
tags:
  - name: Apps
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/apps-resource/) for details about
      using the Apps resource.
  - name: Machines
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/machines-resource/) for details
      about using the Machines resource.
  - name: TLS Certificates
    description: >
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/certificates-resource/) for details
      about using the TLS Certificates resource.
  - name: Volumes
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/volumes-resource/) for details
      about using the Volumes resource.
  - name: Postgres Clusters
    description: >-
      Create and manage Postgres clusters, including databases, users,
      extensions, backups, and app attachments.
externalDocs:
  url: https://fly.io/docs/machines/working-with-machines/
paths:
  /v1/postgres:
    post:
      tags:
        - Postgres Clusters
      summary: Create Postgres Cluster
      description: >-
        Create a Managed Postgres cluster for the organization named in the
        request body. Provisioning is asynchronous: poll `GET /v1/postgres/{id}`
        until `status == ready` before calling database, user, extension, or
        credential endpoints.
      operationId: Postgres_create
      requestBody:
        description: Cluster details
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createPostgresClusterRequest'
        required: true
      responses:
        '201':
          description: Cluster accepted for provisioning
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/showPostgresClusterResponse'
        '400':
          description: org_slug is required and must be a string, or creation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
        '422':
          description: Invalid attributes
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostgresErrorResponse'
      security:
        - FlyBearerAuth: []
components:
  schemas:
    createPostgresClusterRequest:
      required:
        - org_slug
        - plan
        - region
      type: object
      properties:
        disk_size_gb:
          maximum: 1000
          minimum: 10
          type: integer
          description: Disk size in gigabytes.
          example: 10
        name:
          type: string
          description: Name for the cluster. A name is generated when omitted.
        org_slug:
          type: string
          description: >-
            Slug of the organization that will own the cluster, or "personal"
            for the caller's personal organization.
          example: my-org
        pg_major_version:
          type: string
          description: Postgres major version.
          example: '17'
          enum:
            - '16'
            - '17'
        plan:
          type: string
          description: >-
            Plan slug selecting CPU, memory, and disk sizing. Matched
            case-insensitively.
          example: basic
          enum:
            - basic
            - starter
            - launch
            - scale
            - Performance
        pool_mode:
          type: string
          description: Connection pooler mode.
          example: transaction
          enum:
            - session
            - transaction
        postgis_enabled:
          type: boolean
          description: Enable PostGIS support, required to later enable PostGIS extensions.
        region:
          type: string
          description: Fly region code where the cluster's primary runs.
          example: iad
    showPostgresClusterResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/PostgresCluster'
    PostgresErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message.
    PostgresCluster:
      type: object
      properties:
        attached_apps:
          type: array
          description: Apps attached to the cluster.
          items:
            $ref: '#/components/schemas/PostgresAttachedApp'
        cpu_kind:
          type: string
          description: CPU class.
          example: shared
          enum:
            - shared
            - performance
        cpus:
          type: integer
          description: vCPUs per node.
          example: 2
        created_at:
          type: string
          description: RFC 3339 creation timestamp.
          format: date-time
        disk_size_gb:
          type: integer
          description: Disk size in gigabytes, for one replica.
          example: 10
        endpoints:
          type: object
          description: Connection endpoints. Populated once the cluster is ready.
          allOf:
            - $ref: '#/components/schemas/PostgresClusterEndpoints'
        id:
          type: string
          description: Cluster ID.
        memory_mb:
          type: integer
          description: Memory per node in megabytes.
          example: 1024
        name:
          type: string
          description: Cluster name.
        organization:
          $ref: '#/components/schemas/OrganizationRef'
        pg_major_version:
          type: string
          description: Postgres major version.
          example: '17'
          enum:
            - '16'
            - '17'
        plan:
          type: string
          description: Plan slug.
          example: basic
          enum:
            - basic
            - starter
            - launch
            - scale
            - Performance
        postgis_enabled:
          type: boolean
          description: Whether PostGIS support is enabled.
        region:
          type: string
          description: Fly region code.
          example: iad
        replicas:
          type: integer
          description: Number of replicas.
          example: 1
        status:
          type: string
          description: Current lifecycle status.
          example: ready
          enum:
            - creating
            - initializing
            - ready
            - deleting
            - deleted
            - failed
        storage_provisioned_bytes:
          type: integer
          description: >-
            Storage provisioned, summed across the cluster's volumes and
            measured hourly.

            Null until first measured.
          nullable: true
          example: 10737418240
        storage_used_bytes:
          type: integer
          description: >-
            Storage used, summed across the cluster's volumes and measured
            hourly. Null

            until first measured.
          nullable: true
          example: 5368709120
    PostgresAttachedApp:
      type: object
      properties:
        name:
          type: string
          description: Attached Fly app name.
    PostgresClusterEndpoints:
      type: object
      properties:
        primary:
          type: object
          description: Endpoints for connecting to the primary node.
          allOf:
            - $ref: '#/components/schemas/PostgresNodeEndpoints'
    OrganizationRef:
      type: object
      properties:
        name:
          type: string
          description: Organization name.
        slug:
          type: string
          description: Organization slug.
    PostgresNodeEndpoints:
      type: object
      properties:
        direct:
          type: object
          description: Unpooled connection to the cluster node.
          allOf:
            - $ref: '#/components/schemas/PostgresEndpoint'
        pooler:
          type: object
          description: Pooled connection to the cluster node (through PgBouncer).
          allOf:
            - $ref: '#/components/schemas/PostgresEndpoint'
    PostgresEndpoint:
      type: object
      properties:
        host:
          type: string
          description: Hostname to connect to.
        port:
          type: integer
          description: TCP port.
  securitySchemes:
    FlyBearerAuth:
      type: apiKey
      description: >-
        A Fly API token with access to the requested organization or resource.
        Send it as `Authorization: Bearer <Fly API token>`.
      name: Authorization
      in: header

````