之前我们学习oracle基础的时候,有一个概念,叫多进程和多线程。在unix/linux等环境下面。数据库是以多进程的方式运行的,当一个会话连接进来,就会通过监听,然后在服务器上创建一个进程。而在windows上面它是以多线程的方式来运行的。一个进程有很多个thread线程。而在12c这个版本上面,oracle在unix/linux平台上做出了一些改变,引入了多线程的方式。通过参数threaded_execution,我们可以控制数据库是以多进程方式运行还是以多线程方式运行,默认该参数是false数据库以多进程方式运行。
1.查看参数的默认值,和数据库进程状态.
[oracle@ol6 ~]$ sqlplus / as sysdba sql*plus: release 12.2.0.1.0 production on fri aug 3 15:57:59 2018 copyright (c) 1982, 2016, oracle. all rights reserved. connected to: oracle database 12c enterprise edition release 12.2.0.1.0 - 64bit production sql> show parameter threaded name type value ------------------------------------ ----------- ------------------------------ threaded_execution boolean false [root@ol6 ~]# ps -ef | grep cdb1 oracle 1773 1 0 aug02 ? 00:00:04 ora_pmon_cdb1 oracle 1775 1 0 aug02 ? 00:00:01 ora_clmn_cdb1 oracle 1777 1 0 aug02 ? 00:00:13 ora_psp0_cdb1 oracle 1786 1 0 aug02 ? 00:17:01 ora_vktm_cdb1 oracle 1790 1 0 aug02 ? 00:00:08 ora_gen0_cdb1 oracle 1792 1 0 aug02 ? 00:00:01 ora_mman_cdb1 oracle 1796 1 0 aug02 ? 00:00:19 ora_gen1_cdb1 oracle 1800 1 0 aug02 ? 00:00:03 ora_diag_cdb1 oracle 1802 1 0 aug02 ? 00:00:01 ora_ofsd_cdb1 oracle 1806 1 0 aug02 ? 00:00:29 ora_dbrm_cdb1 oracle 1808 1 0 aug02 ? 00:01:14 ora_vkrm_cdb1 oracle 1810 1 0 aug02 ? 00:00:03 ora_svcb_cdb1 oracle 1812 1 0 aug02 ? 00:00:10 ora_pman_cdb1 oracle 1814 1 0 aug02 ? 00:00:48 ora_dia0_cdb1 oracle 1816 1 0 aug02 ? 00:00:08 ora_dbw0_cdb1 oracle 1818 1 0 aug02 ? 00:00:10 ora_lgwr_cdb1 oracle 1820 1 0 aug02 ? 00:00:18 ora_ckpt_cdb1 oracle 1822 1 0 aug02 ? 00:00:01 ora_smon_cdb1 oracle 1824 1 0 aug02 ? 00:00:04 ora_smco_cdb1 oracle 1826 1 0 aug02 ? 00:00:00 ora_reco_cdb1 oracle 1830 1 0 aug02 ? 00:00:03 ora_lreg_cdb1 oracle 1834 1 0 aug02 ? 00:00:01 ora_pxmn_cdb1 oracle 1838 1 0 aug02 ? 00:00:20 ora_mmon_cdb1 oracle 1840 1 0 aug02 ? 00:00:26 ora_mmnl_cdb1 oracle 1842 1 0 aug02 ? 00:00:00 ora_d000_cdb1 oracle 1844 1 0 aug02 ? 00:00:00 ora_s000_cdb1 oracle 1846 1 0 aug02 ? 00:00:00 ora_tmon_cdb1 oracle 1869 1 0 aug02 ? 00:00:00 ora_tt00_cdb1 oracle 1871 1 0 aug02 ? 00:00:00 ora_tt01_cdb1 oracle 1873 1 0 aug02 ? 00:00:02 ora_tt02_cdb1 oracle 1875 1 0 aug02 ? 00:00:00 ora_aqpc_cdb1 oracle 1879 1 0 aug02 ? 00:00:02 ora_p000_cdb1 oracle 1881 1 0 aug02 ? 00:00:02 ora_p001_cdb1 oracle 1883 1 0 aug02 ? 00:00:02 ora_p002_cdb1 oracle 1885 1 0 aug02 ? 00:00:02 ora_p003_cdb1 oracle 2039 1 0 aug02 ? 00:02:36 ora_cjq0_cdb1 oracle 2109 1 0 aug02 ? 00:00:01 ora_qm02_cdb1 oracle 2113 1 0 aug02 ? 00:00:00 ora_q002_cdb1 oracle 2120 1 0 aug02 ? 00:00:02 ora_q005_cdb1 oracle 24076 1 0 15:56 ? 00:00:00 ora_w000_cdb1 oracle 24149 1 0 15:56 ? 00:00:00 ora_q003_cdb1 oracle 24154 1 0 15:56 ? 00:00:00 ora_q004_cdb1 oracle 24161 1 0 15:56 ? 00:00:00 ora_q006_cdb1 oracle 24165 1 0 15:56 ? 00:00:00 ora_w001_cdb1 oracle 24317 1 0 15:57 ? 00:00:00 ora_w002_cdb1 oracle 24422 24421 0 15:57 ? 00:00:00 oraclecdb1 (description=(local=yes)(address=(protocol=beq))) root 24504 24458 0 15:58 pts/1 00:00:00 grep cdb1 oracle 28778 1 0 aug02 ? 00:00:01 ora_q001_cdb1 oracle 29034 29033 0 aug02 ? 00:00:00 oraclecdb1 (description=(local=yes)(address=(protocol=beq)))
2.修改参数重启数据库
sql> alter system set threaded_execution = true scope = spfile; system altered. sql> shutdown immediate; database closed. database dismounted. oracle instance shut down. [oracle@ol6 ~]$ sqlplus / as sysdba sql*plus: release 12.2.0.1.0 production on fri aug 3 15:59:47 2018 copyright (c) 1982, 2016, oracle. all rights reserved. connected to an idle instance. sql> startup error: ora-01017: invalid username/password; logon denied
当重启数据库的时候会遇到一些障碍,这里居然报无效的用户名和密码。这是因为我们修改了线程模式导致的,在这个时候我们需要通过先sqlplus /nolog,然后在conn的方式进行连接。
[oracle@ol6 ~]$ sqlplus /nolog sql*plus: release 12.2.0.1.0 production on fri aug 3 16:02:15 2018 copyright (c) 1982, 2016, oracle. all rights reserved. sql> conn sys as sysdba enter password: connected. sql> shutdown immediate; ora-01507: database not mounted oracle instance shut down. sql> startup oracle instance started. total system global area 629145600 bytes fixed size 8795760 bytes variable size 322963856 bytes database buffers 293601280 bytes redo buffers 3784704 bytes database mounted. database opened. sql> show parameter threaded name type value ------------------------------------ ----------- ------------------------------ threaded_execution boolean true
3.修改完参数之后查看进程状态。
后台进程的数量减少了。一些后台进程(pmon,dbw,lgwr,psp,vktm)的行为与以前一样。奇怪的是居然smon也没了。其他backgtound进程属于名为ora_uxxx_ 的多线程进程。
[root@ol6 ~]# ps -ef | grep cdb1 oracle 25236 1 0 16:03 ? 00:00:00 ora_pmon_cdb1 oracle 25238 1 0 16:03 ? 00:00:00 ora_u002_cdb1 oracle 25242 1 0 16:03 ? 00:00:00 ora_psp0_cdb1 oracle 25244 1 0 16:03 ? 00:00:00 ora_vktm_cdb1 oracle 25251 1 0 16:03 ? 00:00:00 ora_gen1_cdb1 oracle 25255 1 21 16:03 ? 00:00:14 ora_u006_cdb1 oracle 25259 1 0 16:03 ? 00:00:00 ora_ofsd_cdb1 oracle 25268 1 0 16:03 ? 00:00:00 ora_dbw0_cdb1 oracle 25270 1 0 16:03 ? 00:00:00 ora_lgwr_cdb1 root 25629 24458 0 16:04 pts/1 00:00:00 grep cdb1
4.通过系统视图查看进程状态。
这里我们可以发现execution_type,一部分已经变成了thread,我们的smon也变成了thread状态。
sql> select spid, stid, pname, program, execution_type from v$process order by execution_type, spid, stid; spid stid pname program execution_ ------------------------ ------------------------ ----- ------------------------------------------------ ---------- pseudo none 25236 25236 pmon oracle@ol6.localdomain (pmon) process 25242 25242 psp0 oracle@ol6.localdomain (psp0) process 25244 25244 vktm oracle@ol6.localdomain (vktm) process 25268 25268 dbw0 oracle@ol6.localdomain (dbw0) process 25238 25238 scmn oracle@ol6.localdomain (scmn) thread 25238 25240 clmn oracle@ol6.localdomain (clmn) thread 25238 25247 gen0 oracle@ol6.localdomain (gen0) thread 25238 25248 mman oracle@ol6.localdomain (mman) thread 25238 25262 dbrm oracle@ol6.localdomain (dbrm) thread 25238 25265 pman oracle@ol6.localdomain (pman) thread 25238 25273 ckpt oracle@ol6.localdomain (ckpt) thread 25238 25274 smon oracle@ol6.localdomain (smon) thread 25238 25278 lreg oracle@ol6.localdomain (lreg) thread 25251 25251 scmn oracle@ol6.localdomain (scmn) thread 25251 25253 gen1 oracle@ol6.localdomain (gen1) thread 25255 25255 scmn oracle@ol6.localdomain (scmn) thread 25255 25257 diag oracle@ol6.localdomain (diag) thread 25255 25263 vkrm oracle@ol6.localdomain (vkrm) thread 25255 25264 svcb oracle@ol6.localdomain (svcb) thread 25255 25266 dia0 oracle@ol6.localdomain (dia0) thread 25255 25275 smco oracle@ol6.localdomain (smco) thread 25255 25276 reco oracle@ol6.localdomain (reco) thread 25255 25277 w000 oracle@ol6.localdomain (w000) thread 25255 25279 w001 oracle@ol6.localdomain (w001) thread 25255 25280 pxmn oracle@ol6.localdomain (pxmn) thread 25255 25282 mmon oracle@ol6.localdomain (mmon) thread 25255 25283 mmnl oracle@ol6.localdomain (mmnl) thread 25255 25284 d000 oracle@ol6.localdomain (d000) thread 25255 25285 s000 oracle@ol6.localdomain (s000) thread 25255 25286 tmon oracle@ol6.localdomain (tmon) thread 25255 25287 n000 oracle@ol6.localdomain (n000) thread 25255 25296 oracle@ol6.localdomain thread 25255 25297 oracle@ol6.localdomain thread 25255 25298 oracle@ol6.localdomain thread 25255 25299 oracle@ol6.localdomain thread 25255 25300 oracle@ol6.localdomain thread 25255 25301 oracle@ol6.localdomain thread 25255 25302 oracle@ol6.localdomain thread 25255 25303 oracle@ol6.localdomain thread 25255 25304 oracle@ol6.localdomain thread 25255 25305 oracle@ol6.localdomain thread 25255 25306 oracle@ol6.localdomain thread 25255 25307 oracle@ol6.localdomain thread 25255 25308 oracle@ol6.localdomain thread 25255 25309 oracle@ol6.localdomain thread 25255 25310 oracle@ol6.localdomain thread 25255 25311 oracle@ol6.localdomain thread 25255 25312 oracle@ol6.localdomain thread 25255 25313 oracle@ol6.localdomain thread 25255 25314 oracle@ol6.localdomain thread 25255 25315 oracle@ol6.localdomain thread 25255 25319 tt00 oracle@ol6.localdomain (tt00) thread 25255 25320 tt01 oracle@ol6.localdomain (tt01) thread 25255 25321 tt02 oracle@ol6.localdomain (tt02) thread 25255 25330 oracle@ol6.localdomain thread 25255 25331 oracle@ol6.localdomain thread 25255 25332 oracle@ol6.localdomain thread 25255 25333 oracle@ol6.localdomain thread 25255 25334 oracle@ol6.localdomain thread 25255 25335 oracle@ol6.localdomain thread 25255 25336 oracle@ol6.localdomain thread 25255 25337 oracle@ol6.localdomain thread 25255 25338 oracle@ol6.localdomain thread 25255 25339 oracle@ol6.localdomain thread 25255 25340 aqpc oracle@ol6.localdomain (aqpc) thread 25255 25342 p000 oracle@ol6.localdomain (p000) thread 25255 25343 p001 oracle@ol6.localdomain (p001) thread 25255 25344 p002 oracle@ol6.localdomain (p002) thread 25255 25345 p003 oracle@ol6.localdomain (p003) thread 25255 25491 cjq0 oracle@ol6.localdomain (cjq0) thread 25255 25528 qm02 oracle@ol6.localdomain (qm02) thread 25255 25530 q002 oracle@ol6.localdomain (q002) thread 25255 25531 q003 oracle@ol6.localdomain (q003) thread 25255 25532 q004 oracle@ol6.localdomain (q004) thread 25255 25533 q005 oracle@ol6.localdomain (q005) thread 25255 25534 q006 oracle@ol6.localdomain (q006) thread 25255 25535 q007 oracle@ol6.localdomain (q007) thread 25255 25536 q008 oracle@ol6.localdomain (q008) thread 25255 25633 w002 oracle@ol6.localdomain (w002) thread 25259 25259 scmn oracle@ol6.localdomain (scmn) thread 25259 25261 ofsd oracle@ol6.localdomain (ofsd) thread 25270 25270 scmn oracle@ol6.localdomain (scmn) thread 25270 25272 lgwr oracle@ol6.localdomain (lgwr) thread
5.通过监听连接,可以看到仍然是进程模式。
[oracle@ol6 ~]$ sqlplus /nolog sql*plus: release 12.2.0.1.0 production on fri aug 3 16:14:48 2018 copyright (c) 1982, 2016, oracle. all rights reserved. sql> connect sys/oracle as sysdba connected. sql> sql> connect sys/oracle@pdb as sysdba connected. [root@ol6 ~]# ps -ef | grep cdb1 oracle 25236 1 0 16:03 ? 00:00:00 ora_pmon_cdb1 oracle 25238 1 0 16:03 ? 00:00:00 ora_u002_cdb1 oracle 25242 1 0 16:03 ? 00:00:00 ora_psp0_cdb1 oracle 25244 1 0 16:03 ? 00:00:06 ora_vktm_cdb1 oracle 25251 1 0 16:03 ? 00:00:00 ora_gen1_cdb1 oracle 25255 1 2 16:03 ? 00:00:17 ora_u006_cdb1 oracle 25259 1 0 16:03 ? 00:00:00 ora_ofsd_cdb1 oracle 25268 1 0 16:03 ? 00:00:00 ora_dbw0_cdb1 oracle 25270 1 0 16:03 ? 00:00:00 ora_lgwr_cdb1 oracle 27220 1 0 16:15 ? 00:00:00 oraclecdb1 (local=no) root 27270 24458 0 16:15 pts/1 00:00:00 grep cdb1
6.如果要通过监听的方式连接变成线程模式,需要修改监听的参数dedicated_through_broker_listener-name,并重启监听才行。
[oracle@ol6 admin]$ vi listener.ora # listener.ora network configuration file: /u01/app/oracle/product/12.2.0.1/db_1/network/admin/listener.ora # generated by oracle configuration tools. listener = (description_list = (description = (address = (protocol = tcp)(host = ol6.localdomain)(port = 1521)) (address = (protocol = ipc)(key = extproc1521)) ) ) dedicated_through_broker_listener-name=on
7.再次通过监听连接到数据库,发现新连接上的会话已经变成了线程模式。
sql> select spid from v$process where addr in (select paddr from v$session where sid=28); spid ------------------------ 25255 sql> / spid stid pname program execution_ ------------------------ ------------------------ ----- ------------------------------------------------ ---------- pseudo none 25236 25236 pmon oracle@ol6.localdomain (pmon) process 25242 25242 psp0 oracle@ol6.localdomain (psp0) process 25244 25244 vktm oracle@ol6.localdomain (vktm) process 25268 25268 dbw0 oracle@ol6.localdomain (dbw0) process 27220 27220 oracle@ol6.localdomain process 25238 25238 scmn oracle@ol6.localdomain (scmn) thread 25238 25240 clmn oracle@ol6.localdomain (clmn) thread 25238 25247 gen0 oracle@ol6.localdomain (gen0) thread 25238 25248 mman oracle@ol6.localdomain (mman) thread 25238 25262 dbrm oracle@ol6.localdomain (dbrm) thread 25238 25265 pman oracle@ol6.localdomain (pman) thread 25238 25273 ckpt oracle@ol6.localdomain (ckpt) thread 25238 25274 smon oracle@ol6.localdomain (smon) thread 25238 25278 lreg oracle@ol6.localdomain (lreg) thread 25251 25251 scmn oracle@ol6.localdomain (scmn) thread 25251 25253 gen1 oracle@ol6.localdomain (gen1) thread 25255 25255 scmn oracle@ol6.localdomain (scmn) thread 25255 25257 diag oracle@ol6.localdomain (diag) thread 25255 25263 vkrm oracle@ol6.localdomain (vkrm) thread 25255 25264 svcb oracle@ol6.localdomain (svcb) thread 25255 25266 dia0 oracle@ol6.localdomain (dia0) thread 25255 25275 smco oracle@ol6.localdomain (smco) thread 25255 25276 reco oracle@ol6.localdomain (reco) thread 25255 25280 pxmn oracle@ol6.localdomain (pxmn) thread 25255 25282 mmon oracle@ol6.localdomain (mmon) thread 25255 25283 mmnl oracle@ol6.localdomain (mmnl) thread 25255 25284 d000 oracle@ol6.localdomain (d000) thread 25255 25285 s000 oracle@ol6.localdomain (s000) thread 25255 25286 tmon oracle@ol6.localdomain (tmon) thread 25255 25287 n000 oracle@ol6.localdomain (n000) thread 25255 25296 oracle@ol6.localdomain thread 25255 25297 oracle@ol6.localdomain thread 25255 25300 oracle@ol6.localdomain thread 25255 25301 oracle@ol6.localdomain thread 25255 25302 oracle@ol6.localdomain thread 25255 25304 oracle@ol6.localdomain thread 25255 25306 oracle@ol6.localdomain thread 25255 25307 oracle@ol6.localdomain thread 25255 25308 oracle@ol6.localdomain thread 25255 25309 oracle@ol6.localdomain thread 25255 25310 oracle@ol6.localdomain thread 25255 25311 oracle@ol6.localdomain thread 25255 25314 oracle@ol6.localdomain thread 25255 25315 oracle@ol6.localdomain thread 25255 25319 tt00 oracle@ol6.localdomain (tt00) thread 25255 25320 tt01 oracle@ol6.localdomain (tt01) thread 25255 25321 tt02 oracle@ol6.localdomain (tt02) thread 25255 25330 oracle@ol6.localdomain thread 25255 25331 oracle@ol6.localdomain thread 25255 25332 oracle@ol6.localdomain thread 25255 25333 oracle@ol6.localdomain thread 25255 25334 oracle@ol6.localdomain thread 25255 25336 oracle@ol6.localdomain thread 25255 25337 oracle@ol6.localdomain thread 25255 25338 oracle@ol6.localdomain thread 25255 25339 oracle@ol6.localdomain thread 25255 25340 aqpc oracle@ol6.localdomain (aqpc) thread 25255 25342 p000 oracle@ol6.localdomain (p000) thread 25255 25343 p001 oracle@ol6.localdomain (p001) thread 25255 25344 p002 oracle@ol6.localdomain (p002) thread 25255 25345 p003 oracle@ol6.localdomain (p003) thread 25255 25491 cjq0 oracle@ol6.localdomain (cjq0) thread 25255 25528 qm02 oracle@ol6.localdomain (qm02) thread 25255 25530 q002 oracle@ol6.localdomain (q002) thread 25255 25533 q005 oracle@ol6.localdomain (q005) thread 25255 25535 q007 oracle@ol6.localdomain (q007) thread 25255 26267 w003 oracle@ol6.localdomain (w003) thread 25255 26842 w004 oracle@ol6.localdomain (w004) thread 25255 27011 w005 oracle@ol6.localdomain (w005) thread 25255 27239 w006 oracle@ol6.localdomain (w006) thread 25259 25259 scmn oracle@ol6.localdomain (scmn) thread 25259 25261 ofsd oracle@ol6.localdomain (ofsd) thread 25270 25270 scmn oracle@ol6.localdomain (scmn) thread 25270 25272 lgwr oracle@ol6.localdomain (lgwr) thread
当然需要注意的一点是,如果在aix上使用线程模式,需要安装补丁bug 22226365 – threaded_execution=true – scmn process res memory increases。
总结
以上所述是www.887551.com给大家介绍的oracle 12c 新特性之多线程数据库操作,希望对大家有所帮助