---
# System prepended metadata

title: Using a custom database

---

# Using a custom database

* Administrators can use a custom database instead of the default PostgreSQL database installed by the Operator. You can use your custom database with `db-migration`, `api`, and `ui` interfaces provided by {tekton-hub}.

* In this case, default database provided by Tekton Hub won't be installed and  and other services like `db-migration`, `api`, and `ui` will be connected to the custom database which is managed by the user

* . Create a secret named `tekton-hub-db` in the target namespace with the following keys: 
    * `POSTGRES_HOST`
    * `POSTGRES_DB`
    * `POSTGRES_USER`
    * `POSTGRES_PASSWORD`
    * `POSTGRES_PORT`

* Example: Custom database secrets
```yaml=
----
apiVersion: v1
kind: Secret
metadata:
  name: tekton-hub-db
  labels:
    app: tekton-hub-db
type: Opaque
stringData:
  POSTGRES_HOST: <The name of the host of the database>
  POSTGRES_DB: <Name of the database>
  POSTGRES_USER: <The name of user account>
  POSTGRES_PASSWORD: <The password of user account>
  POSTGRES_PORT: <The port that the database is listening on>
```

In the `TektonHub` CR, set the value of the database secret attribute to `tekton-hub-db`

Example: Adding custom database secret 

```yaml=
----
apiVersion: operator.tekton.dev/v1alpha1
kind: TektonHub
metadata:
  name: hub
spec:
  targetNamespace: openshift-pipelines
  db:                      # 👈 external database to be used
    secret: tekton-hub-db  # 👈 Name of db secret should be `tekton-hub-db`
  api:
    hubConfigUrl: https://raw.githubusercontent.com/tektoncd/hub/main/config.yaml
    catalogRefreshInterval: 30m
```

#### For fresh installation of Tekton Hub using Custom Database
Apply the updated `TektonHub` CR.

```bash=
$ oc apply -f <tekton-hub-cr>.yaml
```

#### If Tekton Hub is already installed and user now wants to use Custom Database

Replace the updated `TektonHub` CR.

```bash=
$ oc replace -f <tekton-hub-cr>.yaml
```

* Check the status of the installation. The `TektonHub` CR might take some time to attain steady state.

```bash=
$ oc get tektonhub.operator.tekton.dev
NAME   VERSION   READY   REASON   APIURL                    UIURL
hub    v1.8.0    True             https://api.route.url/    https://ui.route.url/
```
 