카디널리티라는 용어는 두 가지 다른 의미로 사용됩니다. 데이터 모델링에서 사용할 때와 SQL 문에서 사용할 때입니다. 데이터 모델링에서 사용할 때 카디널리티는 한 테이블이 다른 테이블과 가질 수 있는 관계를 나타냅니다. 다대다, 다대일/일대다 또는 일대일의 테이블 간의 관계를 카디널리티라고 합니다. SQL에서 사용할 때는 해당 열에 대한 테이블에 나타나는 고유한 값의 수를 나타냅니다.
data modeling 에서의 cardinality
회사에서 직원 정보를 저장하는 데 사용하는 세 개의 테이블(Employee 테이블, Employee_Salary 테이블 및 Department 테이블)이 있다고 가정합니다. 모든 직원은 하나의 부서에만 속할 수 있지만 부서는 여러 직원으로 구성될 수 있기 때문에 부서 테이블은 Employee 테이블과 일대다 관계를 갖습니다. 즉, 직원 테이블과 관련된 부서 테이블의 카디널리티는 일대다입니다. Employee_Salary 테이블과 관련된 Employee 테이블의 카디널리티는 직원이 하나의 급여만 가질 수 있고 그 반대도 마찬가지이므로 일대일입니다(예, 두 명의 직원이 동일한 급여를 가질 수 있지만 여전히 정확히 하나의 급여 항목이 있습니다. 다른 사람이 동일한 급여를 받는지 여부에 관계없이 각 직원에 대해).
만일, 한명의 직원이 여러 부서에 소속될 수 있다고 한다면 부서와 직원간의 관계는 다대다 관계입니다.
SQL에서의 Cardinality
카디널리티의 다른 정의는 아마도 용어의 더 일반적으로 사용되는 버전일 것입니다. SQL에서 주어진 테이블에 있는 열의 카디널리티는 해당 열에 대한 테이블에 나타나는 고유한 값의 수를 나타냅니다. 따라서 카디널리티는 숫자라는 것을 기억하십시오. 예를 들어 "남성"과 "여성"이라는 두 가지 가능한 값만 있는 "성별" 열이 있는 테이블이 있다고 가정해 보겠습니다. 그런 다음 해당 열에 나타날 수 있는 고유한 값은 남성과 여성이라는 두 가지뿐이므로 해당 "성별" 열의 카디널리티는 2입니다. Cardinality정보는 Execution Plan 정보에서 볼 수 있습니다.
primary key의 cardinality
또는 다른 예로 10,000개의 행이 있는 테이블에 기본 키 열이 있다고 가정해 보겠습니다. 해당 열의 카디널리티는 무엇이라고 생각합니까? 자, 10,000입니다. 기본 키 열이기 때문에 열의 모든 값이 고유해야 함을 알고 있습니다. 그리고 10,000개의 행이 있기 때문에 열에 10,000개의 항목이 있다는 것을 알고 있으며, 이는 해당 열에 대해 10,000개의 카디널리티로 변환됩니다. 따라서 기본 키 열의 카디널리티는 항상 동일한 테이블의 레코드 수와 동일하다는 규칙을 생각해낼 수 있습니다
cardinality 가 0 이라는 의미는?
열의 카디널리티가 0이면 열에 고유한 값이 없음을 의미합니다. 이것은 열의 값이 NULL인 경우입니다.
Docker registry에 login하여 Oracle image를 검색한 후 원하는 컨테이너 이미지를 docker pull로 다운받아 사용한다.
참고로, 이 이미지는 multitenant DB(CDB, PDB)이다.
[ 수행환경 ]
- Microsoft Windows 10 Pro(10.0.19041 N/A 빌드 19041)
- WSL 2(Ubuntu 20.04.3 LTS)
- Docker Desktop version : 4.3.2
- SQL Developer 21.4.1
WSL 에 접속
윈도우 command 창이나 Window PowerShell 창에서 wsl 명령어를 수행하여 wsl에 접속한다. wsl에 접속한다는 것은 wsl 이 기동하는 Ubuntu Linux에 접속하는 것이다. 문서에서 "$" 표시는 wsl 접속된 상태를 의미한다.
PS D:\> wsl
username@computername:/mnt/d$
Oracle container 이미지 검색
dockerhub(https://hub.docker.com/)에 접속하여 검색창에 oracle19를 입력하여 oracle image를 검색한다. Oracle19.3c 버전의 image가 검색된다. 본 문서에서는 Docker image for Oracle Database 19c (19.3) Enterprise Edition 이미지인 banglamon/oracle193db 이미지를 docker pull로 다운받는다.
docker login
Docker registry(dockerhub)에 login하는 명령어로 docker registry에 등록된 이미지를 pull하거나 push를 위해 login한다. docker login은 패스워드를 직접 입력하는 방식과 STDIN 을 사용해서 로그인하는 방식이 있는데 보안을 위해 STDIN 방식으로 로긴하는 것을 권장한다.
docker ps -a는 실행중인 컨테이너와 중지된 컨테이너 모두를 조회한다. 컨테이너가 생성된 것을 확인 할 수 있다.
컨테이너 로그 조회 - docker logs
컨테이너 실행 명령어 수행 후 바로 컨테이너를 사용할 수 있는 것은 아니다. 컨테이너에 따라 컨테이너를 생성하는데 필요한 설정을 하고 컨테이너를 생성하는데 시간이 소요된다. 오라클 데이터베이스는 오라클 인스턴스와 데이터베이스에 필요한 파일들을 생성하는데 일정 시간이 소요된다. 컨테이너 생성 과정을 모니터링 하기 위해
docker logs <container name or cotainer id> 명령어를 수행한다. 아래 화면은 DB 설치가 진행 중인 것을 보여주고 있다.
log의 마지막 줄에 "XDB initialized" 가 보이면 정상 설치된 것이다.
컨테이너 접속 - docker exec
컨테이너 생성이 "XDB initialized" 메시지와 함께 정상적으로 완료되면,
docker exec -i -t <ontainer name or cotainer id> /bin/bash 명령어로 컨Docker 테이너에 접속할 수 있다.
$ docker exec -it oracle19db bash
-i, --interactive=false : 표준 입력(stdin)을 활성화하며 컨테이너와 연결(attach)되어 있지 않더라도 표준 입력을 유지한다.
-t, --tty=false : TTY 모드(pseudo-TTY)를 사용한다. Bash를 사용하려면 이 옵션을 설정해야 한다. 이 옵션을 설정하지 않으면 명령을 입력할 수는 있지만 셸이 표시되지 않는다.
ontainer name 을 oracle19db 로 입력한다.
bash : 컨테이너 안의 /bin/bash를 실행하여 Bash 셸에 연결한다
참고로 아래 명령어는 bash 쉘로 접속하고 /home/oracle/.bashrc을 수행한 후 oracle DB에 sqlplus /nolog로 접속한다.
Oracle DB가 설치된 컨테이너에서 SQL 명령어 수행
$ sqlplus '/as sysdba'
SQL> select name from v$database;
NAME
---------
MONGO
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 MONGOPDB READ WRITE NO
## PDB에 접속
SQL> alter session set container=MONGOPDB;
Session altered.
## user 생성
SQL> create user docker identified by "docker123";
## 접속, resource 권한 부여
SQL> grant connect, resource to docker;
## users 테이블스페이스 사용 권한 설정
SQL> alter user docker quota unlimited on users;
Oracle client Tool로 DB 접속하기
Oracle Client Tool(SQL Developer, DBeaver, TOAD, Orange, Golden 등)로 컨테이너 DB 접속하기
SQL Developer로 Docker DB 접속하기
SQL Developer실행 후 좌측 상단의 [+] 를 클릭한 후 새 데이터베이스 접속 메뉴를 클릭한다.
- 호스트이름 : Localhost 또는 127.0.0.1 또는 본인의 PC/서버 IP를 입력한다.
- 포트 : docker run 수행 시 지정한 host port를 입력한다.
- 서비스 이름 : 반드시 SID가 아닌 서비스명을 입력한다.
[테스트] 버튼을 클릭하여 정상 접속 여부를 확인한다. 올바르게 설정했으면 좌측 하단에 "상태 : 성공" 이라는 메시지가 출력된다.
접속 테스트를 성공했으면 [접속] 버튼을 클릭하여 PDB에 접속한다.
SQL DML 수행하기
SQL Developer의 SQL 작성창에 테이블생성, 데이터 입력 등을 할 수 있다.
sqlplus 로 Docker DB 접속하기
접속하고자는 PC나 서버에 오라클 Client가 설치된 경우에는 아래와 같이 접속할 수 있다.
sqlplus 사용자/패스워드@//host:port/service_name
host 앞의 '//' 문자는 IP를 입력할 경우 생략해도 된다. url을 입력할 경우에는 사용해야 하니, 평소 사용하는 습관을 들이는 것이 좋을 듯하다. port도 오라클 DB 기본 port인 1521인 경우에는 생략해도 되나, 습관적으로 사용하는 것이 좋겠다.
주의할 것은 service_name에는 반드시 SID가 아닌 service_name을 사용해야 한다.
SID를 사용할 경우 ORA-01017 : invalid username/password:login denied 오류가 발생한다.
$ sqlplus docker/docker123@//127.0.0.1:1521/MONGOPDB
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Dec 25 02:26:49 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Sat Dec 25 2021 02:10:43 +00:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
Specifies that network I/O is to be done synchronously (SYNC) or asynchronously (ASYNC) when archival is performed using the log writer process (LGWR).
Note:
When the primary database is in maximum protection mode or maximum availability mode, destinations archiving to standby redo log files and using the log writer process are automatically placed in SYNC mode.
Category
SYNC
ASYNC
Data type
Keyword
Numeric
Valid values
Not applicable
Not applicable
Default value
Not applicable
None
Requires attributes ...
None
LGWR
Conflicts with attributes ...
ASYNC
SYNC, LOCATION, ARCH
Corresponds to ...
TRANSMIT_MODE column of the V$ARCHIVE_DEST view
TRANSMIT_MODE and ASYNC_BLOCKS columns of the V$ARCHIVE_DEST view
Usage Notes
Table 5-2 Minimum Requirements for Data Protection Modes
Maximum Protection
Maximum Availability
Maximum Performance
Redo archival process
LGWR
LGWR
LGWR or ARCH
Network transmission mode
SYNC
SYNC
SYNC or ASYNC when using LGWR process. SYNC if using ARCH process
The client application that manages backup and recovery operations for a target database. The RMAN client can use Oracle Net to connect to a target database, so it can be located on any host that is connected to the target host through Oracle Net.
A database containing the control files, datafiles, and optional archived redo logs that RMAN backs up or restores. RMAN uses the target database control file to gather metadata about the target database and to store information about its own operations. The work of backup and recovery is performed by server sessions running on the target database.
A database containing a recovery catalog, which contains metadata that RMAN uses to perform backup and recovery. You can create one recovery catalog that contains the RMAN metadata for multiple target databases. Unless you are using RMAN with a physical standby database, a recovery catalog is optional when using RMAN because RMAN stores its metadata in the control file of each target database.
The user within the recovery catalog database that owns the metadata tables maintained by RMAN. RMAN periodically propagates metadata from the target database control file into the recovery catalog.
A copy of the primary database that is updated with archived redo logs generated by the primary database. A physical standby database has the same DBID and DB_NAME values as the primary database, but a different DB_UNIQUE_NAME. You can fail over to the standby database if the primary database becomes inaccessible. RMAN can create, back up, or recover a standby database. Backups that you make at a standby database are usable at primary database or another standby database for same production database. The recovery catalog is required when you use RMAN in the Data Guard environment. Note: A logical standby database is treated as a separate database by RMAN because it has a different DBID from its primary database. See Also: Oracle Data Guard Concepts and Administration to learn how to use RMAN in a Data Guard environment
A disk location that you can use to store recovery-related files such as control file and online redo log copies, archived redo logs, flashback logs, and RMAN backups. Oracle Database and RMAN manage the files in the fast recovery area automatically.
A vendor-specific repository of metadata about a media management application
Oracle Enterprise Manager
A browser-based interface to the database, including backup and recovery through RMAN
RMAN Environment
RMAN Command-Line Client
Use the RMAN command-line client to enter commands that you can use to manage all aspects of backup and recovery operations. RMAN uses a command language interpreter that can execute commands in interactive or batch mode. Even when you use the backup and recovery features in Enterprise Manager that are built on top of RMAN, an RMAN client executes behind the scenes.
RMAN Channels
The RMAN client directs database server sessions to perform all backup and recovery tasks. What constitutes a session depends on the operating system. For example, on Linux, a server session corresponds to a server process, whereas on Windows it corresponds to a thread within the database service.
RMAN Channels
Channels and Devices
The RMAN-supported device types are disk and SBT (system backup to tape). An SBT device is controlled by a third-party media manager. Typically, SBT devices are tape libraries and tape drives.
If you use a disk channel for a backup, then the channel creates the backup on disk in the file name space of the target database instance creating the backup. You can make a backup on any device that can store a datafile. RMAN does not call a media manager when making disk backups.
To create backups on nondisk media, you must use media management software such as Oracle Secure Backup and allocate channels supported by this software. RMAN contacts the media manager whenever the channel type allocated is not disk. How and when the SBT channels cause the media manager to allocate resources is vendor-specific. Some media managers allocate resources when you issue the command; others do not allocate resources until you open a file for reading or writing.
You can use the CONFIGURE CHANNEL command to configure channels for use with disk or tape across RMAN sessions. This technique is known as automatic channel allocation. RMAN comes preconfigured with one DISK channel that you can use for backups to disk.
When you run a command that can use automatic channels, RMAN automatically allocates the channels with the options that you specified in the CONFIGURE command. For the BACKUP command, RMAN allocates only the type of channel required to back up to the specified media. For the RESTORE command and RMAN maintenance commands, RMAN allocates all necessary channels for the device types required to execute the command. RMAN determines the names for automatic channels.
You can also manually allocate channels. Each manually allocated channel uses a separate connection to the database. When you manually allocate a channel, you give it a user-defined name such as dev1 or ch2.
The number of channels available for use with a device when you run a command determines whether RMAN reads from or write to this device in parallel while performing the command. When the work is done in parallel, the backup of the files is done by more than one channel. Each channel may back up more than one file, but unless a multisection backup is performed, no file is backed up by more than one channel.
The RMAN repository is the collection of metadata about the target databases that RMAN uses for backup, recovery, and maintenance. RMAN always stores its metadata in the control file. The version of this metadata in the control file is the authoritative record of RMAN backups of your database. This is one reason why protecting your control file is an important part of your backup strategy. RMAN can conduct all necessary backup and recovery operations using just the control file to store the RMAN repository information, and maintains all records necessary to meet your configured retention policy.
You can also create a recovery catalog, which is a repository of RMAN metadata stored in an Oracle database schema. The control file has finite space for records of backup activities, whereas a recovery catalog can store a much longer history. You can simplify backup and recovery administration by creating a single recovery catalog that contains the RMAN metadata for all of your databases.
The owner of a recovery catalog can grant or revoke restricted access to the catalog to other database users. Each restricted user has full read/write access to his own metadata, which is called a virtual private catalog. When one or more virtual private catalogs exist in a database, the database contains just one set of catalog tables. These tables are owned by the base recovery catalog owner. The owner of the base recovery catalog controls which databases each virtual private catalog user can access.
Some RMAN features only function when you use a recovery catalog. For example, you can create a stored script in the recovery catalog and use this script to execute RMAN jobs. Other RMAN commands are specifically related to managing the recovery catalog and so are not available (and not needed) if RMAN is not connected to a recovery catalog.
The recovery catalog is maintained solely by RMAN. A target database instance never accesses the catalog directly. RMAN propagates information about the database structure, archived redo logs, backup sets, and datafile copies into the recovery catalog from the target database control file after any operation that updates the repository, and also before certain operations.
The Oracle Media Management Layer (MML) API lets third-party vendors build a media manager, software that works with RMAN and the vendor's hardware to allow backups to sequential media devices such as tape drives. A media manager handles loading, unloading, and labeling of sequential media such as tapes. You must install media manager software to use RMAN with sequential media devices.
When backing up or restoring, the RMAN client connects to a target database instance and directs the instance to send requests to its media manager. No direct communication occurs between the RMAN client and the media manager.
RMAN Interaction with a Media Manager
Before performing backup or restore to a media manager, you must allocate one or more channels to handle the communication with the media manager. You can also configure default channels for the media manager. The default channels are used for all backup and recovery tasks that employ the media manager and for which you have not explicitly allocated channels.
RMAN does not issue specific commands to load, label, or unload tapes. When backing up, RMAN gives the media manager a stream of bytes and associates a unique name with this stream. When RMAN must restore the backup, it asks the media manager to retrieve the byte stream. All details of how and where that stream is stored are handled entirely by the media manager. For example, the media manager labels and keeps track of the tape and names of files on each tape, and automatically loads and unloads tapes, or signals an operator to do so.
Some media managers support proxy copy functionality, in which they handle the entire data movement between datafiles and the backup devices. These products may use technologies such as high-speed connections between storage and media subsystems to reduce the load on the primary database server. RMAN provides a list of files requiring backup or restore to the media manager, which in turn makes all decisions regarding how and when to move the data.
Oracle Secure Backup is a media manager that provides reliable and secure data protection through file system backup to tape. All major tape drives and tape libraries in SAN, Gigabit Ethernet, and SCSI environments are supported.
Although Oracle Secure Backup has no specialized knowledge of database backup and recovery algorithms, it can serve as a media management layer for RMAN through the SBT interface. In this capacity, Oracle Secure Backup provides the same services for RMAN as other supported third-party SBT libraries. Oracle Secure Backup has some features, however, that are not available in other media managers.
The Oracle Backup Solutions Program (BSP), part of the Oracle PartnerNetwork, is a group of media manager vendors whose products are compliant with Oracle's MML specification. Several products may be available for your platform from media management vendors. For more information, contact your Oracle representative for a list of available products, contact individual vendors to ask them if they participate, or access the Backup Solutions Program Web site at:
Oracle does not certify media manager vendors for compatibility with RMAN. Questions about availability, version compatibility, and functionality can only be answered by the media manager vendor, not Oracle.
Fast Recovery Area
The components that create different backup and recovery-related files have no knowledge of each other or of the size of the file systems where they store their data. With automatic disk-based backup and recovery, you can create a fast recovery area (also called the recovery area), which automates management of backup-related files.
A fast recovery area minimizes the need to manually manage disk space for backup-related files and balance the use of space among the different types of files. In this way, a fast recovery area simplifies the ongoing administration of your database. Oracle recommends that you enable a recovery area to simplify backup management.
When you create a recovery area, you choose a location on disk and set an upper bound for storage space. You also set a backup retention policy that governs how long backup files are needed for recovery. The database manages the storage used for backups, archived redo logs, and other recovery-related files for the database within this space. Files no longer needed are eligible for deletion when RMAN must reclaim space for new files.
When using RMAN in a Data Guard environment, a recovery catalog is required. The recovery catalog can store the metadata for all primary and standby databases.
A database in a Data Guard environment is uniquely identified by means of the DB_UNIQUE_NAME parameter in the initialization parameter file. For RMAN to work correctly in a Data Guard environment, the DB_UNIQUE_NAME must be unique across all the databases with the same DBID.
To simplify ongoing use of RMAN for backup and recovery, you can set a number of persistent configuration settings for each primary and physical standby database in a Data Guard environment. These settings control many aspects of RMAN behavior. For example, you can configure the backup retention policy, default destinations for backups to tape or disk, default backup device type, and so on.
You can use the CONFIGURE command with the FOR DB_UNIQUE_NAME clause to create a persistent configuration for a database in a Data Guard environment without connecting to the standby database or primary database as TARGET. For example, you connect RMAN to the recovery catalog, run the SET DBID command, and then can create a configuration for a physical standby database before its creation so that the RMAN configuration applies when the database is created.
RMAN updates the control file of the database when connected to it as TARGET during a recovery catalog resynchronization. If you use FOR DB_UNIQUE_NAME for a database without being connected as TARGET to this database, however, then RMAN changes configurations in the recovery catalog only.
RMAN uses a recovery catalog to track filenames for all database files in a Data Guard environment. The catalog also records where the online redo log files, standby redo log files, tempfiles, archived redo log files, backup sets, and image copies are created.
Interchangeability of Backups in a Data Guard Environment
RMAN commands use the recovery catalog metadata to function transparently across different physical databases in the Data Guard environment. For example, you can back up a tablespace on a physical standby database and restore and recover it on the primary database. Similarly, you can back up a tablespace on a primary database and restore and recover it on a physical standby database.
Note:
Backups of logical standby databases are not usable at the primary database.
Backups of standby control files and nonstandby control files are interchangeable. For example, you can restore a standby control file on a primary database and a primary control file on a physical standby database. This interchangeability means that you can offload control file backups to one database in a Data Guard environment. RMAN automatically updates the filenames for database files during restore and recovery at the databases.
Association of Backups in a Data Guard Environment
The recovery catalog tracks the files in the Data Guard environment by associating every database file or backup file with a DB_UNIQUE_NAME. The database that creates a file is associated with the file. For example, if RMAN backs up the database with the unique name of standby1, then standby1 is associated with this backup. A backup remains associated with the database that created it unless you use the CHANGE ...RESET DB_UNIQUE_NAME command to associate the backup with a different database.
Accessibility of Backups in a Data Guard Environment
The accessibility of a backup is different from its association. In a Data Guard environment, the recovery catalog considers disk backups as accessible only to the database with which they are associated, whereas tape backups created on one database are accessible to all databases. If a backup file is not associated with any database, then the row describing it in the recovery catalog view shows null for the SITE_KEY column. By default, RMAN associates a file whose SITE_KEY is null with the database to which they are connected as TARGET.
RMAN commands such as BACKUP, RESTORE, and CROSSCHECK work on any accessible backup. For example, for a RECOVER COPY operation, RMAN considers only image copies that are associated with the database as eligible to be recovered. RMAN considers the incremental backups on disk and tape as eligible to recover the image copies. In a database recovery, RMAN considers only the disk backups associated with the database and all files on tape as eligible to be restored.
To illustrate the differences in backup accessibility, assume that databases prod and standby1 reside on different hosts. RMAN backs up datafile 1 on prod to /prmhost/disk1/df1.dbf on the production host and also to tape. RMAN backs up datafile 1 on standby1 to /sbyhost/disk2/df1.dbf on the standby host and also to tape. If RMAN is connected to database prod, then you cannot use RMAN commands to perform operations with the /sbyhost/disk2/df1.dbf backup located on the standby host. However, RMAN does consider the tape backup made on standby1 as eligible to be restored.
Note:
You can transfer a backup from a standby host to a primary host or vice versa, connect as TARGET to the database on this host, and then use the CATALOG command to catalog the backup. After a file is cataloged by the target database, the file is associated with the target database.
sqlselect * from DBA_HIST_SQLTEXT where sql_id ='4b6z0rh5jrktx'; select * from DBA_HIST_SQL_PLAN where sql_id ='4b6z0rh5jrktx' order by plan_hash_value, id; select * from DBA_HIST_SQLSTAT where sql_id ='4b6z0rh5jrktx'; select * from v$sql where sql_id ='4b6z0rh5jrktx';
select sql_id, plan_hash_value, id, count(*) from dba_hist_sql_plan group by sql_id, plan_hash_value, id having count(*) > 1; WRH$_SQL_PLAN select * from( select a.aid, b.bid from (select distinct sql_id as aid from DBA_HIST_SQLTEXT) A full outer join (select sql_id as bid from DBA_HIST_SQLSTAT ) B on a.aid = b.bid) c where c.bid is null;
select * from( select a.aid, b.bid from (select distinct sql_id as aid from sys.WRH$_SQLTEXT) A full outer join (select sql_id as bid from sys.WRH$_SQLSTAT ) B on a.aid = b.bid) c where c.bid is null;
select * FROM WRM$_SNAPSHOT sn, WRH$_SQLSTAT sql WHERE sn.snap_id = sql.snap_id AND sn.dbid = sql.dbid AND sn.instance_number = sql.instance_number AND sn.status = 0;
select * From dba_hist_snapshot where snap_id = 96410 order by 1 desc; select * From sys.WRH$_SQLTEXT b where not exists(select 'x' from sys.WRH$_SQLstat a where a.sql_id = b.sql_id);
select * From dba_objects where object_name='AWR_ROOT_SQLTEXT'; select * From dict where table_name='AWR_ROOT_SQLTEXT';
select sql_id, plan_hash_value, count(*) from DBA_HIST_SQLSTAT s where s.parsing_schema_name = 'KALMHS' group by sql_id, plan_hash_value order by 1 ; ---------------------- -- sql_id 추출 ---------------------- select sql_id, sql_text, replace(dbms_lob.substr(sql_text, 20, 1), chr(10), ' '), (select command_name from DBA_HIST_SQLCOMMAND_NAME where command_type=t.command_type) type from DBA_HIST_SQLTEXT T where exists (select 'EXIST' from DBA_HIST_SQLSTAT S where t.sql_id = s.sql_id and s.parsing_schema_name = 'KALMHS'); ;
select * from ( select t.sql_id, t.sql_text, replace(dbms_lob.substr(t.sql_text, 20, 1), chr(10), ' '), (select command_name from DBA_HIST_SQLCOMMAND_NAME where command_type=t.command_type) type, p.plan_hash_value from DBA_HIST_SQLTEXT T, (select sql_id, plan_hash_value from (select sql_id, plan_hash_value, row_number() over (partition by sql_id order by sql_id, timestamp desc) row_num from DBA_HIST_SQL_PLAN where 1 = 1) -- 전체 SQL where row_num = 1) P where t.sql_id = p.sql_id(+)) where plan_hash_value is null and type='SELECT';
select a.sql_id, b.sql_id, b.command_type from (select distinct sql_id from v$sql) a, DBA_HIST_SQLTEXT b where a.sql_id = b.sql_id(+) ;-- where sql_id='3hc96wfvxp4tk'; -- 56196, 9610 select distinct sql_id from DBA_HIST_SQLTEXT; --> 5540
select sql_id, sql_text, sql_t, type, plan_hash_value, parsing_schema_name from ( select t.sql_id, t.sql_text, replace(dbms_lob.substr(t.sql_text, 20, 1), chr(10), ' ') sql_t, (select command_name from DBA_HIST_SQLCOMMAND_NAME where command_type=t.command_type) type, p.plan_hash_value, (select parsing_schema_name from DBA_HIST_SQLSTAT S where 1=1 and s.sql_id = t.sql_id and s.plan_hash_value = p.plan_hash_value and rownum = 1) parsing_schema_name from DBA_HIST_SQLTEXT T, (select sql_id, plan_hash_value from (select sql_id, plan_hash_value, row_number() over (partition by sql_id order by sql_id, timestamp desc) row_num from DBA_HIST_SQL_PLAN where 1 = 1) -- 전체 SQL where row_num = 1) P where t.sql_id = p.sql_id and exists ( select 'X' from DBA_HIST_SQLSTAT S where s.parsing_schema_name in ('KALMHS','KALPPO','NETBACKUP','KALPPO_SSO','KALSTD') and module like '%%' and s.sql_id = t.sql_id and s.plan_hash_value = p.plan_hash_value) ) order by 1;
select t.*, sql_id, replace(dbms_lob.substr(t.sql_text, 20, 1), chr(10), ' ') sql_t, (select command_name from DBA_HIST_SQLCOMMAND_NAME where command_type=t.command_type) type, parsing_schema_name From v$sql t where t.parsing_schema_name in ('KALMHS','KALPPO','NETBACKUP','KALPPO_SSO','KALSTD');
where plan_hash_value is null and type='SELECT';
select sql_id, count(*) From v$sql group by sql_id having count(*) > 1;
select * From dba_tab_columns where column_name = 'MODULE' order by table_name;
select * from v$sql where sql_id='grvaq6wc3s189';
select * From dict where table_name like '%SHARED%'; select * from V$SQL_SHARED_CURSOR where sql_id='grvaq6wc3s189';
SELECT A.SQL_ID, A.SQL_TEXT, A.COMMAND_TYPE, --> IF NEEDED B.PLAN_HASH_VALUE, B.ID, B.OPERATION, B.OPTIONS, B.OBJECT_OWNER, B.OBJECT_NAME, B.OBJECT_TYPE, B.OPTIMIZER, B.PARTITION_START, B.PARTITION_STOP, B.PARTITION_ID FROM DBA_HIST_SQLTEXT A, DBA_HIST_SQL_PLAN B WHERE A.DBID = B.DBID AND A.SQL_ID = B.SQL_ID AND A.SQL_ID IN('03y5xw17vncxd') AND EXISTS (SELECT 'E' FROM DBA_HIST_SQLSTAT C WHERE A.DBID = C.DBID AND A.SQL_ID = C.SQL_ID AND B.SQL_ID = C.SQL_ID AND B.PLAN_HASH_VALUE <> C.PLAN_HASH_VALUE AND PARSING_SCHEMA_NAME IN('KALMHS')) ORDER BY A.DBID, A.SQL_ID, B.PLAN_HASH_VALUE, B.ID;