趣旨
以下参考サイトを参照し、WSL2のdockerでOracle19cのコンテナを起動させたい。
スキーマ・テーブル作成まで自動化したいが、
startup/setupスクリプトがCDBに対して動くので、
PDBに対して動くようにしたい。
前提条件
- Windows10
- WSL2
- Ubuntu20.10
参考サイト
- https://zenn.dev/msksgm/articles/20211225-oracle-database-19c-docker
- https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md
- https://qiita.com/blueskyarea/items/e96ec596819e0530e577
事象
- /opt/oracle/scripts/setupに置いたcreate user文が、CDBに対して実行される。(PDBが作られる前に実行される?)
CDBでは、ユーザーを作れない(ORA-65096) - 以下の通り、startupスクリプトが動くが、エラーになる。(CDBに対してCREATE USERするため ORA-65096発生)
myoracledb19 | Executing user defined scripts
myoracledb19 | /opt/oracle/runUserScripts.sh: running /opt/oracle/scripts/setup/01_ot_create_user.sql
myoracledb19 | CREATE USER OT IDENTIFIED BY "oracle"
myoracledb19 | *
myoracledb19 | ERROR at line 1:
myoracledb19 | ORA-65096: invalid common user or role name
myoracledb19 |
myoracledb19 |
myoracledb19 | GRANT CONNECT, RESOURCE, DBA TO OT
myoracledb19 | *
myoracledb19 | ERROR at line 1:
myoracledb19 | ORA-01917: user or role 'OT' does not exist
myoracledb19 |
myoracledb19 |
myoracledb19 |
myoracledb19 |
myoracledb19 | /opt/oracle/runUserScripts.sh: ignoring /opt/oracle/scripts/setup/02_ot_drop.sql_block
myoracledb19 |
myoracledb19 | /opt/oracle/runUserScripts.sh: ignoring /opt/oracle/scripts/setup/03_ot_schema.sql_block
myoracledb19 |
myoracledb19 | /opt/oracle/runUserScripts.sh: ignoring /opt/oracle/scripts/setup/04_ot_data.sql_block
myoracledb19 |
myoracledb19 | DONE: Executing user defined scripts
myoracledb19 |
myoracledb19 | The Oracle base remains unchanged with value /opt/oracle
myoracledb19 | #########################
myoracledb19 | DATABASE IS READY TO USE!
myoracledb19 | #########################
myoracledb19 | The following output is now a tail of the alert.log:
myoracledb19 | ORCLPDB1(3):ALTER DATABASE DEFAULT TABLESPACE "USERS"
myoracledb19 | ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
myoracledb19 | 2022-08-19T02:13:23.851527+00:00
myoracledb19 | ALTER SYSTEM SET control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl' SCOPE=SPFILE;
myoracledb19 | 2022-08-19T02:13:23.864042+00:00
myoracledb19 | ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
myoracledb19 | ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
myoracledb19 | Completed: ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
myoracledb19 |
myoracledb19 | XDB initialized.
docker-compose
docker-compose.yml
version: '3'
services:
oracle_server:
image: oracle/database:19.3.0-ee
container_name: myoracledb19
ports:
- 1521:1521
- 5500:5500
volumes:
- ./oradata:/opt/oracle/oradata
- ./setup:/opt/oracle/scripts/setup
environment:
- ORACLE_PWD=oracle
- ORACLE_PDB=ORCLPDB1
解決策
- 実行したいスクリプトの最初に以下を入れる。
ALTER SESSION SET CONTAINER=ORCLPDB1;