oracle / docker-images

Official source of container configurations, images, and examples for Oracle products and projects
https://developer.oracle.com/use-cases/#containers
Universal Permissive License v1.0
6.6k stars 5.44k forks source link

ORACLE_PDB being overwritten for 23ai Free #2853

Open cmdkeen opened 3 months ago

cmdkeen commented 3 months ago

Hi,

I'm running into a problem trying to customise the PDB being created in the 23ai Free image. The documentation says the ORACLE_PDB environment variable can be used to customise this, but when set it is ignored and FREEPDB1 created. I think this is due to this block overwriting any passed value. Line 214 later on handles the default value, so could the export below could potentially be removed?

# Sanitizing env for FREE
if [ "${ORACLE_SID}" = "FREE" ]; then
   export ORACLE_PDB="FREEPDB1"
   unset DG_OBSERVER_ONLY CLONE_DB STANDBY_DB
fi
oraclesean commented 3 months ago

The CDB and PDB names for the 23ai Free Edition are fixed in the RPM and can't be customized when starting the container. You could work around this (if you really wanted to) by editing /etc/init.d/oracle-free-23ai and changing the fixed values for SID and PDB. You'd need to perform this operation during image creation since the file is owned by root and can't be edited from the container (which would be running as the oracle user). You could accomplish this by adding something like this to the image build, which will update the file to read the SID/PDB from the environment:

sed -i -e 's/^export ORACLE_SID=FREE$/export ORACLE_SID=\$ORACLE_SID/' -e 's/^export PDB_NAME=FREEPDB1$/export PDB_NAME=\$PDB_NAME/' oracle-free-23c

This section of my repo does something similar and might work to give you an idea of how to accomplish this: https://github.com/oraclesean/cloud-native-oracle/blob/c7b6143586d1dae957e3018733c28409014488bc/manageOracle.sh#L429C1-L474C7 In this example, it's updating directories like ORACLE_HOME and ORACLE_BASE that are fixed in the 11g/19c RPM.

Optionally, you could docker exec -u root -it <CONTAINER_NAME> bash (or perhaps run the above sed command directly as root) and edit the file, then recreate the database after container startup.

Disclaimer: I didn't test this, so no guarantees, and IDK if this violates any license agreements. YMMV, caveat emptor, proceed at your own risk, etc. 😄

cmdkeen commented 3 months ago

Thanks Sean - that seems to not line up with the container docs and what I'm seeing in the shell script for it. On the docs on the Oracle registry under "Custom Configurations" it describes this as possible.

The container entry script does have the potential to call the script to create a PDB, it's just in the linked section above the documented environment variable is being ignored. If the docs are wrong that's understandable but it would be useful to update them.

oraclesean commented 3 months ago

The documentation applies to the non-23ai Free builds and probably hasn't been updated to reflect this. The code block you see is the workaround for the fixed SID/PDB names. If I recall correctly, I believe there's something similar for 11g XE and 18c XE.

oraclesean commented 3 months ago

I updated the documentation to clarify the limitation in the 23ai and 11g/18c XE sections, added a note on defaults to the documentation of the ORACLE_SID and PDB_NAME parameters, and submitted a pull request. The limitation on ORACLE_SID is mentioned here but doesn't cover the PDB_NAME: https://github.com/oracle/docker-images/blob/cb1416b13b105adf5dac26e2780f8b1751522f86/OracleDatabase/SingleInstance/README.md?plain=1#L403-L404