Edit

PSU Jan 2019

Note
It’s a short post about how to do patching Oracle12c

… where to get patches
https://www.oracle.com/technetwork/topics/security/alerts-086861.html
… name of patches
https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=276414090790556&id=2466391.1&_afrWindowMode=0&_adf.ctrl-state=18pwv5yj9p_4

… GI Update 12.2.0.1.190115 Patch 28828733 (12.2)

as root:

> $GI_HOME/OPatch/opatch version
> $ORACLE_HOME/OPatch/opatch version
> export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1 && \
$GI_HOME/bin/crsctl status res |grep -v "^$"|awk -F "=" 'BEGIN {print " "} {printf("%s",NR%4 ? $2"|" : $2"\n")}'|sed -e 's/ *, /,/g' -e 's/, /,/g'|\
awk -F "|" 'BEGIN { printf "%-40s%-35s%-20s%-50s\n","Resource Name","Resource Type","Target ","State" }{ split ($3,trg,",") split ($4,st,",")}{for (i in trg) {printf "%-40s%-35s%-20s%-50s\n",$1,$2,trg[i],st[i]}}' && \
crsctl disable has && crsctl stop has
> export ORACLE_HOME=/u01/app/oracle/product/12.2.0/db_1 && \
cd /u01/app/transfer && \
mkdir -p /u01/app/grid/install && \
chown grid.oinstall /u01/app/grid/install && \
chown grid.oinstall p28828733_122010_Linux-x86-64.zip && \
mv p28828733_122010_Linux-x86-64.zip /u01/app/grid/install/ && \
chown grid.oinstall /u01/app/grid/12.2.0 && \
su - grid -c 'cd /u01/app/grid/install && unzip -q p28828733_122010_Linux-x86-64.zip && rm p28828733_122010_Linux-x86-64.zip'
> $GI_HOME/OPatch/opatchauto apply /u01/app/grid/install/28828733 -analyze -oh $GI_HOME && \
$ORACLE_HOME/OPatch/opatchauto apply /u01/app/grid/install/28828733 -analyze -oh $ORACLE_HOME && \
$GI_HOME/OPatch/opatchauto apply /u01/app/grid/install/28828733 -oh $GI_HOME && \
$ORACLE_HOME/OPatch/opatchauto apply /u01/app/grid/install/28828733 -oh $ORACLE_HOME
> crsctl start has && crsctl enable has
> su - oracle -c 'cd $ORACLE_HOME/OPatch; for i in ''1p 2p 3p''; do export ORACLE_SID=$i; echo ORACLE_SID=$ORACLE_SID; ./datapatch -verbose; done'

if oracle database cannot start (wrong permissions), execute as grid user:

> cd $ORACLE_HOME/bin
> ./setasmgidwrap o=/u01/app/oracle/product/12.2.0/db_1/bin/oracle

to check last applied PSU:

select max(vers) vers from (
--11g table always exists, but may be empty in 12c.
select MAX(regexp_substr(comments, '\d*\.\d*\.\d*\.\d*.\d*')) VERS from dba_registry_history WHERE upper(comments) not like '%UPGRADED FROM%'
union all
--12c table doesn't exist in 11g. Only query it when it's available.
select MAX(regexp_substr(description, '\d*\.\d*\.\d*\.\d*.\d*')) VERS
from
(
select xmltype(dbms_xmlgen.getxml(q'!SELECT MAX(regexp_substr(description, '\d*\.\d*\.\d*\.\d*.\d*')) VERS from dba_registry_sqlpatch!')) xml_results
from dba_views
where owner = 'SYS' and view_name = 'DBA_REGISTRY_SQLPATCH'
) cross join
xmltable
(
'/ROWSET/ROW'
passing xml_results
columns
description varchar2(4000) path 'VERS'
)
);

%23%23%23%20%60PSU%20Jan%202019%60%0A%3E**Note**%0A*It%27s%20a%20short%20post%20about%20how%20to%20do%20patching%20Oracle12c*%0A%0A...%20where%20to%20get%20patches%0Ahttps%3A//www.oracle.com/technetwork/topics/security/alerts-086861.html%0A...%20name%20of%20patches%0Ahttps%3A//support.oracle.com/epmos/faces/DocumentDisplay%3F_afrLoop%3D276414090790556%26id%3D2466391.1%26_afrWindowMode%3D0%26_adf.ctrl-state%3D18pwv5yj9p_4%0A%0A...%20GI%20Update%2012.2.0.1.190115%20Patch%2028828733%20%2812.2%29%0A%3Eas%20root%3A%20%20%0A%60%60%60bash%0A%3E%20%24GI_HOME/OPatch/opatch%20version%0A%3E%20%24ORACLE_HOME/OPatch/opatch%20version%0A%60%60%60%0A%60%60%60bash%0A%3E%20export%20ORACLE_HOME%3D/u01/app/oracle/product/12.2.0/db_1%20%26%26%20%5C%0A%24GI_HOME/bin/crsctl%20status%20res%20%7Cgrep%20-v%20%22%5E%24%22%7Cawk%20-F%20%22%3D%22%20%27BEGIN%20%7Bprint%20%22%20%22%7D%20%7Bprintf%28%22%25s%22%2CNR%254%20%3F%20%242%22%7C%22%20%3A%20%242%22%5Cn%22%29%7D%27%7Csed%20-e%20%27s/%20%20*%2C%20/%2C/g%27%20-e%20%27s/%2C%20/%2C/g%27%7C%5C%0Aawk%20-F%20%22%7C%22%20%27BEGIN%20%7B%20printf%20%22%25-40s%25-35s%25-20s%25-50s%5Cn%22%2C%22Resource%20Name%22%2C%22Resource%20Type%22%2C%22Target%20%22%2C%22State%22%20%7D%7B%20split%20%28%243%2Ctrg%2C%22%2C%22%29%20split%20%28%244%2Cst%2C%22%2C%22%29%7D%7Bfor%20%28i%20in%20trg%29%20%7Bprintf%20%22%25-40s%25-35s%25-20s%25-50s%5Cn%22%2C%241%2C%242%2Ctrg%5Bi%5D%2Cst%5Bi%5D%7D%7D%27%20%26%26%20%5C%0Acrsctl%20disable%20has%20%26%26%20crsctl%20stop%20has%0A%60%60%60%0A%60%60%60bash%0A%3E%20export%20ORACLE_HOME%3D/u01/app/oracle/product/12.2.0/db_1%20%26%26%20%5C%0Acd%20/u01/app/transfer%20%26%26%20%5C%0Amkdir%20-p%20/u01/app/grid/install%20%26%26%20%5C%0Achown%20grid.oinstall%20/u01/app/grid/install%20%26%26%20%5C%0Achown%20grid.oinstall%20p28828733_122010_Linux-x86-64.zip%20%26%26%20%5C%0Amv%20p28828733_122010_Linux-x86-64.zip%20/u01/app/grid/install/%20%26%26%20%5C%0Achown%20grid.oinstall%20/u01/app/grid/12.2.0%20%26%26%20%5C%0Asu%20-%20grid%20-c%20%27cd%20/u01/app/grid/install%20%26%26%20unzip%20-q%20p28828733_122010_Linux-x86-64.zip%20%26%26%20rm%20p28828733_122010_Linux-x86-64.zip%27%0A%60%60%60%0A%60%60%60bash%0A%3E%20%24GI_HOME/OPatch/opatchauto%20apply%20/u01/app/grid/install/28828733%20-analyze%20-oh%20%24GI_HOME%20%26%26%20%5C%0A%24ORACLE_HOME/OPatch/opatchauto%20apply%20/u01/app/grid/install/28828733%20-analyze%20-oh%20%24ORACLE_HOME%20%26%26%20%5C%0A%24GI_HOME/OPatch/opatchauto%20apply%20/u01/app/grid/install/28828733%20-oh%20%24GI_HOME%20%26%26%20%5C%0A%24ORACLE_HOME/OPatch/opatchauto%20apply%20/u01/app/grid/install/28828733%20-oh%20%24ORACLE_HOME%0A%60%60%60%0A%60%60%60bash%0A%3E%20crsctl%20start%20has%20%26%26%20crsctl%20enable%20has%0A%60%60%60%0A%60%60%60bash%0A%3E%20su%20-%20oracle%20-c%20%27cd%20%24ORACLE_HOME/OPatch%3B%20for%20i%20in%20%27%271p%202p%203p%27%27%3B%20do%20export%20ORACLE_SID%3D%24i%3B%20echo%20ORACLE_SID%3D%24ORACLE_SID%3B%20./datapatch%20-verbose%3B%20done%27%0A%60%60%60%0A%3E%20if%20oracle%20database%20cannot%20start%20%28wrong%20permissions%29%2C%20execute%20as%20grid%20user%3A%0A%60%60%60bash%0A%3E%20cd%20%24ORACLE_HOME/bin%0A%60%60%60%0A%60%60%60bash%0A%3E%20./setasmgidwrap%20o%3D/u01/app/oracle/product/12.2.0/db_1/bin/oracle%0A%60%60%60%0A%3Eto%20check%20last%20applied%20PSU%3A%0A%60%60%60sql%0Aselect%20max%28vers%29%20vers%20from%20%28%20%0A--11g%20table%20always%20exists%2C%20but%20may%20be%20empty%20in%2012c.%0Aselect%20MAX%28regexp_substr%28comments%2C%20%27%5Cd*%5C.%5Cd*%5C.%5Cd*%5C.%5Cd*.%5Cd*%27%29%29%20VERS%20from%20dba_registry_history%20WHERE%20upper%28comments%29%20not%20like%20%27%25UPGRADED%20FROM%25%27%0Aunion%20all%20%0A--12c%20table%20doesn%27t%20exist%20in%2011g.%20%20Only%20query%20it%20when%20it%27s%20available.%0Aselect%20MAX%28regexp_substr%28description%2C%20%27%5Cd*%5C.%5Cd*%5C.%5Cd*%5C.%5Cd*.%5Cd*%27%29%29%20VERS%20%0Afrom%20%0A%28%0A%20%20select%20xmltype%28dbms_xmlgen.getxml%28q%27%21SELECT%20MAX%28regexp_substr%28description%2C%20%27%5Cd*%5C.%5Cd*%5C.%5Cd*%5C.%5Cd*.%5Cd*%27%29%29%20VERS%20from%20dba_registry_sqlpatch%21%27%29%29%20xml_results%0A%20%20from%20dba_views%0A%20%20where%20owner%20%3D%20%27SYS%27%20and%20view_name%20%3D%20%27DBA_REGISTRY_SQLPATCH%27%0A%29%20cross%20join%0A%20%20xmltable%0A%28%0A%20%20%27/ROWSET/ROW%27%0A%20%20passing%20xml_results%0A%20%20columns%0A%20%20description%20varchar2%284000%29%20path%20%27VERS%27%0A%29%0A%29%3B%0A%60%60%60%0A%0A%20%20%20%0A@%28Postach.io%29%5Bunix%2C%20PSU%2C%20patch%2C%20patching%2C%20oracle%2C%2012c%2C%20published%5D