|
| 1 | +<!-- |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | +--> |
| 19 | + |
| 20 | +This page documents the general configurations to connect to production database through [EclipseLink](https://eclipse.dev/eclipselink/). |
| 21 | + |
| 22 | +## Polaris Server Configuration |
| 23 | +Configure the `metaStoreManager` section in server configuration `polaris-server.yml` as follows: |
| 24 | +``` |
| 25 | +metaStoreManager: |
| 26 | + type: eclipse-link |
| 27 | + conf-file: META-INF/persistence.xml |
| 28 | + persistence-unit: polaris |
| 29 | +``` |
| 30 | +`conf-file` points to the EclipseLink configuration file and `persistence-unit` tells which unit from the configuration file to use for database connection. |
| 31 | + |
| 32 | +E.g., `polaris-dev` and `polaris` persistence units are configured in `persistence.xml` to connect to development database and production database respectively. Updating `persistence-unit` from `polaris-dev` to `polaris` switch from the development to the production. |
| 33 | + |
| 34 | +`conf-file` by default points to the embedded resource file `META-INF/persistence.xml` in `polaris-eclipselink` module. |
| 35 | +To specify an external configuration file, |
| 36 | +1) Place `persistence.xml` into a jar file: `jar cvf /tmp/conf.jar persistence.xml`. |
| 37 | +2) Use `conf-file: /tmp/conf.jar!/persistence.xml`. |
| 38 | + |
| 39 | +## EclipseLink Configuration - persistence.xml |
| 40 | +The configuration file `persistence.xml` is used to set up the database connection properties, which can differ depending on the type of database and its configuration. |
| 41 | + |
| 42 | +Check out [default persistence.xml](https://github.com/apache/polaris/blob/main/extension/persistence/eclipselink/src/main/resources/META-INF/persistence.xml) for the complete sample and the following shows the database connection properties against file-based H2 database. Polaris creates and connects to a separate database for each realm. Specifically, `{realm}` placeholder in `jakarta.persistence.jdbc.url` is substituted with the actual realm name, allowing the Polaris server to connect to different databases based on the realm. |
| 43 | + |
| 44 | +> Note: some database systems such as Postgres don't create databases automatically. Database admins need to create them manually before running Polaris server. |
| 45 | +```xml |
| 46 | +<persistence-unit name="polaris" transaction-type="RESOURCE_LOCAL"> |
| 47 | + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> |
| 48 | + <class>org.apache.polaris.core.persistence.models.ModelEntity</class> |
| 49 | + <class>org.apache.polaris.core.persistence.models.ModelEntityActive</class> |
| 50 | + <class>org.apache.polaris.core.persistence.models.ModelEntityChangeTracking</class> |
| 51 | + <class>org.apache.polaris.core.persistence.models.ModelEntityDropped</class> |
| 52 | + <class>org.apache.polaris.core.persistence.models.ModelGrantRecord</class> |
| 53 | + <class>org.apache.polaris.core.persistence.models.ModelPrincipalSecrets</class> |
| 54 | + <class>org.apache.polaris.core.persistence.models.ModelSequenceId</class> |
| 55 | + <shared-cache-mode>NONE</shared-cache-mode> |
| 56 | + <properties> |
| 57 | + <property name="jakarta.persistence.jdbc.url" |
| 58 | + value="jdbc:h2:file:tmp/polaris_test/filedb_{realm}"/> |
| 59 | + <property name="jakarta.persistence.jdbc.user" value="sa"/> |
| 60 | + <property name="jakarta.persistence.jdbc.password" value=""/> |
| 61 | + <property name="jakarta.persistence.schema-generation.database.action" value="create"/> |
| 62 | + </properties> |
| 63 | +</persistence-unit> |
| 64 | +``` |
| 65 | + |
| 66 | +Build with H2 dependency and run Polaris service: |
| 67 | +```bash |
| 68 | +polaris> ./gradlew --no-daemon --info -PeclipseLink=true -PeclipseLinkDeps=com.h2database:h2:2.3.232 clean shadowJar |
| 69 | +polaris> java -jar polaris-service/build/libs/polaris-service-*.jar server ./polaris-server.yml |
| 70 | +``` |
| 71 | + |
| 72 | +### Postgres |
| 73 | + |
| 74 | +The following shows a sample configuration for Postgres database. |
| 75 | + |
| 76 | +```xml |
| 77 | +<persistence-unit name="polaris" transaction-type="RESOURCE_LOCAL"> |
| 78 | + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> |
| 79 | + <class>org.apache.polaris.core.persistence.models.ModelEntity</class> |
| 80 | + <class>org.apache.polaris.core.persistence.models.ModelEntityActive</class> |
| 81 | + <class>org.apache.polaris.core.persistence.models.ModelEntityChangeTracking</class> |
| 82 | + <class>org.apache.polaris.core.persistence.models.ModelEntityDropped</class> |
| 83 | + <class>org.apache.polaris.core.persistence.models.ModelGrantRecord</class> |
| 84 | + <class>org.apache.polaris.core.persistence.models.ModelPrincipalSecrets</class> |
| 85 | + <class>org.apache.polaris.core.persistence.models.ModelSequenceId</class> |
| 86 | + <shared-cache-mode>NONE</shared-cache-mode> |
| 87 | + <properties> |
| 88 | + <property name="jakarta.persistence.jdbc.url" |
| 89 | + value="jdbc:postgresql://localhost:5432/{realm}"/> |
| 90 | + <property name="jakarta.persistence.jdbc.user" value="postgres"/> |
| 91 | + <property name="jakarta.persistence.jdbc.password" value="postgres"/> |
| 92 | + <property name="jakarta.persistence.schema-generation.database.action" value="create"/> |
| 93 | + <property name="eclipselink.persistence-context.flush-mode" value="auto"/> |
| 94 | + </properties> |
| 95 | +</persistence-unit> |
| 96 | +``` |
| 97 | +Build with Postgres dependency and run Polaris service: |
| 98 | +```bash |
| 99 | +polaris> ./gradlew --no-daemon --info -PeclipseLink=true -PeclipseLinkDeps=org.postgresql:postgresql:42.7.4 clean shadowJar |
| 100 | +polaris> java -jar polaris-service/build/libs/polaris-service-*.jar server ./polaris-server.yml |
| 101 | +``` |
0 commit comments