Docker Run Oracle DB 18c XE: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 132: Line 132:
ALTER session SET container=XEPDB1;
ALTER session SET container=XEPDB1;
ALTER profile DEFAULT limit password_life_time UNLIMITED;
ALTER profile DEFAULT limit password_life_time UNLIMITED;
SELECT name, con_id, open_mode FROM v$pdbs;
SELECT name as "Service Name" FROM v$active_services WHERE con_id = 3;
CONNECT / as sysdba
ALTER session SET container=XEPDB1;
ALTER PLUGGABLE DATABASE open;
ALTER USER hr IDENTIFIED BY hr ACCOUNT UNLOCK;
-- cl scr
-- cdb => container database
-- pdb => pluggable database
SHOW con_name;
COLUMN name FORMAT a20;
SELECT name, con_id, open_mode FROM v$pdbs;
SELECT name as "Service Name" FROM v$active_services WHERE con_id = 3;
</source>
<source lang="bash">
lsnrctl reload
: <<'END_COMMENT'
LSNRCTL for 64-bit Windows: Version 18.0.0.0.0 - Production on 19-DEC-2020 21:03:42
Copyright (c) 1991, 2018, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=pc00)(PORT=1521)))
The command completed successfully
END_COMMENT
</source>
<source lang="sql">
CONNECT / as sysdba
ALTER session SET container=XEPDB1;
SHOW con_name;
COLUMN name FORMAT a20;
SELECT name, con_id, open_mode FROM v$pdbs;
ALTER PLUGGABLE DATABASE open; -- if open_mode is mounted
SELECT name, con_id, open_mode FROM v$pdbs; -- check again
ALTER USER hr IDENTIFIED BY hr ACCOUNT UNLOCK; -- unlock user if open_mode is read, write
CONNECT hr/hr@xepdb1
</source>
</source>



Revision as of 07:20, 19 December 2020

Linux:
export ORACLE_HOME=/srv/oracle
MacOS:
export ORACLE_HOME=$HOME/oracle

Build

cd $ACADEMIA_WSS/unix/dokr_wss/
mkdir academia-dokr-ora18c
cd academia-dokr-ora18c/

git clone https://github.com/oracle/docker-images.git .
cd OracleDatabase/SingleInstance/dockerfiles/
./buildDockerImage.sh -v 18.4.0 -x

Run

docker run --detach \
--name oracle18c \
--publish 1521:1521 \
--publish 5500:5500 \
--env ORACLE_PWD=oracle \
--env ORACLE_CHARACTERSET=AL32UTF8 \
oracle/database:18.4.0-xe

With Volumes

Local location Container location Usage
$ORACLE_HOME/oracle18c/oradata /opt/oracle/oradata Oracle 18c XE Data
$ORACLE_HOME/oracle18c/scripts/setup /opt/oracle/scripts/setup Setup Scripts
$ORACLE_HOME/oracle18c/scripts/startup /opt/oracle/scripts/startup Startup Scripts
docker run --detach \
--name oracle18c \
--publish 1521:1521 \
--publish 5500:5500 \
--env ORACLE_PWD=oracle \
--env ORACLE_CHARACTERSET=AL32UTF8 \
--volume $ORACLE_HOME/oracle18c/oradata:/opt/oracle/oradata \
--volume $ORACLE_HOME/oracle18c/scripts/setup:/opt/oracle/scripts/setup \
--volume $ORACLE_HOME/oracle18c/scripts/startup:/opt/oracle/scripts/startup \
oracle/database:18.4.0-xe

With Volumes And Network

docker network ls
docker network create oracle_network
docker run --detach \
--name oracle18c \
--publish 1521:1521 \
--publish 5500:5500 \
--env ORACLE_PWD=oracle \
--env ORACLE_CHARACTERSET=AL32UTF8 \
--volume $ORACLE_HOME/oracle18c/oradata:/opt/oracle/oradata \
--volume $ORACLE_HOME/oracle18c/scripts/setup:/opt/oracle/scripts/setup \
--volume $ORACLE_HOME/oracle18c/scripts/startup:/opt/oracle/scripts/startup \
--network oracle_network \
oracle/database:18.4.0-xe

SQL Plus

Docker

XEPDB1: (pluggable)
───────────────────
docker exec -it --user=oracle oracle18c bash
sqlplus sys@XEPDB1 as sysdba
sho con_name
CDB$ROOT:
─────────
docker exec -it --user=oracle oracle18c bash
sqlplus sys@XE as sysdba
sho con_name
Direct SQLPlus:
───────────────
docker exec -it --user=oracle oracle18c sqlplus sys@XEPDB1 as sysdba
docker exec -it --user=oracle oracle18c sqlplus sys@XE as sysdba

Remote

sqlplus sys/oracle@//10.19.83.10:1521/XE as sysdba
sqlplus sys/oracle@//10.19.83.10:1521/XEPDB1 as sysdba

Query

DESC V$DATABASE;
SELECT DBID, NAME, CREATED FROM V$DATABASE;
SELECT USERNAME AS "SCHEMA_NAME" FROM SYS.ALL_USERS ORDER BY USERNAME;
SELECT USERNAME AS "SCHEMA_NAME" FROM SYS.DBA_USERS ORDER BY USERNAME;
-- docker exec -it --user=oracle oracle18c sqlplus sys@XE as sysdba
ALTER SESSION SET "_oracle_script"=true;
CREATE USER academia_dev IDENTIFIED BY academia_dev;
GRANT CONNECT, RESOURCE, DBA TO academia_dev;
-- docker exec -it --user=oracle oracle18c sqlplus academia_dev@XE
SELECT COUNT(tname) FROM tab;

Apex

tnsping XE
sqlplus /nolog
CONNECT / as sysdba
SHOW parameter pga
SHOW parameter sga_target

SELECT name FROM v$containers;
ALTER session SET container=XEPDB1;
ALTER profile DEFAULT limit password_life_time UNLIMITED;

SELECT name, con_id, open_mode FROM v$pdbs;
SELECT name as "Service Name" FROM v$active_services WHERE con_id = 3;

CONNECT / as sysdba
ALTER session SET container=XEPDB1;
ALTER PLUGGABLE DATABASE open;
ALTER USER hr IDENTIFIED BY hr ACCOUNT UNLOCK;

-- cl scr
-- cdb => container database
-- pdb => pluggable database
SHOW con_name;
COLUMN name FORMAT a20;
SELECT name, con_id, open_mode FROM v$pdbs;
SELECT name as "Service Name" FROM v$active_services WHERE con_id = 3;
lsnrctl reload
: <<'END_COMMENT'
LSNRCTL for 64-bit Windows: Version 18.0.0.0.0 - Production on 19-DEC-2020 21:03:42

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=pc00)(PORT=1521)))
The command completed successfully
END_COMMENT
CONNECT / as sysdba
ALTER session SET container=XEPDB1;
SHOW con_name;
COLUMN name FORMAT a20;
SELECT name, con_id, open_mode FROM v$pdbs;
ALTER PLUGGABLE DATABASE open; -- if open_mode is mounted

SELECT name, con_id, open_mode FROM v$pdbs; -- check again
ALTER USER hr IDENTIFIED BY hr ACCOUNT UNLOCK; -- unlock user if open_mode is read, write
CONNECT hr/hr@xepdb1

Good To Know

docker logs oracle18c
docker stop oracle18c
docker start oracle18c
docker restart oracle18c
docker exec -it oracle18c /bin/bash
docker exec -it --user=oracle oracle18c bash
docker network ls
docker network create oracle_network
docker-machine create --driver virtualbox default
docker-machine start default
docker-machine stop default
docker-machine ip default
docker-machine ls
docker run --detach \
--name oracle11g \
--publish 1521:1521 \
--publish 8090:8080 \
--env ORACLE_ENABLE_XDB=true \
--env ORACLE_ALLOW_REMOTE=true \
wnameless/oracle-xe-11g-r2:latest

References