docker를 이용하여 로컬에 오라클 12c 셋팅 하는 방법이다.
- 오라클 사용하기 앞서 이용약관 동의 과정이 존재한다.
https://hub.docker.com/_/oracle-database-enterprise-edition?tab=resources
Proceed to Checkout 클릭
2. 기본정보를 입력하고 동의
3. docker에 오라클 이미지를 다운로드 받고 container 를 띄운다.
- 진하게 표시된 부분이 명령어
> docker pull store/oracle/database-enterprise:12.2.0.1-slim
12.2.0.1-slim: Pulling from store/oracle/database-enterprise
4ce27fe12c04: Pull complete 9d3556e8e792: Pull complete fc60a1a28025: Pull complete 0c32e4ed872e: Pull complete be0a1f1e8dfd: Pull complete Digest: sha256:dbd87ae4cc3425dea7ba3d3f34e062cbd0afa89aed2c3f3d47ceb5213cc0359a
Status: Downloaded newer image for store/oracle/database-enterprise:12.2.0.1-slim
docker.io/store/oracle/database-enterprise:12.2.0.1-slim
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
store/oracle/database-enterprise 12.2.0.1-slim 27c9559d36ec 2 years ago 2.08GB
> docker run -e "TZ=Asia/Seoul" -dit --name ora_custom_db -p 1521:1521 store/oracle/database-enterprise:12.2.0.1-slim
599ba9ba3f285e0797eea4c26d837326f2fc1de9b8b8a94b944c57580558bca4
> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
599ba9ba3f28 store/oracle/database-enterprise:12.2.0.1-slim "/bin/sh -c '/bin/ba…" 12 seconds ago Up 11 seconds (health: starting) 0.0.0.0:1521->1521/tcp, 5500/tcp ora_custom_db
4. sqlplus에 접속 하여 계정생성, 권한 추가
- 진하게 표시된 부분이 명령어
- 계정은 root , 비밀번호는 1234
//오라클 쉘(SQLPLUS) 접속
> docker exec -it ora_custom_db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba"
//계정 규칙 제한 없애기
SQL> alter session set "_ORACLE_SCRIPT"=true;
// 계정생성 (root / 1234)
SQL> create user root identified by 1234;
// 권한 추가
SQL> grant connect, resource, dba to root;
5. timezone 설정 & utf8설정
- 진하게 표시된 부분이 명령어
// 오라클 설정 파일 확인
> docker exec -it ora_custom_db bash -c "cat /home/oracle/.bashrc"// Timezone 변경
> docker exec -it ora_custom_db bash -c "echo \"export TZ='Asia/Seoul'\" >> /home/oracle/.bashrc"// sqlplus 접속
> docker exec -it ora_custom_db bash -c "source /home/oracle/.bashrc; sqlplus sys/Oradoc_db1@ORCLCDB as sysdba"// language utf8 업데이트
SQL> update sys.props$ set value$='KOREAN_KOREA.UTF8' where name='NLS_LANGUAGE';// characterset utf8 업데이트
SQL> update sys.props$ set value$='UTF8' where name='NLS_CHARACTERSET';// nchar characterset utf8업데이트
SQL> update sys.props$ set value$='UTF8' where name='NLS_NCHAR_CHARACTERSET';// 반영
SQL> commit;// 재부팅
SQL> shutdown immediate;
SQL> conn / as sysdba;
SQL> startup;
*ORA-06553: PLS-553 에러가 발생할 경우
- 위 설정대로 해도 에러가 나는 경우가 있다. 그럴경우 charset 을 위와 조금 다른 방법으로 설정하는 걸로 해결했다.
- 진하게 표시된 부분이 명령어
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor
Warning: You are no longer connected to ORACLE.SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 1342177280 bytes
Fixed Size 8792536 bytes
Variable Size 369100328 bytes
Database Buffers 956301312 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.SQL> conn / as sysdba;
Connected to an idle instance.SQL> STARTUP MOUNT;
ORACLE instance started.
Total System Global Area 1342177280 bytes
Fixed Size 8792536 bytes
Variable Size 369100328 bytes
Database Buffers 956301312 bytes
Redo Buffers 7983104 bytes
Database mounted.SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
System altered.
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
System altered.
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
System altered.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> COL VALUE NEW_VALUE CHARSET
SQL> SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_CHARACTERSET';
VALUE
-------------------------------------------------------------------
UTF8SQL> COL VALUE NEW_VALUE NCHARSET
SQL> SELECT VALUE FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER='NLS_NCHAR_CHARACTERSET';
VALUE
--------------------------------------------------------------------
UTF8
SQL> ALTER DATABASE CHARACTER SET INTERNAL_USE &CHARSET;
old 1: ALTER DATABASE CHARACTER SET INTERNAL_USE &CHARSET
new 1: ALTER DATABASE CHARACTER SET INTERNAL_USE UTF8
Database altered.SQL> ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE &NCHARSET;
old 1: ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE &NCHARSET
new 1: ALTER DATABASE NATIONAL CHARACTER SET INTERNAL_USE UTF8
Database altered.SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.SQL> conn / as sysdba;
Connected to an idle instance.
SQL> STARTUP;
ORACLE instance started.
Total System Global Area 1342177280 bytes
Fixed Size 8792536 bytes
Variable Size 369100328 bytes
Database Buffers 956301312 bytes
Redo Buffers 7983104 bytes
Database mounted.
Database opened.
[참고]