λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
ORACLE/DB

[Oracle] Sample Schema HR, OE, PM, IX, SH, BI 생성

by πŸŒ»β™š 2020. 7. 15.

Oracle Sample Schema

였라클 λ°μ΄ν„°λ² μ΄μŠ€λ₯Ό μˆ˜λ™μƒμ„±ν•˜κ±°λ‚˜ Sample Schemaλ₯Ό μΆ”κ°€ν•˜μ§€ μ•ŠλŠ” 경우 ν…ŒμŠ€νŠΈν•  수 μžˆλŠ” 데이터가 μ—†μŠ΅λ‹ˆλ‹€. μ˜€λΌν΄μ—μ„œ μ œκ³΅ν•΄μ£ΌλŠ” μƒ˜ν”Œ μŠ€ν‚€λ§ˆλ‘œ 6가지가 μžˆμŠ΅λ‹ˆλ‹€.

HR : Human Resource
OE : Order Entry
PM : Product Media
IX : Information Exchange
SH : Sales History
BI : Business Intelligence

 

ν•΄λ‹Ή κΈ€μ—μ„œλŠ” μœ„ 6개의 μƒ˜ν”Œ μŠ€ν‚€λ§ˆλ₯Ό μˆ˜λ™μœΌλ‘œ μƒμ„±ν•˜λŠ” 방법을 μ•Œλ €λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€.

 

 

Sample Schema 생성

μ‹€μŠ΅ν™˜κ²½

OS : Red Hat Enterprise Linux Server release 6.10
DB : Oracle 12.1.0.2
SID : testdb

 

 

μ•„λž˜ λ§ν¬λŠ” Oracle이 μš΄μ˜ν•˜λŠ” githubμž…λ‹ˆλ‹€. μƒ˜ν”Œ μŠ€ν‚€λ§ˆλ₯Ό λ§Œλ“€μ–΄μ£ΌλŠ” νŒŒμΌμ„ μ œκ³΅ν•˜λ‹ˆ 버전에 맞게 μ„€μΉ˜ ν›„ μž‘μ—… μ§„ν–‰ν•©λ‹ˆλ‹€.

 

Releases · oracle/db-sample-schemas

Oracle Database Sample Schemas. Contribute to oracle/db-sample-schemas development by creating an account on GitHub.

github.com

 

 

 

Oracle 12.1.0.2 버전을 μ‚¬μš©ν•˜μ—¬ μ‹€μŠ΅ μ§„ν–‰ν•˜λ‹ˆ tar.gz 파일둜 λ°›μ•„μ€λ‹ˆλ‹€. ν•΄λ‹Ή νŒŒμΌμ€ μ„œλ²„μ— μ λ‹Ήν•œ μœ„μΉ˜μ— λ„£μ–΄μ£ΌλŠ” κ²ƒμœΌλ‘œ μ‹€μŠ΅ μ€€λΉ„λ₯Ό λλƒ…λ‹ˆλ‹€.

 

 

생성 슀크립트 μ„€μ •

[testdb@host01 ~]$ tar xvfz db-sample-schemas-12.1.0.2.tar.gz
[testdb@host01 ~]$ cd db-sample-schemas-12.1.0.2
[testdb@host01 db-sample-schemas-12.1.0.2]$ cp -R ./* $ORACLE_HOME/demo/schema
[testdb@host01 db-sample-schemas-12.1.0.2]$ cd $ORACLE_HOME/demo/schema/

μ••μΆ•νŒŒμΌμ„ ν’€μ–΄μ£Όκ³  $ORACLE_HOME/demo/schema 경둜 μ•„λž˜ νŒŒμΌλ“€μ„ μ΄λ™μ‹œμΌœ μ€λ‹ˆλ‹€.

 

 

[testdb@host01 schema]$ vi mksample.sql

μƒ˜ν”Œ μŠ€ν‚€λ§ˆλ₯Ό μƒμ„±ν•˜κΈ° μœ„ν•΄ mksample.sqlμ΄λΌλŠ” νŒŒμΌμ„ μ‹€ν–‰ν• κ²λ‹ˆλ‹€. νŒŒμΌμ„ 열어보면 경둜둜 ν‘œμ‹œλ˜μ–΄μ•Όν•˜λŠ” 뢀뢄이 '__SUB__CWD__'둜 λ˜μ–΄μžˆμŠ΅λ‹ˆλ‹€. ν•΄λ‹Ή 뢀뢄을 λ³€κ²½ν•΄μ£ΌκΈ° μœ„ν•΄ λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•˜κ² μŠ΅λ‹ˆλ‹€.

 

[testdb@host01 schema]$ cd $ORACLE_HOME/demo/schema
[testdb@host01 schema]$ perl -p -i.bak -e 's#__SUB__CWD__#'$(pwd)'#g' *.sql */*.sql */*.dat

perl λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•΄μ„œ μž‘μ—…μ— ν•„μš”ν•œ νŒŒμΌλ“€ μ•ˆμ— '__SUB__CWD__'λ₯Ό ν˜„μž¬ μœ„μΉ˜ν•΄ μžˆλŠ” 경둜둜 λ³€κ²½ν•©λ‹ˆλ‹€. ν•΄λ‹Ή λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν• λ•ŒλŠ” κΌ­ $ORACLE_HOME/demo/schemaμ•„λž˜μ„œ μ‹€ν–‰ν•©λ‹ˆλ‹€.

 

 

생성 슀크립트 μ‹€ν–‰

생성 슀크립트λ₯Ό μ‹€ν–‰ν• λ•Œ λͺ‡κ°€μ§€ λ°μ΄ν„°λ² μ΄μŠ€μ˜ 정보λ₯Ό μ•Œκ³  μžˆμ–΄μ•Όν•©λ‹ˆλ‹€. μ‹€ν–‰μ‹œ systemκ³Ό sys의 λΉ„λ°€λ²ˆν˜Έλ₯Ό 물을것이고 생성할 μŠ€ν‚€λ§ˆμ˜ λΉ„λ°€λ²ˆν˜Έλ“€μ„ μ§€μ •ν•©λ‹ˆλ‹€. 이후 μ‚¬μš©ν•  Tablespace λͺ…, Temporary Tablespace λͺ…, 둜그 μœ„μΉ˜ 그리고 connection URL을 μž…λ ₯ν•΄μ€˜μ•Όν•©λ‹ˆλ‹€. multinenant ν™˜κ²½μ—μ„œλŠ” PDB둜 연결이 ν•„μš”ν•©λ‹ˆλ‹€.

 

ν…Œμ΄λΈ”μŠ€νŽ˜μ΄μŠ€ 생성
SYS@testdb> create tablespace examples
datafile '/u01/app/oracle/oradata/testdb/examples01.dbf' size 200m;

μ‚¬μš©ν•  ν…Œμ΄λΈ”μŠ€νŽ˜μ΄μŠ€λ₯Ό μƒμ„±ν•΄μ€λ‹ˆλ‹€.

 

SYS@testdb> select tablespace_name, contents from dba_tablespaces;

 

λ¦¬μŠ€λ„ˆ μ‹€ν–‰
[testdb@host01 ~]$ lsnrctl start
[testdb@host01 testdb]$ lsnrctl ser  

LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 15-JUL-2020 16:16:55

Copyright (c) 1991, 2014, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host01)(PORT=1521)))
Services Summary...
Service "testdb" has 1 instance(s).
  Instance "testdb", status READY, has 1 handler(s) for this service...
    Handler(s):
      "DEDICATED" established:48 refused:0 state:ready
         LOCAL SERVER
The command completed successfully

 

이지 컀λ„₯μ…˜μ„ ν†΅ν•΄μ„œν•˜λŠ” μž‘μ—…λ“€μ΄ μžˆμ–΄ λ¦¬μŠ€λ„ˆλ₯Ό μ‹€ν–‰μ‹œμΌœμ€λ‹ˆλ‹€.

 

ν•„μš”ν•œ 정보듀을 ν™•μΈν–ˆμœΌλ‹ˆ 이제 생성 슀크립트λ₯Ό μ‹€ν–‰ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.

 

 

SYS@testdb> @?/demo/schema/mksample.sql

specify password for SYSTEM as parameter 1:
Enter value for 1: oracle

specify password for SYS as parameter 2:
Enter value for 2: oracle

specify password for HR as parameter 3:
Enter value for 3: hr      

specify password for OE as parameter 4:
Enter value for 4: oe

specify password for PM as parameter 5:
Enter value for 5: pm

specify password for IX as parameter 6:
Enter value for 6: ix

specify password for  SH as parameter 7:
Enter value for 7: sh

specify password for  BI as parameter 8:
Enter value for 8: bi

specify default tablespace as parameter 9:
Enter value for 9: examples

specify temporary tablespace as parameter 10:
Enter value for 10: temp

specify log file directory (including trailing delimiter) as parameter 11:
Enter value for 11: $ORACLE_HOME/demo/schema/log/

specify connect string as parameter 12:
Enter value for 12: localhost:1521/testdb                       

Sample Schemas are being created ...

μŠ€ν‚€λ§ˆ 생성이 μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. μƒμ„±κ³Όμ •μ—μ„œ 각각 λ°μ΄ν„°λ² μ΄μŠ€ ν™˜κ²½μ—λ”°λΌ 생성이 μ•ˆλ˜κ±°λ‚˜ λˆ„λ½λ˜λŠ” 데이터가 생길 수 μžˆμŠ΅λ‹ˆλ‹€. ν…ŒμŠ€νŠΈμƒ κ°€μž₯ 많이 μ‚¬μš©ν•˜λŠ” HR μŠ€ν‚€λ§ˆλ₯Ό μ œμ™Έν•˜κ³ λŠ” μ‘°κΈˆμ”© λ¬Έμ œκ°€ μƒκΈ°λŠ” μŠ€ν‚€λ§ˆκ°€ μžˆμŠ΅λ‹ˆλ‹€. κ°„λ‹¨ν•œ μ‹€μŠ΅μ„ μœ„ν•΄μ„œ HR μŠ€ν‚€λ§ˆλ§Œ μžˆμ–΄λ„ λ¬Έμ œκ°€ μ•ˆλœλ‹€λ©΄ κ·ΈλŒ€λ‘œ μ‚¬μš©ν•˜κ±°λ‚˜ μ•„λž˜ λͺ…령을 ν†΅ν•΄μ„œ HRμŠ€ν‚€λ§ˆλ§Œ μƒμ„±ν•˜μ—¬ μ‚¬μš©ν•΄λ„λ©λ‹ˆλ‹€.

SYS@testdb> @?/demo/schema/human_resources/hr_main.sql
specify password for HR as parameter 1:
Enter value for 1: hr

specify default tablespeace for HR as parameter 2:
Enter value for 2: examples

specify temporary tablespace for HR as parameter 3:
Enter value for 3: temp

specify password for SYS as parameter 4:
Enter value for 4: oracle

specify log path as parameter 5:
Enter value for 5: $ORACLE_HOME/demo/schema/log/

specify connect string as parameter 6:
Enter value for 6: localhost:1521/testdb

 

 

μ—λŸ¬λ°œμƒμ—λŒ€ν•œ 뢀뢄은 μ„€μ •ν•œ λ‘œκ·ΈνŒŒμΌμ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

 

λŒ“κΈ€