// Metadata created by nebel
// ParentAssemblies: assemblies/getting-started/as_installing-the-registry.adoc

[id="setting-up-postgresql-storage_{context}"]

= Configuring {registry} with PostgreSQL database storage on OpenShift

[role="_abstract"]
This section explains how to configure storage for {registry} on OpenShift using a PostgreSQL database Operator. You can install {registry} in an existing database or create a new database, depending on your environment. This section shows a simple example using the PostgreSQL Operator by Dev4Ddevs.com.

.Prerequisites
* You must have an OpenShift cluster with cluster administrator access.
* You must have already installed {registry}. See {installing-the-registry-openshift}.
* You must have already installed a PostgreSQL Operator on OpenShift. For example, see xref:installing-postgresql-operatorhub_{context}[].

.Procedure

. In the OpenShift Container Platform web console, log in using an account with cluster administrator privileges.

. Change to the OpenShift project in which {registry} and your PostgreSQL Operator are installed. For example, from the *Project* drop-down, select `my-project`.

. Create a PostgreSQL database for your {registry} storage. For example, click *Installed Operators*, *PostgreSQL Operator by Dev4Ddevs.com*, and then *Create database*.

. Click *YAML* and edit the database settings as follows:
** `name`: Change the value to `registry`
** `image`: Change the value to `centos/postgresql-12-centos7`

. Edit any other database settings as needed depending on your environment, for example:
+
[source,yaml]
----
apiVersion: postgresql.dev4devs.com/v1alpha1
kind: Database
metadata:
  name: registry
  namespace: my-project
spec:
  databaseCpu: 30m
  databaseCpuLimit: 60m
  databaseMemoryLimit: 512Mi
  databaseMemoryRequest: 128Mi
  databaseName: example
  databaseNameKeyEnvVar: POSTGRESQL_DATABASE
  databasePassword: postgres
  databasePasswordKeyEnvVar: POSTGRESQL_PASSWORD
  databaseStorageRequest: 1Gi
  databaseUser: postgres
  databaseUserKeyEnvVar: POSTGRESQL_USER
  image: centos/postgresql-12-centos7
  size: 1
----

. Click *Create*, and wait until the database is created.

ifdef::apicurio-registry[]
. Click *Installed Operators* > *{registry}* > *ApicurioRegistry* > *Create ApicurioRegistry*.
endif::[]
ifdef::rh-service-registry[]
. Click *Installed Operators* > *Red Hat Integration - Service Registry* > *ApicurioRegistry* > *Create ApicurioRegistry*.
endif::[]

. Paste in the following custom resource definition, and edit the values for the database `url` and credentials to match your environment:
+
[source,yaml]
----
apiVersion: registry.apicur.io/v1
kind: ApicurioRegistry
metadata:
  name: example-apicurioregistry-sql
spec:
  configuration:
    persistence: 'sql'
    sql:
      dataSource:
        url: 'jdbc:postgresql://<service name>.<namespace>.svc:5432/<database name>'
        # e.g. url: 'jdbc:postgresql://acid-minimal-cluster.my-project.svc:5432/registry'
        userName: 'postgres'
        password: '<password>' # Optional
----

. Click *Create* and wait for the {registry} route to be created on OpenShift.

. Click *Networking* > *Route* to access the new route for the {registry} web console. For example:
+
[source]
----
http://example-apicurioregistry-sql.my-project.my-domain-name.com/
----

[role="_additional-resources"]
.Additional resources

 * link:https://access.crunchydata.com/documentation/postgres-operator/4.3.2/quickstart/[Crunchy PostgreSQL Operator QuickStart]
 * https://github.com/Apicurio/apicurio-registry-operator[Apicurio Registry Operator QuickStart]
