• Oracle 体系结构概述


    1.定义数据库和实例

    实例(instance)和数据库(database)

    • 数据库(database):物理操作系统文件或磁盘(disk)的集合。
    • 实例(instance):一组Oracle后台进程/线程以及一个共享内存区,这些内容由同一个计算机上运行的线程/进程所共享。
    • 实例和数据库之间的关系: 数据库可以由多个实例装载和打开,而实例可以在任何时间点装载和打开一个数据库。准确的讲,实例在其整个生存期中最多能装载和打开一个数据库。

    实例就是一组操作系统进程(或者是一个多线程的进程)以及一些内存。

    数据库只是一个文件集合(包括数据文件、临时文件、重做日志文件和控制文件)。

    ps(进程状态)命令,可以看到用户运行的所有进程。

    ipcs 命令,可用于显示进程间的通信设备,如共享内存,信号量等。目前系统中没有使用任何通信设备。

    1. [oracle@MaxwellDBA dbs]$ ll
    2. total 20
    3. -rw-rw---- 1 oracle oinstall 1544 Sep 27 11:12 hc_ORCLCDB.dat
    4. -rw-r--r-- 1 oracle oinstall 3079 May 14 2015 init.ora
    5. -rw-r----- 1 oracle oinstall 24 Jun 29 05:28 lkORCLCDB
    6. -rw-r----- 1 oracle oinstall 2048 Jun 29 09:49 orapwORCLCDB
    7. -rw-r----- 1 oracle oinstall 3584 Sep 29 16:00 spfileORCLCDB.ora
    8. [oracle@MaxwellDBA dbs]$
    9. [oracle@MaxwellDBA dbs]$
    10. [oracle@MaxwellDBA dbs]$ ps -aef | grep ora19c
    11. oracle 91690 91536 0 19:05 pts/0 00:00:00 grep --color=auto ora19c
    12. [oracle@MaxwellDBA dbs]$ ipcs -a
    13. ------ Message Queues --------
    14. key msqid owner perms used-bytes messages
    15. 0x00000000 0 root 666 0 0
    16. 0x00000000 2 db2inst1 601 0 0
    17. 0x00000000 4 db2inst1 601 0 0
    18. 0x00000000 5 db2fenc1 700 0 0
    19. 0x9d852d71 6 db2inst1 663 0 0
    20. 0x00000000 7 db2inst1 601 0 0
    21. 0x9d852d72 8 db2inst1 663 0 0
    22. 0x9d852d77 9 db2inst1 665 0 0
    23. ------ Shared Memory Segments --------
    24. key shmid owner perms bytes nattch status
    25. 0x0052e2c1 0 postgres 600 56 6
    26. 0x9d852d74 1 db2inst1 601 34156360 7
    27. 0x9d852d61 2 db2inst1 601 175570944 6
    28. 0x00000000 3 db2fenc1 601 268435456 6
    29. 0x43b375cc 9 oracle 600 12288 57
    30. ------ Semaphore Arrays --------
    31. key semid owner perms nsems
    32. 0x9d852d74 0 db2inst1 645 1
    33. 0x00000000 2 db2inst1 661 1
    34. 0x00000000 3 db2inst1 661 1
    35. 0x00000000 4 db2inst1 661 1
    36. 0x00000000 5 db2inst1 661 1
    37. 0x00000000 6 db2inst1 661 1
    38. 0x00000000 7 db2inst1 661 1
    39. 0x00000000 8 db2inst1 661 1
    40. 0x00000000 9 db2inst1 661 1
    41. 0x9d852d73 10 db2inst1 667 1
    42. 0x00000000 11 db2inst1 661 1
    43. 0x00000000 12 db2inst1 661 1
    44. 0x00000000 13 db2inst1 661 1
    45. 0x00000000 14 db2inst1 661 1
    46. 0x00000000 15 db2inst1 661 1
    47. 0x00000000 17 db2fenc1 667 3
    48. 0x9d852e69 18 db2inst1 661 1
    49. 0x00000000 20 db2inst1 661 1
    50. 0x8d2a3534 28 oracle 600 250
    51. 0x8d2a3535 29 oracle 600 250
    52. [oracle@MaxwellDBA dbs]$
    1. sys@cdb$root:orclcdb> !ipcs -a
    2. ------ Message Queues --------
    3. key msqid owner perms used-bytes messages
    4. 0x00000000 0 root 666 0 0
    5. 0x00000000 2 db2inst1 601 0 0
    6. 0x00000000 4 db2inst1 601 0 0
    7. 0x00000000 5 db2fenc1 700 0 0
    8. 0x9d852d71 6 db2inst1 663 0 0
    9. 0x00000000 7 db2inst1 601 0 0
    10. 0x9d852d72 8 db2inst1 663 0 0
    11. 0x9d852d77 9 db2inst1 665 0 0
    12. ------ Shared Memory Segments --------
    13. key shmid owner perms bytes nattch status
    14. 0x0052e2c1 0 postgres 600 56 6
    15. 0x9d852d74 1 db2inst1 601 34156360 7
    16. 0x9d852d61 2 db2inst1 601 175570944 6
    17. 0x00000000 3 db2fenc1 601 268435456 6
    18. 0x43b375cc 9 oracle 600 12288 58
    19. ------ Semaphore Arrays --------
    20. key semid owner perms nsems
    21. 0x9d852d74 0 db2inst1 645 1
    22. 0x00000000 2 db2inst1 661 1
    23. 0x00000000 3 db2inst1 661 1
    24. 0x00000000 4 db2inst1 661 1
    25. 0x00000000 5 db2inst1 661 1
    26. 0x00000000 6 db2inst1 661 1
    27. 0x00000000 7 db2inst1 661 1
    28. 0x00000000 8 db2inst1 661 1
    29. 0x00000000 9 db2inst1 661 1
    30. 0x9d852d73 10 db2inst1 667 1
    31. 0x00000000 11 db2inst1 661 1
    32. 0x00000000 12 db2inst1 661 1
    33. 0x00000000 13 db2inst1 661 1
    34. 0x00000000 14 db2inst1 661 1
    35. 0x00000000 15 db2inst1 661 1
    36. 0x00000000 17 db2fenc1 667 3
    37. 0x9d852e69 18 db2inst1 661 1
    38. 0x00000000 20 db2inst1 661 1
    39. 0x8d2a3534 28 oracle 600 250
    40. 0x8d2a3535 29 oracle 600 250
    41. sys@cdb$root:orclcdb> select name from v$datafile;
    42. NAME
    43. ----------------------------------------------------------------------------------------------------
    44. /opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf
    45. /opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf
    46. /opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf
    47. /opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf
    48. 4 rows selected.
    49. sys@cdb$root:orclcdb> select member from v$logfile;
    50. MEMBER
    51. ----------------------------------------------------------------------------------------------------
    52. /opt/oracle/oradata/ORCLCDB/redo03.log
    53. /opt/oracle/oradata/ORCLCDB/redo02.log
    54. /opt/oracle/oradata/ORCLCDB/redo01.log
    55. 3 rows selected.
    56. sys@cdb$root:orclcdb> select name from v$controlfile;
    57. NAME
    58. ----------------------------------------------------------------------------------------------------
    59. /opt/oracle/oradata/ORCLCDB/control01.ctl
    60. /opt/oracle/oradata/ORCLCDB/control02.ctl
    61. 2 rows selected.
    62. sys@cdb$root:orclcdb>

     

    重申一遍:

    • 实例是一组后台进程和共享内存组成。
    • 数据库是磁盘上存储的数据集合。
    • 实例“一生”只能装载并打开一个数据库。
    • 数据库可以由一个或多个实例(使用RAC)装载和打开。装载一个数据库的实例数量会随时间变化。

    2. SGA和后台进程

    • 维护所有进程需要访问的多种内部数据结构。
    • 缓存磁盘上的数据,另外重做数据写至磁盘之前先在这里缓存。
    • 保存已解析的SQL计划。

    Unix环境,可以用pstat查看各线程的更多详细信息。

    1. [oracle@MaxwellDBA dbs]$
    2. [oracle@MaxwellDBA dbs]$
    3. [oracle@MaxwellDBA dbs]$ ps -aef | grep oracle$ORACLE_SID
    4. oracle 88586 1 0 17:11 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    5. oracle 88616 1 0 17:12 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    6. oracle 88841 1 0 17:20 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    7. oracle 89028 89027 0 17:25 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    8. oracle 92059 92058 0 19:17 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    9. oracle 92409 91536 0 19:30 pts/0 00:00:00 grep --color=auto oracleORCLCDB
    10. [oracle@MaxwellDBA dbs]$
    11. sys@cdb$root:orclcdb>
    12. sys@cdb$root:orclcdb> !ps -aef | grep oracle$ORACLE_SID
    13. oracle 88586 1 0 17:11 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    14. oracle 88616 1 0 17:12 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    15. oracle 88841 1 0 17:20 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    16. oracle 89028 89027 0 17:25 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    17. oracle 92059 92058 0 19:17 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    18. oracle 92428 92426 0 19:31 pts/6 00:00:00 grep oracleORCLCDB
    19. sys@cdb$root:orclcdb>

    3.连接Oracle

    Oracle服务器处理请求的两种最常见的方式:

    • 专用服务器(dedicated server)连接
    • 共享服务器(shared server)连接

    服务器上的监听器(listener)进程会以不同的方式工作,这些监听器进程负责建立与服务器的物理连接。

    专用服务器

    1. [oracle@MaxwellDBA dbs]$ sqlplus sys/sys as sysdba
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Thu Sep 29 19:37:08 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Connected to:
    6. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    7. Version 19.3.0.0.0
    8. sys@cdb$root:orclcdb> !ps -aef | grep oracle$ORACLE_SID
    9. oracle 88616 1 0 17:12 ? 00:00:00 oracleORCLCDB (LOCAL=NO)
    10. oracle 89028 89027 0 17:25 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    11. oracle 92059 92058 0 19:17 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    12. oracle 92587 92586 0 19:37 ? 00:00:00 oracleORCLCDB (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
    13. oracle 92599 92597 0 19:37 pts/7 00:00:00 grep oracleORCLCDB
    14. sys@cdb$root:orclcdb>

    共享服务器(shared server)

    TCP/IP连接的基本原理

    1. [oracle@MaxwellDBA dbs]$ sqlplus sys/sys as sysdba
    2. SQL*Plus: Release 19.0.0.0.0 - Production on Thu Sep 29 19:40:57 2022
    3. Version 19.3.0.0.0
    4. Copyright (c) 1982, 2019, Oracle. All rights reserved.
    5. Connected to:
    6. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
    7. Version 19.3.0.0.0
    8. sys@cdb$root:orclcdb> ALTER SESSION SET CONTAINER=ORCLPDB1;
    9. Session altered.
    10. sys@cdb$root:orclcdb> conn SCOTT/TIGER@ORCLPDB1
    11. Connected.
    12. scott@orclpdb1:orclcdb>
    1. [oracle@MaxwellDBA admin]$ cat tnsnames.ora
    2. # tnsnames.ora Network Configuration File: /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
    3. # Generated by Oracle configuration tools.
    4. ORCLCDB =
    5. (DESCRIPTION =
    6. (ADDRESS = (PROTOCOL = TCP)(HOST = MaxwellDBA)(PORT = 1521))
    7. (CONNECT_DATA =
    8. (SERVER = DEDICATED)
    9. (SERVICE_NAME = ORCLCDB)
    10. )
    11. )
    12. LISTENER_ORCLCDB =
    13. (ADDRESS = (PROTOCOL = TCP)(HOST = MaxwellDBA)(PORT = 1521))
    14. ORCLPDB1 =
    15. (DESCRIPTION =
    16. (ADDRESS = (PROTOCOL = TCP)(HOST = MaxwellDBA)(PORT = 1521))
    17. (CONNECT_DATA =
    18. (SERVER = DEDICATED)
    19. (SERVICE_NAME = ORCLPDB1)
    20. )
    21. )
    22. LISTENER_ORCLPDB1 =
    23. (ADDRESS = (PROTOCOL = TCP)(HOST = MaxwellDBA)(PORT = 1521))
    24. [oracle@MaxwellDBA admin]$

     

     

  • 相关阅读:
    MySql和Oracle表分区
    F2O模式是旁氏模型吗?一文详解其模型的经济学原理
    设计模式 --单例模式
    使用Python绘制旭日图
    [漏洞分析] CVE-2022-2588 route4 double free内核提权
    seata使用说明及AT模式异常回滚失败记录
    【前端设计模式】之组合模式
    vue中,使用mock流程
    单链表的定义、初始化、建立、插入、删除
    详解ConCurrentHashMap源码(jdk1.8)
  • 原文地址:https://blog.csdn.net/u011868279/article/details/127112049