> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sambanova.ai/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:

**SambaStack on-prem / Airgapped**

### Step 1: Create the Secret

#### Option A: Base64-encoded Values

First, encode your database credentials:

```bash theme={}
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={}
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={}
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={}
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={}
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](/docs/en/v2.2.6/sambastack/resources/sambastack-yaml) for a full example.

### Step 3: Apply the Configuration

Update your Helm deployment:

#### On-prem

```bash theme={}
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={}
helm upgrade sambastack \
  -f sambastack.yaml \
  --namespace sambastack \
  sambastack-<VERSION>.tgz
```

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

> [!NOTE]
>
> SambaNova provides the full registry URL and version number during handover. Contact your SambaNova representative for access credentials.

> [!WARNING]
>
> Ensure your external PostgreSQL database is accessible from the Kubernetes cluster and that network policies allow the connection.

**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={}
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.

### 3. Update sambastack.yaml

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

```yaml theme={}
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](/docs/en/v2.2.6/sambastack/resources/sambastack-yaml) for a full example.

### 4. Apply Updated Configuration

Apply the changes:

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

After applying these changes, your deployment will connect to the configured external PostgreSQL database.
