简介
Oracle Database 21c 于8月13日发布,首先发布的是Linux版本,可以从官方网站下载。21c整合了原计划2020年发布的 20c 版本,原计划 2021年上半年发布,因为疫情等原因推迟了发布。而且据悉,22c 版本号可能取消,23c将是下一个可见版本。
下载
https://www.oracle.com/database/technologies/oracle-database-software-downloads.html
https://www.oracle.com/database/technologies/oracle21c-linux-downloads.html
https://www.oracle.com/downloads/
单实例只需要下载LINUX.X64_213000_db_home.zip
即可。
当然,我们本文不教大家如何安装Oracle。我们只需要看下面的内容即可!!!
一、从Docker Hub或阿里云镜像下载小麦苗上传的镜像文件
-
小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
-
Oracle 21c DB的地址:https://hub.docker.com/r/lhrbest/oracle21c_ee_db_21.3.0.0/tags
小麦苗的Docker Hub的地址:https://hub.docker.com/u/lhrbest
Oracle 21c DB的地址:https://hub.docker.com/r/lhrbest/oracle21c_ee_db_21.3.0.0/tags
1# 从Docker hub下载,网络不好时,一般比较慢
2docker pull lhrbest/oracle21c_ee_db_21.3.0.0
3# 可以选择从阿里云下载
4docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle21c_ee_db_21.3.0.0
5# 从阿里云下载后可以tag成如下形式
6docker tag registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle21c_ee_db_21.3.0.0 lhrbest/oracle21c_ee_db_21.3.0.0
镜像大概5.5G左右,解压后大约16G左右,所以请保留充足的空间。执行过程如下:
1[root@docker35 ~]# docker images | grep 21c
2lhrbest/oracle21c_ee_db_21.3.0.0 latest 86933671efb6 About an hour ago 16.3GB
3registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle21c_ee_db_21.3.0.0 latest 86933671efb6 About an hour ago 16.3GB
二、创建容器并启动数据库
1# 1、创建容器
2docker run -d --name lhroracle21c -h lhroracle21c \
3 -p 5510:5500 -p 55100:5501 -p 1530:1521 -p 3400:3389 \
4 -v /sys/fs/cgroup:/sys/fs/cgroup \
5 --privileged=true lhrbest/oracle21c_ee_db_21.3.0.0 \
6 /usr/sbin/init
7
8# 2、进入容器
9docker exec -it lhroracle21c bash
10
11
12# 3、启动监听和数据库
13su - oracle
14sas
15startup
16lsnrctl start
执行过程如下:
1[root@docker35 ~]# docker run -d --name lhroracle21c -h lhroracle21c \
2> -p 5510:5500 -p 55100:5501 -p 1530:1521 -p 3400:3389 \
3> -v /sys/fs/cgroup:/sys/fs/cgroup \
4> --privileged=true lhrbest/oracle21c_ee_db_21.3.0.0 \
5> /usr/sbin/init
6c5c16e24b308fb5120811e2e0edbeceb11a9a292ae991840097e63e385d6517f
7[root@docker35 ~]#
8[root@docker35 ~]# docker exec -it lhroracle21c bash
9[root@lhroracle21c /]# su - oracle
10Last login: Mon Aug 16 14:05:17 CST 2021 on pts/0
11[oracle@lhroracle21c ~]$ sas
12
13SQL*Plus: Release 21.0.0.0.0 - Production on Mon Aug 16 15:48:53 2021
14Version 21.3.0.0.0
15
16Copyright (c) 1982, 2021, Oracle. All rights reserved.
17
18Connected to an idle instance.
19
20SYS@LHRCDB> startup
21ORACLE instance started.
22
23Total System Global Area 859829400 bytes
24Fixed Size 9692312 bytes
25Variable Size 461373440 bytes
26Database Buffers 381681664 bytes
27Redo Buffers 7081984 bytes
28Database mounted.
29Database opened.
30SYS@LHRCDB> show pdbs
31
32 CON_ID CON_NAME OPEN MODE RESTRICTED
33---------- ------------------------------ ---------- ----------
34 2 PDB$SEED READ ONLY NO
35 3 PDB2 READ WRITE NO
36SYS@LHRCDB> exit
37Disconnected from Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
38Version 21.3.0.0.0
39[oracle@lhroracle21c ~]$ lsnrctl start
40
41LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 16-AUG-2021 15:50:54
42
43Copyright (c) 1991, 2021, Oracle. All rights reserved.
44
45Starting /u01/app/oracle/product/21c/dbhome_1/bin/tnslsnr: please wait...
46
47TNSLSNR for Linux: Version 21.0.0.0.0 - Production
48System parameter file is /u01/app/oracle/product/21c/dbhome_1/network/admin/listener.ora
49Log messages written to /u01/app/oracle/diag/tnslsnr/lhroracle21c/listener/alert/log.xml
50Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhroracle21c)(PORT=1521)))
51Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
52
53Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhroracle21c)(PORT=1521)))
54STATUS of the LISTENER
55------------------------
56Alias LISTENER
57Version TNSLSNR for Linux: Version 21.0.0.0.0 - Production
58Start Date 16-AUG-2021 15:50:54
59Uptime 0 days 0 hr. 0 min. 0 sec
60Trace Level off
61Security ON: Local OS Authentication
62SNMP OFF
63Listener Parameter File /u01/app/oracle/product/21c/dbhome_1/network/admin/listener.ora
64Listener Log File /u01/app/oracle/diag/tnslsnr/lhroracle21c/listener/alert/log.xml
65Listening Endpoints Summary...
66 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhroracle21c)(PORT=1521)))
67 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
68The listener supports no services
69The command completed successfully
三、尽情使用吧
3.1 数据库使用
1[oracle@lhroracle21c ~]$ lsnrctl status
2
3LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 16-AUG-2021 15:51:26
4
5Copyright (c) 1991, 2021, Oracle. All rights reserved.
6
7Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lhroracle21c)(PORT=1521)))
8STATUS of the LISTENER
9------------------------
10Alias LISTENER
11Version TNSLSNR for Linux: Version 21.0.0.0.0 - Production
12Start Date 16-AUG-2021 15:50:54
13Uptime 0 days 0 hr. 0 min. 31 sec
14Trace Level off
15Security ON: Local OS Authentication
16SNMP OFF
17Listener Parameter File /u01/app/oracle/product/21c/dbhome_1/network/admin/listener.ora
18Listener Log File /u01/app/oracle/diag/tnslsnr/lhroracle21c/listener/alert/log.xml
19Listening Endpoints Summary...
20 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=lhroracle21c)(PORT=1521)))
21 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
22 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhroracle21c)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/LHRCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
23Services Summary...
24Service "LHRCDB" has 1 instance(s).
25 Instance "LHRCDB", status READY, has 1 handler(s) for this service...
26Service "LHRCDBXDB" has 1 instance(s).
27 Instance "LHRCDB", status READY, has 1 handler(s) for this service...
28Service "c9a73ae76f543a73e0530e0011acc4b4" has 1 instance(s).
29 Instance "LHRCDB", status READY, has 1 handler(s) for this service...
30Service "pdb2" has 1 instance(s).
31 Instance "LHRCDB", status READY, has 1 handler(s) for this service...
32The command completed successfully
33
34[oracle@lhroracle21c ~]$ sas
35
36SQL*Plus: Release 21.0.0.0.0 - Production on Mon Aug 16 16:12:35 2021
37Version 21.3.0.0.0
38
39Copyright (c) 1982, 2021, Oracle. All rights reserved.
40
41
42Connected to:
43Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
44Version 21.3.0.0.0
45
46SYS@LHRCDB> show pdbs
47
48 CON_ID CON_NAME OPEN MODE RESTRICTED
49---------- ------------------------------ ---------- ----------
50 2 PDB$SEED READ ONLY NO
51 3 PDB2 READ WRITE NO
52SYS@LHRCDB>
53
54
55SYS@LHRCDB> create pluggable database xmmup admin user lhr identified by lhr ROLES = (dba)
56 2 file_name_convert=('/u01/app/oracle/oradata/LHRCDB/pdbseed/','/u01/app/oracle/oradata/CDBLHR/xmmup/');
57
58Pluggable database created.
59
60SYS@LHRCDB> show pdbs
61
62 CON_ID CON_NAME OPEN MODE RESTRICTED
63---------- ------------------------------ ---------- ----------
64 2 PDB$SEED READ ONLY NO
65 3 PDB2 READ WRITE NO
66 4 XMMUP MOUNTED
67SYS@LHRCDB> alter pluggable database xmmup open;
68
69Pluggable database altered.
70
71SYS@LHRCDB> show pdbs
72
73 CON_ID CON_NAME OPEN MODE RESTRICTED
74---------- ------------------------------ ---------- ----------
75 2 PDB$SEED READ ONLY NO
76 3 PDB2 READ WRITE NO
77 4 XMMUP READ WRITE NO
3.2 创建数据库
我们也可以自己创建自己需要的数据库,如下所示,创建了一个cdb的数据库,dbname和sid都是lhrdb:
1dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
2-gdbname lhrdb -sid lhrdb \
3-createAsContainerDatabase TRUE \
4-numberOfPDBs 1 \
5-pdbName pdb2 \
6-pdbAdminPassword lhr \
7-sysPassword lhr -systemPassword lhr \
8-datafileDestination '/u01/app/oracle/oradata' \
9-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
10-redoLogFileSize 50 \
11-storageType FS \
12-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
13-totalMemory 1024 \
14-databaseType OLTP \
15-emConfiguration NONE
需要注意的是,Oracle 21c不再支持非cdb的库了。
1[FATAL] [DBT-10333] Container database (CDB) creation option is not selected.
2 CAUSE: Non-CDB creation is not supported.
3 ACTION: Make sure container database (CDB) option is selected.
4[oracle@lhroracle21c ~]$ oerr dbt 10333
510333, 0,"Container database (CDB) creation option is not selected."
6// *Cause: Non-CDB creation is not supported.
7// *Action: Make sure container database (CDB) option is selected.
8// *FQN: oracle.assistants.dbca.resource.DBCAErrorCode.NON_CDB_CREATION_NOT_SUPPORTED_ERR
3.3 EMDE的使用
这个镜像默认配置了EM,端口为5500,所以EM的访问地址为:https://192.168.1.35:5500/em
1[oracle@lhroracle21c ~]$ lsnrctl status | grep tcps
2 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhroracle21c)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/LHRCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
image-20210816160842275
用户名:sys
密码:lhr
登陆界面为18c,但是登录进去后依然是21c。
3.4 外部客户端连接容器内的数据库
我们可以在容器外部通过sqlplus或其他工具连接容器内的数据库,注意此时的端口应该为1530:
1C:\Users\lhrxxt>sqlplus sys/lhr@192.168.1.35:1530/LHRCDB as sysdba
2
3SQL*Plus: Release 12.1.0.2.0 Production on Mon Aug 16 16:16:48 2021
4
5Copyright (c) 1982, 2014, Oracle. All rights reserved.
6
7
8Connected to:
9Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
10
11SYS@192.168.1.35:1530/LHRCDB> show pdbs
12
13 CON_ID CON_NAME OPEN MODE RESTRICTED
14---------- ------------------------------ ---------- ----------
15 2 PDB$SEED READ ONLY NO
16 3 PDB2 READ WRITE NO
17 4 XMMUP READ WRITE NO
18SYS@192.168.1.35:1530/LHRCDB>
如果使用PLSQL Developer也是可以连接的,如下:
image-20210816162007647
其它版本环境的创建
参考:https://www.xmmup.com/dbbao37zaidockerzhongkuaisushiyonggegebanbencong10gdao19cdeoracleshu.html
怎么样,是不是很爽,是不是非常方便呢,文末记得点赞哈。