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

# Custom database

By default, SambaNova provisions a PostgreSQL instance within your cluster. To use an external PostgreSQL database instead of the in-cluster deployment, complete the following steps:

<Tabs>
  <Tab title="SambaStack on-prem / Airgapped">
    ### Step 1: Create the Secret

    #### Option A: Base64-encoded Values

    First, encode your database credentials:

    ```bash theme={null}
    echo -n "<db-host>" | base64
    echo -n "<db-name>" | base64
    echo -n "<db-user>" | base64
    echo -n "<db-password>" | base64
    ```

    Create a Kubernetes secret with base64-encoded values:

    ```yaml theme={null}
    apiVersion: v1
    kind: Secret
    metadata:
      name: pg-credentials
      namespace: sambastack
    type: Opaque
    data:
      DB_HOST: <Base64 encoded DB_HOST>
      DB_DATABASE: <Base64 encoded DB_DATABASE>
      DB_USER: <Base64 encoded DB_USER>
      DB_PASSWD: <Base64 encoded DB_PASSWD>
    ```

    Apply the secret:

    ```bash theme={null}
    kubectl apply -f pg-credentials.yaml
    ```

    #### Option B: Using kubectl with Literal Values

    Instead of manually encoding, you can create the secret with literal values:

    ```bash theme={null}
    kubectl create secret generic pg-credentials \
      --from-literal=DB_HOST=<host> \
      --from-literal=DB_DATABASE=<database> \
      --from-literal=DB_USER=<user> \
      --from-literal=DB_PASSWD=<password> \
      --namespace sambastack
    ```

    ### Step 2: Update sambastack.yaml

    Configure your `sambastack.yaml` to use the external database:

    ```yaml theme={null}
    auth-and-billing:
      pgSecretName: pg-credentials

    cloudnative-pg:
      enabled: false
    ```

    * `auth-and-billing.pgSecretName`: References the Kubernetes secret containing database credentials
    * `cloudnative-pg.enabled: false`: Disables the in-cluster PostgreSQL deployment

    <Note>
      See the  [SambaStack.yaml Reference](/en/v1.2.0/sambastack/resources/sambastack-yaml) for a full example.
    </Note>

    ### Step 3: Apply the Configuration

    Update your Helm deployment:

    #### On-prem

    ```bash theme={null}
    helm upgrade sambastack \
      -f sambastack.yaml \
      --namespace sambastack \
      oci://<REGISTRY_URL>/sambastack/sambastack
    ```

    #### Airgapped

    Use your local copy of the Helm chart instead of the OCI registry path:

    ```shellscript theme={null}
    helm upgrade sambastack \
      -f sambastack.yaml \
      --namespace sambastack \
      sambastack-<VERSION>.tgz
    ```

    <Info>
      `sambastack-<VERSION>.tgz` is your local copy of the Helm chart used for the upgrade. Contact SambaNova Support if you need further assistance.
    </Info>

    <Note>
      SambaNova provides the full registry URL and version number during handover. Contact your SambaNova representative for access credentials.
    </Note>

    <Warning>
      Ensure your external PostgreSQL database is accessible from the Kubernetes cluster and that network policies allow the connection.
    </Warning>
  </Tab>

  <Tab title="SambaStack hosted">
    ### 1. Provision External Database

    Set up an external PostgreSQL instance and collect these credentials:

    * `DB_HOST`
    * `DB_DATABASE`
    * `DB_USER`
    * `DB_PASSWD`

    ### 2. Create Kubernetes Secret for PostgreSQL Credentials

    Create a secret named `pg-credentials` with your database credentials:

    ```bash theme={null}
    cat <<EOPGSECRET | kubectl apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
      name: pg-credentials
      namespace: default
    type: Opaque
    data:
      DB_HOST: <Base64 encoded DB_HOST>
      DB_DATABASE: <Base64 encoded DB_DATABASE>
      DB_USER: <Base64 encoded DB_USER>
      DB_PASSWD: <Base64 encoded DB_PASSWD>
    EOPGSECRET
    ```

    <Note>
      Ensure all credential values are base64 encoded.
    </Note>

    ### 3. Update sambastack.yaml

    Modify `sambastack.yaml` (`data → sambastack.yaml`) to reference your external PostgreSQL secret and disable the in-cluster database:

    ```yaml theme={null}
    data:
      sambastack.yaml: |
        # Auth and Billing Configuration
        auth-and-billing:
          pgSecretName: pg-credentials # Kubernetes secret with PostgreSQL credentials
        # Database Configuration
        cloudnative-pg:
          enabled: false # Disable in-cluster PostgreSQL
    ```

    <Note>
      See the  [SambaStack.yaml Reference](/en/v1.2.0/sambastack/resources/sambastack-yaml) for a full example.
    </Note>

    ### 4. Apply Updated Configuration

    Apply the changes:

    ```bash theme={null}
    kubectl apply -f sambastack.yaml
    ```

    After applying these changes, your deployment will connect to the configured external PostgreSQL database.
  </Tab>
</Tabs>
