forked from gvenzl/oci-oracle-xe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.1840.sh
executable file
·1118 lines (870 loc) · 45.8 KB
/
install.1840.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Since: February, 2021
# Author: gvenzl
# Name: install.1840.sh
# Description: Install script for Oracle DB XE 18.4.0
#
# Copyright 2021 Gerald Venzl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Exit on errors
# Great explanation on https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
echo "BUILDER: started"
# Build mode ("SLIM", "REGULAR", "FULL")
BUILD_MODE=${1:-"REGULAR"}
echo "BUILDER: BUILD_MODE=${BUILD_MODE}"
# Set data file sizes
CDB_SYSAUX_SIZE=480
PDB_SYSAUX_SIZE=342
CDB_SYSTEM_SIZE=840
PDB_SYSTEM_SIZE=255
if [ "${BUILD_MODE}" == "REGULAR" ]; then
REDO_SIZE=20
USERS_SIZE=10
CDB_TEMP_SIZE=10
# CDB_SYSAUX_SIZE=464
elif [ "${BUILD_MODE}" == "SLIM" ]; then
REDO_SIZE=10
USERS_SIZE=2
CDB_TEMP_SIZE=2
# CDB_SYSAUX_SIZE=464
fi;
echo "BUILDER: Installing OS dependencies"
# Install installation dependencies
microdnf -y install bc binutils file elfutils-libelf ksh sysstat procps-ng smartmontools make net-tools hostname
# Install runtime dependencies
microdnf -y install libnsl glibc libaio libgcc libstdc++
# Install fortran runtime for libora_netlib.so (so that the Intel Math Kernel libraries are no longer needed)
if [ "${BUILD_MODE}" == "REGULAR" ] || [ "${BUILD_MODE}" == "SLIM" ]; then
microdnf -y install compat-libgfortran-48
fi;
# Install container runtime specific packages
# (used by the entrypoint script, not the database itself)
microdnf -y install unzip gzip
##############################################
###### Install and configure Database ########
##############################################
echo "BUILDER: installing database binaries"
# Install Oracle XE
rpm -iv --nodeps /install/oracle-database-xe-18c-1.0-1.x86_64.rpm
# Set 'oracle' user home directory to ${ORACE_BASE}
usermod -d ${ORACLE_BASE} oracle
# Add listener port and skip validations to conf file
sed -i "s/LISTENER_PORT=/LISTENER_PORT=1521/g" /etc/sysconfig/oracle-xe-18c.conf
sed -i "s/SKIP_VALIDATIONS=false/SKIP_VALIDATIONS=true/g" /etc/sysconfig/oracle-xe-18c.conf
# Disable netca to avoid "No IP address found" issue
mv "${ORACLE_HOME}"/bin/netca "${ORACLE_HOME}"/bin/netca.bak
echo "exit 0" > "${ORACLE_HOME}"/bin/netca
chmod a+x "${ORACLE_HOME}"/bin/netca
echo "BUILDER: configuring database"
# Set random password
ORACLE_PASSWORD=$(date '+%s' | sha256sum | base64 | head -c 8)
(echo "${ORACLE_PASSWORD}"; echo "${ORACLE_PASSWORD}";) | /etc/init.d/oracle-xe-18c configure
# Stop unconfigured listener
su -p oracle -c "lsnrctl stop"
# Re-enable netca
mv "${ORACLE_HOME}"/bin/netca.bak "${ORACLE_HOME}"/bin/netca
echo "BUILDER: post config database steps"
############################
### Create network files ###
############################
echo "BUILDER: creating network files"
# listener.ora
echo \
"LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_${ORACLE_SID}))
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = ${ORACLE_SID}" > "${ORACLE_HOME}"/network/admin/listener.ora
# tnsnames.ora
echo \
"${ORACLE_SID} =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ${ORACLE_SID})
)
)
${ORACLE_SID}PDB1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ${ORACLE_SID}PDB1)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_${ORACLE_SID}))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
" > "${ORACLE_HOME}"/network/admin/tnsnames.ora
# sqlnet.ora
echo "NAMES.DIRECTORY_PATH = (EZCONNECT, TNSNAMES)" > "${ORACLE_HOME}"/network/admin/sqlnet.ora
chown -R oracle:dba "${ORACLE_HOME}"/network/admin
# Start listener
su -p oracle -c "lsnrctl start"
####################
### bash_profile ###
####################
# Create .bash_profile for oracle user
echo "BUILDER: creating .bash_profile"
echo \
"export ORACLE_BASE=${ORACLE_BASE}
export ORACLE_HOME=\${ORACLE_BASE}/product/18c/dbhomeXE
export ORACLE_SID=XE
export PATH=\${PATH}:\${ORACLE_HOME}/bin:\${ORACLE_BASE}
" >> "${ORACLE_BASE}"/.bash_profile
chown oracle:dba "${ORACLE_BASE}"/.bash_profile
# Perform further Database setup operations
echo "BUILDER: changing database configuration and parameters for all images"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Enable remote HTTP access
EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
-- Disable common_user_prefix (needed for OS authenticated user)
ALTER SYSTEM SET COMMON_USER_PREFIX='' SCOPE=SPFILE;
-- Disable controlfile splitbrain check
-- Like with every underscore parameter, DO NOT SET THIS PARAMETER EVER UNLESS YOU KNOW WHAT THE HECK YOU ARE DOING!
ALTER SYSTEM SET "_CONTROLFILE_SPLIT_BRAIN_CHECK"=FALSE;
-- Remove local_listener entry (using default 1521)
ALTER SYSTEM SET LOCAL_LISTENER='';
-- Reboot of DB
SHUTDOWN IMMEDIATE;
STARTUP;
-- Setup healthcheck user
CREATE USER OPS\$ORACLE IDENTIFIED EXTERNALLY;
GRANT CONNECT, SELECT_CATALOG_ROLE TO OPS\$ORACLE;
exit;
EOF
###################################
######## FULL INSTALL DONE ########
###################################
# If not building the FULL image, remove and shrink additional components
if [ "${BUILD_MODE}" == "REGULAR" ] || [ "${BUILD_MODE}" == "SLIM" ]; then
echo "BUILDER: further optimizations for REGULAR and SLIM image"
# Open PDB\$SEED to READ/WRITE
echo "BUILDER: Opening PDB\$SEED in READ/WRITE mode"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Open PDB\$SEED to READ WRITE mode
ALTER PLUGGABLE DATABASE PDB\$SEED CLOSE;
ALTER PLUGGABLE DATABASE PDB\$SEED OPEN READ WRITE;
exit;
EOF
# Change parameters/settings
echo "BUILDER: changing database configuration and parameters for REGULAR and SLIM images"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Deactivate Intel's Math Kernel Libraries
-- Like with every underscore parameter, DO NOT SET THIS PARAMETER EVER UNLESS YOU KNOW WHAT THE HECK YOU ARE DOING!
ALTER SYSTEM SET "_dmm_blas_library"='libora_netlib.so' SCOPE=SPFILE;
-- Disable shared servers (enables faster shutdown)
ALTER SYSTEM SET SHARED_SERVERS=0;
-------------------------------------
-- Disable password profile checks --
-------------------------------------
-- Disable password profile checks (can only be done container by container)
ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
ALTER SESSION SET CONTAINER=PDB\$SEED;
ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
ALTER SESSION SET CONTAINER=XEPDB1;
ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
-------------------------------
-- Remove HR schema from PDB --
-------------------------------
ALTER SESSION SET CONTAINER=XEPDB1;
DROP user HR cascade;
exit;
EOF
########################
# Remove DB components #
########################
# Needs to be run as 'oracle' user (Perl script otherwise fails #TODO: see whether it can be run with su -c somehow instead)
echo "BUILDER: Removing additional components for REGULAR image"
su - oracle << EOF
cd "${ORACLE_HOME}"/rdbms/admin
# Remove Workspace Manager
echo "BUILDER: Removing Oracle Workspace Manager"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -C 'CDB\$ROOT' -b builder_remove_workspace_manager_pdbs -d "${ORACLE_HOME}"/rdbms/admin owmuinst.plb
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_workspace_manager_cdb -d "${ORACLE_HOME}"/rdbms/admin owmuinst.plb
echo "BUILDER: Removing Oracle Multimedia"
# Remove Multimedia (dependent on Oracle Database Java Packages)
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -C 'CDB\$ROOT' -b builder_remove_multimedia_pdbs -d "${ORACLE_HOME}"/ord/im/admin imremdo.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_multimedia_cdb -d "${ORACLE_HOME}"/ord/im/admin imremdo.sql
# Remove Oracle Database Java Packages
echo "BUILDER: Removing Oracle Database Java Packages"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_remove_java_packages -d "${ORACLE_HOME}"/rdbms/admin catnojav.sql
# Remove Oracle XDK
echo "BUILDER: Removing Oracle XDK"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_remove_xdk -d "${ORACLE_HOME}"/xdk/admin rmxml.sql
# Remove Oracle JServer JAVA Virtual Machine
echo "BUILDER: Removing Oracle JServer JAVA Virtual Machine"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_remove_jvm -d "${ORACLE_HOME}"/javavm/install rmjvm.sql
# Remove Oracle OLAP API
echo "BUILDER: Removing Oracle OLAP API"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -C 'CDB\$ROOT' -b builder_remove_olap_api_pdbs_1 -d "${ORACLE_HOME}"/olap/admin/ olapidrp.plb
# Needs to be done one by one, otherwise there is a ORA-65023: active transaction exists in container PDB\$SEED
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'PDB\$SEED' -b builder_remove_olap_api_pdbseed_2 -d "${ORACLE_HOME}"/olap/admin/ catnoxoq.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'XEPDB1' -b builder_remove_olap_api_xepdb1_2 -d "${ORACLE_HOME}"/olap/admin/ catnoxoq.sql
# Remove it from the CDB
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_olap_api_cdb_1 -d "${ORACLE_HOME}"/olap/admin/ olapidrp.plb
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_olap_api_cdb_2 -d "${ORACLE_HOME}"/olap/admin/ catnoxoq.sql
# Remove OLAP Analytic Workspace
echo "BUILDER: Removing OLAP Analytic Workspace"
# Needs to be done one by one, otherwise there is a ORA-65023: active transaction exists in container PDB\$SEED
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'PDB\$SEED' -b builder_remove_olap_workspace_pdb_seed -d "${ORACLE_HOME}"/olap/admin/ catnoaps.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'XEPDB1' -b builder_remove_olap_workspace_xepdb1 -d "${ORACLE_HOME}"/olap/admin/ catnoaps.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_olap_workspace_cdb -d "${ORACLE_HOME}"/olap/admin/ catnoaps.sql
# Recompile
echo "BUILDER: Recompiling database objects"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_recompile_all_objects -d "${ORACLE_HOME}"/rdbms/admin utlrp.sql
# Remove all log files
rm "${ORACLE_HOME}"/rdbms/admin/builder_*
exit;
EOF
# Drop leftover items
echo "BUILDER: Dropping leftover Database dictionary objects for REGULAR image"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Oracle Multimedia leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORD_ADMIN');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORDIMDPCALLOUTS');
-- Open PDB\$SEED to READ WRITE mode (catcon put it into READY ONLY again)
ALTER PLUGGABLE DATABASE PDB\$SEED CLOSE;
ALTER PLUGGABLE DATABASE PDB\$SEED OPEN READ WRITE;
ALTER SESSION SET CONTAINER=PDB\$SEED;
-- Remove Java VM leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE JAVAVM_SYS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE JVMRJBCINV');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE DBMS_JAVA_MISC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE OJDS_CONTEXT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$NODE_NUMBER\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$BINDINGS\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$INODE\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$ATTRIBUTES\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$REFADDR\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$PERMISSIONS\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$SHARED\$OBJ\$SEQ\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$SHARED\$OBJ\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP TRIGGER OJDS\$ROLE_TRIGGER\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER OJVMSYS');
-- Oracle Multimedia leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORD_ADMIN');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORDIMDPCALLOUTS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_COLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_STILLIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_AVERAGECOLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_COLORHISTOGRAM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_POSITIONALCOLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_TEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FEATURELIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDAUDIO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDVIDEO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDOC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDIMAGESIGNATURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDICOM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDATASOURCE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDPLSGWYUTIL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKSTILLIMAGE1');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKSTILLIMAGE2');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORA_SI_MKSTILLIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_CHGCONTENT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_CONVERTFORMAT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTHMBNL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETSIZEDTHMBNL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCONTENT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCONTENTLNGTH');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETHEIGHT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETWIDTH');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETFORMAT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKRGBCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_ARRAYCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_APPENDCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDPSTNLCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYPSTNLCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDTEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYTEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKFTRLIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETAVGCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETCLRHSTGRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETPSTNLCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETTEXTUREFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETAVGCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETAVGCLRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCLRHSTGRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCLRHSTGRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETPSTNLCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETPSTNLCLRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTEXTUREFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTEXTUREFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYFTRLIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DICOM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DICOM_ADMIN');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_IMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_AUDIO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_VIDEO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DOC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DBRELEASE_DOCS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENTS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENT_TYPES');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_CONSTRAINT_NAMES');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENT_REFS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_CONFORMANCE_VLD_MSGS');
ALTER SESSION SET CONTAINER=XEPDB1;
-- Remove Java VM leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE JAVAVM_SYS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE JVMRJBCINV');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE DBMS_JAVA_MISC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE OJDS_CONTEXT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$NODE_NUMBER\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$BINDINGS\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$INODE\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$ATTRIBUTES\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$REFADDR\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$PERMISSIONS\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$SHARED\$OBJ\$SEQ\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP SYNONYM OJDS\$SHARED\$OBJ\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP TRIGGER OJDS\$ROLE_TRIGGER\$');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER OJVMSYS');
-- Oracle Multimedia leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORD_ADMIN');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE SYS.ORDIMDPCALLOUTS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_COLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_STILLIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_AVERAGECOLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_COLORHISTOGRAM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_POSITIONALCOLOR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_TEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FEATURELIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDAUDIO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDVIDEO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDOC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDIMAGESIGNATURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDICOM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDATASOURCE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDPLSGWYUTIL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKSTILLIMAGE1');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKSTILLIMAGE2');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORA_SI_MKSTILLIMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_CHGCONTENT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_CONVERTFORMAT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTHMBNL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETSIZEDTHMBNL');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCONTENT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCONTENTLNGTH');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETHEIGHT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETWIDTH');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETFORMAT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKRGBCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYAVGCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_ARRAYCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_APPENDCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYCLRHSTGR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDPSTNLCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYPSTNLCLR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_FINDTEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYTEXTURE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_MKFTRLIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETAVGCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETCLRHSTGRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETPSTNLCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SETTEXTUREFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETAVGCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETAVGCLRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCLRHSTGRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETCLRHSTGRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETPSTNLCLRFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETPSTNLCLRFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTEXTUREFTR');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_GETTEXTUREFTRW');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM SI_SCOREBYFTRLIST');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DICOM');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DICOM_ADMIN');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_IMAGE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_AUDIO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_VIDEO');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORD_DOC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DBRELEASE_DOCS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENTS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENT_TYPES');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_CONSTRAINT_NAMES');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_DOCUMENT_REFS');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM ORDDCM_CONFORMANCE_VLD_MSGS');
exit;
EOF
####################################
# SLIM Image: Remove DB components #
####################################
if [ "${BUILD_MODE}" == "SLIM" ]; then
# Needs to be run as 'oracle' user (Perl script otherwise fails #TODO: see whether it can be run with su -c somehow instead)
echo "BUILDER: Removing additional components for SLIM image"
su - oracle << EOF
cd "${ORACLE_HOME}"/rdbms/admin
# Remove Oracle Text
echo "BUILDER: Removing Oracle Text"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_remove_text_pdbs -C 'CDB\$ROOT' -d "${ORACLE_HOME}"/ctx/admin catnoctx.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_remove_text_cdb -c 'CDB\$ROOT' -d "${ORACLE_HOME}"/ctx/admin catnoctx.sql
# Remove Spatial
echo "BUILDER: Removing Oracle Spatial"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -C 'CDB\$ROOT' -b builder_remove_spatial_pdbs -d "${ORACLE_HOME}"/md/admin mddins.sql
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -c 'CDB\$ROOT' -b builder_remove_spatial_cdb -d "${ORACLE_HOME}"/md/admin mddins.sql
# Recompile
echo "BUILDER: Recompiling database objects"
"${ORACLE_HOME}"/perl/bin/perl catcon.pl -n 1 -b builder_recompile_all_objects -d "${ORACLE_HOME}"/rdbms/admin utlrp.sql
# Remove all log files
rm "${ORACLE_HOME}"/rdbms/admin/builder_*
exit;
EOF
# Drop leftover items
echo "BUILDER: Dropping leftover Database dictionary objects for SLIM image"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Oracle Text leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE XDB.XDB_DATASTORE_PROC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE XDB.DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE SYS.VALIDATE_CONTEXT');
-- Remove Spatial leftover components
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER MDDATA CASCADE');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER MDSYS CASCADE');
-- Open PDB\$SEED to READ WRITE mode (catcon put it into READY ONLY again)
ALTER PLUGGABLE DATABASE PDB\$SEED CLOSE;
ALTER PLUGGABLE DATABASE PDB\$SEED OPEN READ WRITE;
ALTER SESSION SET CONTAINER=PDB\$SEED;
-- Oracle Text leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE XDB.XDB_DATASTORE_PROC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE XDB.DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE SYS.VALIDATE_CONTEXT');
-- Remove Spatial leftover components
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER MDDATA CASCADE');
ALTER SESSION SET CONTAINER=XEPDB1;
-- Oracle Text leftovers
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE XDB.XDB_DATASTORE_PROC');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PUBLIC SYNONYM DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PACKAGE XDB.DBMS_XDBT');
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP PROCEDURE SYS.VALIDATE_CONTEXT');
-- Remove Spatial leftover components
exec DBMS_PDB.EXEC_AS_ORACLE_SCRIPT('DROP USER MDDATA CASCADE');
exit;
EOF
fi;
#####################
# Shrink data files #
#####################
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
----------------------------
-- Shrink SYSAUX tablespaces
----------------------------
-- Create new temporary SYSAUX tablespace
--CREATE TABLESPACE SYSAUX_TEMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux_temp.dbf'
--SIZE 250M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;
-- Move tables to temporary SYSAUX tablespace
--#TODO
--BEGIN
-- FOR cur IN (SELECT owner || '.' || table_name AS name FROM all_tables WHERE tablespace_name = 'SYSAUX') LOOP
-- EXECUTE IMMEDIATE 'ALTER TABLE ' || cur.name || ' MOVE TABLESPACE SYSAUX_TEMP';
-- END LOOP;
--END;
--/
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux01.dbf' RESIZE ${CDB_SYSAUX_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/sysaux01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=PDB\$SEED;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/sysaux01.dbf' RESIZE ${PDB_SYSAUX_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/sysaux01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=XEPDB1;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/sysaux01.dbf' RESIZE ${PDB_SYSAUX_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/sysaux01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=CDB\$ROOT;
----------------------------
-- Shrink SYSTEM tablespaces
----------------------------
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/system01.dbf' RESIZE ${CDB_SYSTEM_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/system01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=PDB\$SEED;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/system01.dbf' RESIZE ${PDB_SYSTEM_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/system01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=XEPDB1;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/system01.dbf' RESIZE ${PDB_SYSTEM_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/system01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=CDB\$ROOT;
--------------------------
-- Shrink TEMP tablespaces
--------------------------
ALTER TABLESPACE TEMP SHRINK SPACE;
ALTER DATABASE TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/temp01.dbf' RESIZE ${CDB_TEMP_SIZE}M;
ALTER DATABASE TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/temp01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
--------------------------------------
ALTER SESSION SET CONTAINER=PDB\$SEED;
--------------------------------------
CREATE TEMPORARY TABLESPACE TEMP_TMP TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/temp_tmp.dbf'
SIZE 2M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP_TMP;
DROP TABLESPACE TEMP INCLUDING CONTENTS AND DATAFILES;
CREATE TEMPORARY TABLESPACE TEMP TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/temp01.dbf'
SIZE 2M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP;
DROP TABLESPACE TEMP_TMP INCLUDING CONTENTS AND DATAFILES;
-----------------------------------
ALTER SESSION SET CONTAINER=XEPDB1;
-----------------------------------
ALTER TABLESPACE TEMP SHRINK SPACE;
ALTER DATABASE TEMPFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/temp01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=CDB\$ROOT;
----------------------------
-- Shrink USERS tablespaces
----------------------------
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/users01.dbf' RESIZE ${USERS_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/users01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=XEPDB1;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/users01.dbf' RESIZE ${USERS_SIZE}M;
ALTER DATABASE DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/users01.dbf'
AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
ALTER SESSION SET CONTAINER=CDB\$ROOT;
----------------------------
-- Shrink UNDO tablespaces
----------------------------
-- Create new temporary UNDO tablespace
CREATE UNDO TABLESPACE UNDO_TMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/undotbs_tmp.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use new temporary UNDO tablespace (so that old one can be deleted)
ALTER SYSTEM SET UNDO_TABLESPACE='UNDO_TMP';
-- Delete old UNDO tablespace
DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
-- Recreate old UNDO tablespace with 1M size and AUTOEXTEND
CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/undotbs01.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use newly created UNDO tablespace
ALTER SYSTEM SET UNDO_TABLESPACE='UNDOTBS1';
-- Drop temporary UNDO tablespace
DROP TABLESPACE UNDO_TMP INCLUDING CONTENTS AND DATAFILES;
--------------------------------------
ALTER SESSION SET CONTAINER=PDB\$SEED;
--------------------------------------
-- Create new temporary UNDO tablespace
CREATE UNDO TABLESPACE UNDO_TMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/undotbs_tmp.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use new temporary UNDO tablespace (so that old one can be deleted)
ALTER SYSTEM SET UNDO_TABLESPACE='UNDO_TMP';
-- Delete old UNDO tablespace
DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
-- Recreate old UNDO tablespace with 1M size and AUTOEXTEND
CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/pdbseed/undotbs01.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use newly created UNDO tablespace
ALTER SYSTEM SET UNDO_TABLESPACE='UNDOTBS1';
-- Drop temporary UNDO tablespace
DROP TABLESPACE UNDO_TMP INCLUDING CONTENTS AND DATAFILES;
-----------------------------------
ALTER SESSION SET CONTAINER=XEPDB1;
-----------------------------------
-- Create new temporary UNDO tablespace
CREATE UNDO TABLESPACE UNDO_TMP DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/undotbs_tmp.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use new temporary UNDO tablespace (so that old one can be deleted)
ALTER SYSTEM SET UNDO_TABLESPACE='UNDO_TMP';
ALTER SYSTEM CHECKPOINT;
-- Delete old UNDO tablespace
DROP TABLESPACE UNDOTBS1 INCLUDING CONTENTS AND DATAFILES;
-- Recreate old UNDO tablespace with 1M size and AUTOEXTEND
CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE '${ORACLE_BASE}/oradata/${ORACLE_SID}/XEPDB1/undotbs01.dbf'
SIZE 1M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;
-- Use newly created UNDO tablespace
ALTER SYSTEM SET UNDO_TABLESPACE='UNDOTBS1';
ALTER SYSTEM CHECKPOINT;
-- Drop temporary UNDO tablespace
DROP TABLESPACE UNDO_TMP INCLUDING CONTENTS AND DATAFILES;
---------------------------------
-- Shrink REDO log files
---------------------------------
ALTER SESSION SET CONTAINER=CDB\$ROOT;
-- Remove original redo logs and create new ones
ALTER DATABASE ADD LOGFILE GROUP 4 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo04.log') SIZE ${REDO_SIZE}m;
ALTER DATABASE ADD LOGFILE GROUP 5 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo05.log') SIZE ${REDO_SIZE}m;
ALTER DATABASE ADD LOGFILE GROUP 6 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo06.log') SIZE ${REDO_SIZE}m;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
ALTER DATABASE DROP LOGFILE GROUP 3;
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo03.log
ALTER DATABASE ADD LOGFILE GROUP 1 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo01.log') SIZE ${REDO_SIZE}m REUSE;
ALTER DATABASE ADD LOGFILE GROUP 2 ('${ORACLE_BASE}/oradata/${ORACLE_SID}/redo02.log') SIZE ${REDO_SIZE}m REUSE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM SWITCH LOGFILE;
ALTER SYSTEM CHECKPOINT;
ALTER DATABASE DROP LOGFILE GROUP 4;
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo04.log
ALTER DATABASE DROP LOGFILE GROUP 5;
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo05.log
ALTER DATABASE DROP LOGFILE GROUP 6;
HOST rm "${ORACLE_BASE}"/oradata/"${ORACLE_SID}"/redo06.log
exit;
EOF
# Close PDB\$SEED to READ ONLY again
echo "BUILDER: Opening PDB\$SEED in READ ONLY (default) mode"
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Open PDB\$SEED to READ WRITE mode
ALTER PLUGGABLE DATABASE PDB\$SEED CLOSE;
ALTER PLUGGABLE DATABASE PDB\$SEED OPEN READ ONLY;
exit;
EOF
fi;
###################################
########### DB SHUTDOWN ###########
###################################
echo "BUILDER: graceful database shutdown"
# Shutdown database gracefully (listener is not yet running)
su -p oracle -c "sqlplus -s / as sysdba" << EOF
-- Exit on any errors
WHENEVER SQLERROR EXIT SQL.SQLCODE
-- Shutdown database gracefully
SHUTDOWN IMMEDIATE;
exit;
EOF
# Stop listener
su -p oracle -c "lsnrctl stop"
###############################
### Compress Database files ###
###############################
echo "BUILDER: compressing database data files"
cd "${ORACLE_BASE}"/oradata
zip -r "${ORACLE_SID}".zip "${ORACLE_SID}"
chown oracle:dba "${ORACLE_SID}".zip
mv "${ORACLE_SID}".zip "${ORACLE_BASE}"/
rm -r "${ORACLE_SID}"
cd - 1> /dev/null
########################
### Install run file ###
########################
echo "BUILDER: install operational files"
# Move operational files to ${ORACLE_BASE}
mv /install/*.sh "${ORACLE_BASE}"/
mv /install/resetPassword "${ORACLE_BASE}"/
chown oracle:dba "${ORACLE_BASE}"/*.sh \
"${ORACLE_BASE}"/resetPassword
chmod u+x "${ORACLE_BASE}"/*.sh \
"${ORACLE_BASE}"/resetPassword
# TODO: relink Oracle binaries
# Multimedia: ord/im/lib/env_ordim.mk
# Java JIT (JOT) compiler: make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk jox_off_static ioracle
#########################
####### Cleanup #########
#########################
echo "BUILDER: cleanup"
# Remove install directory
rm -r /install
# Cleanup XE files not needed for being in a container but were installed by the rpm
/sbin/chkconfig --del oracle-xe-18c
rm /etc/init.d/oracle-xe-18c
rm /etc/sysconfig/oracle-xe-18c.conf
rm -r /var/log/oracle-database-xe-18c
rm -r /tmp/*
# Remove SYS audit directories and files created during install
rm -r "${ORACLE_BASE}"/admin/"${ORACLE_SID}"/adump/*
rm -r "${ORACLE_BASE}"/audit/"${ORACLE_SID}"/*
# Remove Data Pump log file
rm "${ORACLE_BASE}"/admin/"${ORACLE_SID}"/dpdump/dp.log
# Remove Oracle DB install logs
rm "${ORACLE_BASE}"/cfgtoollogs/dbca/XE/*
rm "${ORACLE_BASE}"/cfgtoollogs/netca/*
rm -r "${ORACLE_BASE}"/cfgtoollogs/sqlpatch/*
rm "${ORACLE_BASE}"/oraInventory/logs/*
rm "${ORACLE_HOME}"/cfgtoollogs/oui/*
rm -r "${ORACLE_HOME}"/log/*
# Remove diag files
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/lck/*
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/metadata/*
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/trace/"${ORACLE_SID}"_*
rm "${ORACLE_BASE}"/diag/rdbms/xe/"${ORACLE_SID}"/trace/drc"${ORACLE_SID}".log
rm -r "${ORACLE_BASE}"/diag/tnslsnr/*
# TODO: clean up os files
# /var/log/lastlog
# Remove additional files for NOMRAL and SLIM builds
if [ "${BUILD_MODE}" == "REGULAR" ] || [ "${BUILD_MODE}" == "SLIM" ]; then
echo "BUILDER: further cleanup for REGULAR and SLIM image"
# Remove OPatch and QOpatch
rm -r "${ORACLE_HOME}"/OPatch
rm -r "${ORACLE_HOME}"/QOpatch
# Remove assistants
rm -r "${ORACLE_HOME}"/assistants
# Remove Oracle Database Migration Assistant for Unicode (dmu)
rm -r "${ORACLE_HOME}"/dmu
# Remove inventory directory
rm -r "${ORACLE_HOME}"/inventory
# Remove JDBC drivers
rm -r "${ORACLE_HOME}"/jdbc
rm -r "${ORACLE_HOME}"/jlib
rm -r "${ORACLE_HOME}"/ucp
# Remove Intel's Math kernel libraries
rm "${ORACLE_HOME}"/lib/libmkl_*
# Remove zip artifacts in $ORACLE_HOME/lib
rm "${ORACLE_HOME}"/lib/*.zip
# Remove lib/*.jar files
rm "${ORACLE_HOME}"/lib/*.jar
# Remove Multimedia
rm -r "${ORACLE_HOME}"/ord/im
# Remove Oracle XDK
rm -r "${ORACLE_HOME}"/xdk
# Remove JServer JAVA Virtual Machine
rm -r "${ORACLE_HOME}"/javavm
# Remove Java JDK
rm -r "${ORACLE_HOME}"/jdk
# Remove dbjava directory
rm -r "${ORACLE_HOME}"/dbjava
# Remove rdbms/jlib
rm -r "${ORACLE_HOME}"/rdbms/jlib
# Remove OLAP
rm -r "${ORACLE_HOME}"/olap
rm "${ORACLE_HOME}"/lib/libolapapi18.so
# Remove property graph (standalone component that can be downloaded from the web)
rm -r "${ORACLE_HOME}"/md/property_graph
# Remove Cluster Ready Services
rm -r "${ORACLE_HOME}"/crs
# Remove Cluster Verification Utility (CVU)
rm -r "${ORACLE_HOME}"/cv
# Remove install directory
rm -r "${ORACLE_HOME}"/install
# Remove network/jlib directory
rm -r "${ORACLE_HOME}"/network/jlib
# Remove network/tools directory
rm -r "${ORACLE_HOME}"/network/tools
# Remove opmn directory
rm -r "${ORACLE_HOME}"/opmn