2026-03-12 20:23:15
This commit is contained in:
BIN
my/.DS_Store
vendored
Normal file
BIN
my/.DS_Store
vendored
Normal file
Binary file not shown.
72
my/Rocky_Linux/gitlab_ce_docker_second_edition.md
Normal file
72
my/Rocky_Linux/gitlab_ce_docker_second_edition.md
Normal file
@@ -0,0 +1,72 @@
|
||||
In this example gitlab will be accessible through the public URL: http://code.databasepro.fr
|
||||
|
||||
As prerequisits:
|
||||
- A valid SSL certificate for the subdomain `code.databasepro.fr` was generated (using **LetsEncrypt** `certbot`)
|
||||
- a reverse-proxy was defined.
|
||||
|
||||
Examlple of *nginx* reverse-proxy configuration:
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name code.databasepro.fr;
|
||||
access_log /wwwlogs/code.databasepro.fr.access.log combined;
|
||||
error_log /wwwlogs/code.databasepro.fr.error.log info;
|
||||
location / {
|
||||
root /www/code.databasepro.fr;
|
||||
index index.html index.htm;
|
||||
autoindex on;
|
||||
}
|
||||
rewrite ^ https://code.databasepro.fr$request_uri? permanent;
|
||||
}
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
ssl_certificate /etc/letsencrypt/live/code.databasepro.fr/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/code.databasepro.fr/privkey.pem;
|
||||
ssl_stapling on;
|
||||
server_name code.databasepro.fr;
|
||||
access_log /wwwlogs/code.databasepro.fr.access.log combined;
|
||||
error_log /wwwlogs/code.databasepro.fr.error.log info;
|
||||
location / {
|
||||
proxy_pass https://192.168.0.91:7004/;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Create persistent directories:
|
||||
|
||||
mkdir /app/persistent_docker/gitlab
|
||||
cd /app/persistent_docker/gitlab
|
||||
mkdir config data logs
|
||||
|
||||
|
||||
Pull the *Comunity Edition* of gitlab:
|
||||
|
||||
docker pull gitlab/gitlab-ce
|
||||
|
||||
|
||||
Create `docker-compose.yaml` file in `/app/persistent_docker/gitlab`:
|
||||
|
||||
services:
|
||||
gitlab:
|
||||
image: 'gitlab/gitlab-ce:latest'
|
||||
restart: always
|
||||
hostname: 'code.databasepro.fr'
|
||||
environment:
|
||||
gitlab_omnibus_config: |
|
||||
external_url 'https://code.databasepro.fr'
|
||||
# add any other gitlab.rb configuration here, each on its own line
|
||||
ports:
|
||||
- 7004:443
|
||||
volumes:
|
||||
- /app/persistent_docker/gitlab/config:/etc/gitlab
|
||||
- /app/persistent_docker/gitlab/logs:/var/log/gitlab
|
||||
- /app/persistent_docker/gitlab/data:/var/opt/gitlab
|
||||
|
||||
|
||||
Start container:
|
||||
|
||||
docker-compose up -d
|
||||
|
||||
|
||||
Initial `root` password can be found in `/app/persistent_docker/gitlab/config/initial_root_password`
|
||||
|
||||
41
my/Rocky_Linux/install_01.txt
Normal file
41
my/Rocky_Linux/install_01.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
virt-install \
|
||||
--graphics vnc,listen=0.0.0.0 \
|
||||
--name=seedmachine \
|
||||
--vcpus=2 \
|
||||
--memory=4096 \
|
||||
--network bridge=br0 \
|
||||
--network bridge=br0 \
|
||||
--cdrom=/vm/hdd0/_kit_/Rocky-8.5-x86_64-minimal.iso \
|
||||
--disk /vm/ssd0/seedmachine/hdd_01.img,size=16 \
|
||||
--disk /vm/ssd0/seedmachine/app_01.img,size=32 \
|
||||
--disk /vm/ssd0/seedmachine/swap_01.img,size=8 \
|
||||
--os-variant=rocky8.5
|
||||
|
||||
|
||||
# Packages
|
||||
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
|
||||
dnf install epel-release elrepo-release -y
|
||||
|
||||
dnf install -y htop.x86_64 lsof.x86_64 cifs-utils.x86_64 tar.x86_64 bzip2.x86_64 telnet.x86_64 nmap-ncat.x86_64 bind-utils.x86_64 wget epel-release
|
||||
dnf install -y rlwrap.x86_64 screen.x86_64 banner.x86_64 cowsay.noarch certbot.noarch kernel-headers.x86_64 kernel-devel kmod-wireguard wireguard-tools git.x86_64
|
||||
dnf install -y ethtool.x86_64 net-tools.x86_64 ipmitool.x86_64
|
||||
dnf install -y gcc.x86_64 redhat-rpm-config automake.noarch make.x86_64
|
||||
|
||||
# Ruby
|
||||
Install Ruby avec rvm
|
||||
Install roo module avec gem
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Firewall
|
||||
systemctl status firewalld
|
||||
systemctl stop firewalld
|
||||
systemctl disable firewalld
|
||||
|
||||
# SELinux
|
||||
getenforce
|
||||
vi /etc/selinux/config
|
||||
disabled
|
||||
|
||||
46
my/Rocky_Linux/mazzolino_tiddlywiki.md
Normal file
46
my/Rocky_Linux/mazzolino_tiddlywiki.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Get basic docker image
|
||||
|
||||
docker pull mazzolino/tiddlywiki
|
||||
|
||||
|
||||
# Customize the image upgrading tiddlywiki
|
||||
|
||||
Create persistent directory:
|
||||
|
||||
mkdir -p /app/persistent_docker/tiddlywiki
|
||||
|
||||
Create `Dockerfile`:
|
||||
|
||||
FROM mazzolino/tiddlywiki:latest
|
||||
MAINTAINER Valeriu PLESNILA
|
||||
RUN npm update -g tiddlywiki
|
||||
|
||||
|
||||
Build new image `my_tiddlywiki`:
|
||||
|
||||
docker build -t my_tiddlywiki .
|
||||
|
||||
|
||||
Create `docker-compose.yaml` file:
|
||||
|
||||
services:
|
||||
wiki:
|
||||
image: my_tiddlywiki
|
||||
restart: always
|
||||
environment:
|
||||
- USERNAME=*****
|
||||
- PASSWORD=*****
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- /app/persistent_docker/tiddlywiki:/var/lib/tiddlywiki
|
||||
|
||||
|
||||
# Create and run the container:
|
||||
|
||||
docker-compose up -d
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
66
my/Rocky_Linux/nginx_docker.md
Normal file
66
my/Rocky_Linux/nginx_docker.md
Normal file
@@ -0,0 +1,66 @@
|
||||
List available docker images:
|
||||
|
||||
docker search nginx
|
||||
|
||||
Download official image:
|
||||
|
||||
docker pull nginx
|
||||
|
||||
Create persistent directory:
|
||||
|
||||
mkdir -p /app/persistent_docker/nginx
|
||||
cd /app/persistent_docker/nginx
|
||||
mkdir www conf logs
|
||||
|
||||
Create `/app/persistent_docker/nginx/conf/nginx.conf`:
|
||||
|
||||
events {
|
||||
|
||||
}
|
||||
error_log /wwwlogs/error.log info;
|
||||
http {
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
access_log /wwwlogs/access.log combined;
|
||||
location / {
|
||||
root /www/demo;
|
||||
index index.html index.htm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Create then root directory for default site:
|
||||
|
||||
mkdir /app/persistent_docker/nginx/www/demo
|
||||
echo "Hello world" > /app/persistent_docker/nginx/www/demo/index.html
|
||||
|
||||
Start the container:
|
||||
|
||||
docker run -p 80:80 -p 443:443 --name nginx -v /etc/letsencrypt:/etc/letsencrypt -v /app/persistent_docker/nginx/www:/www -v /app/persistent_docker/nginx/conf:/etc/nginx -v /app/persistent_docker/nginx/logs:/wwwlogs -d nginx
|
||||
|
||||
|
||||
In order to use docker-compose, create `docker-compose.yml`:
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx
|
||||
restart: always
|
||||
volumes:
|
||||
- /etc/letsencrypt:/etc/letsencrypt
|
||||
- /app/persistent_docker/nginx/www:/www
|
||||
- /app/persistent_docker/nginx/conf:/etc/nginx
|
||||
- /app/persistent_docker/nginx/logs:/wwwlogs
|
||||
ports:
|
||||
- 80:80
|
||||
- 443:443
|
||||
|
||||
|
||||
Start the container and set the autostart:
|
||||
|
||||
docker-compose up -d
|
||||
docker update --restart unless-stopped nginx
|
||||
|
||||
|
||||
|
||||
53
my/awrsqlid.sql
Normal file
53
my/awrsqlid.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
@@myheader.sql
|
||||
|
||||
COLUMN iname HEADING "Instance" FORMAT A8
|
||||
COLUMN snap_id HEADING "Snap|Id" FORMAT 9999999
|
||||
COLUMN endsnaptime HEADING "End|snaphot|time" FORMAT A11
|
||||
COLUMN plan_hash_value HEADING "Plan|hash|value"
|
||||
COLUMN executions_delta HEADING "#Ex" FORMAT 999
|
||||
COLUMN buffer_gets_delta HEADING "Buffer|gets"
|
||||
COLUMN bufferperexec HEADING "Buffer|gets|/exec" FORMAT 9999999999
|
||||
COLUMN optimizer_cost HEADING "0ptimizer|cost"
|
||||
COLUMN rows_processed_delta HEADING "#Rows"
|
||||
COLUMN sql_profile HEADING "SQL|Prof" FORMAT A4
|
||||
COLUMN elapsed_time_delta HEADING "Elapsed|time|/exec|(sec)" FORMAT 99999
|
||||
COLUMN cpu_time_delta HEADING "CPU|time|/exec|(sec)" FORMAT 9999
|
||||
COLUMN iowait_delta HEADING "IO|time|/exec|(sec)" FORMAT 99999
|
||||
COLUMN px_servers_execs_delta HEADING "Px" FORMAT 999
|
||||
COLUMN disk_reads_delta HEADING "Disk|reads"
|
||||
COLUMN io_offload_elig_bytes_delta HEADING "Elig|Mb" FORMAT 999999
|
||||
COLUMN io_interconnect_bytes_delta HEADING "Inter|Mb" FORMAT 999999
|
||||
|
||||
select
|
||||
i.instance_name iname,
|
||||
sqlstat.snap_id,
|
||||
to_char(end_interval_time,'dd/mm hh24:mi') endsnaptime,
|
||||
plan_hash_value,
|
||||
optimizer_cost,
|
||||
executions_delta,
|
||||
buffer_gets_delta,
|
||||
buffer_gets_delta/executions_delta bufferperexec,
|
||||
decode (sql_profile,null, '',substr(sql_profile,1,4)) sql_profile,
|
||||
px_servers_execs_delta,
|
||||
disk_reads_delta,
|
||||
round(elapsed_time_delta/1000000) elapsed_time_delta,
|
||||
round(cpu_time_delta/1000000) cpu_time_delta,
|
||||
round(iowait_delta/1000000) iowait_delta,
|
||||
io_offload_elig_bytes_delta/1024/1024 io_offload_elig_bytes_delta,
|
||||
io_interconnect_bytes_delta/1024/1024 io_interconnect_bytes_delta,
|
||||
rows_processed_delta
|
||||
from
|
||||
dba_hist_sqlstat sqlstat
|
||||
join dba_hist_snapshot snap on (sqlstat.snap_id=snap.snap_id) and (sqlstat.INSTANCE_NUMBER=snap.INSTANCE_NUMBER)
|
||||
join gv$instance i on sqlstat.instance_number=i.instance_number
|
||||
where
|
||||
snap.begin_interval_time>=&&2
|
||||
and snap.end_interval_time<=&&3
|
||||
and sql_id='&&1'
|
||||
and executions_delta>0
|
||||
order by
|
||||
sqlstat.snap_id
|
||||
/
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
121
my/bak/sqlmon_lsrep.sql
Normal file
121
my/bak/sqlmon_lsrep.sql
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
|
||||
Usage:
|
||||
@sqlmon_lsrep <condition> <start_time> <end_time> <order_by_clause>
|
||||
|
||||
Examples:
|
||||
|
||||
@sqlmon_lsrep 1=1 sysdate-1 sysdate
|
||||
@sqlmon_lsrep "sql_id='c5wnbwzzc7h3k'" sysdate-31 sysdate
|
||||
@sqlmon_lsrep 1=1 "timestamp'2023-02-12 19:31:10'" "timestamp'2023-02-12 22:00:31'"
|
||||
@sqlmon_lsrep "t.session_id=303 and session_serial#=59545" sysdate-10 sysdate "6 asc"
|
||||
|
||||
*/
|
||||
|
||||
@@myheader.sql
|
||||
|
||||
COLUMN _order_by_clause NEW_VALUE order_by_clause NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
DECODE('&&4','','1,4 ASC','&&4') "_order_by_clause"
|
||||
FROM DUAL;
|
||||
set term on
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * List SQL Monitor reports
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - where clause = &&1
|
||||
PROMPT * - min timestamp = &&2
|
||||
PROMPT * - min timestamp = &&3
|
||||
PROMPT * - order by list = &&order_by_clause
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
set pages 50
|
||||
|
||||
column report_id format 99999 heading 'Report|ID'
|
||||
column status format a15 heading 'Status'
|
||||
column sql_id format a17 heading 'SQL_ID'
|
||||
column plan_hash format a15 heading 'Plan|hash value'
|
||||
column sql_exec_start format a21 heading 'SQL|start'
|
||||
column sql_exec_id format a12 heading 'SQL|exec ID'
|
||||
column elap_sec format 9999.99 heading 'Elapsed|sec'
|
||||
column cpu_sec format 9999.99 heading 'CPU|sec'
|
||||
column io_sec format 9999.99 heading 'IO|sec'
|
||||
column buffer_gets format a9 heading 'Buffer|gets'
|
||||
column px_servers_requested format a3 heading 'PX|req'
|
||||
column px_servers_allocated format a3 heading 'PW|all'
|
||||
column sess format a16 heading 'Session'
|
||||
column username format a15 heading 'Username'
|
||||
|
||||
|
||||
|
||||
SELECT /*+ NO_XML_QUERY_REWRITE */
|
||||
t.report_id
|
||||
, t.key1 sql_id
|
||||
, t.key2 sql_exec_id
|
||||
, to_char(to_date(t.key3,'MM:DD:YYYY HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') sql_exec_start
|
||||
, x.plan_hash
|
||||
, x.elapsed_time/1000000 elap_sec
|
||||
, x.cpu_time/1000000 cpu_sec
|
||||
, x.user_io_wait_time/1000000 io_sec
|
||||
, x.buffer_gets
|
||||
, x.username
|
||||
, ''''||t.session_id||','||t.session_serial#||'@'||t.instance_number||'''' sess
|
||||
, x.px_servers_requested
|
||||
, x.px_servers_allocated
|
||||
, x.status
|
||||
FROM dba_hist_reports t
|
||||
, xmltable('/report_repository_summary/sql'
|
||||
PASSING xmlparse(document t.report_summary)
|
||||
COLUMNS
|
||||
sql_id path '@sql_id'
|
||||
, sql_exec_start path '@sql_exec_start'
|
||||
, sql_exec_id path '@sql_exec_id'
|
||||
, status path 'status'
|
||||
, sql_text path 'sql_text'
|
||||
, first_refresh_time path 'first_refresh_time'
|
||||
, last_refresh_time path 'last_refresh_time'
|
||||
, refresh_count path 'refresh_count'
|
||||
, inst_id path 'inst_id'
|
||||
, session_id path 'session_id'
|
||||
, session_serial path 'session_serial'
|
||||
, user_id path 'user_id'
|
||||
, username path 'user'
|
||||
, con_id path 'con_id'
|
||||
, con_name path 'con_name'
|
||||
, modul path 'module'
|
||||
, action path 'action'
|
||||
, service path 'service'
|
||||
, program path 'program'
|
||||
, plan_hash path 'plan_hash'
|
||||
, is_cross_instance path 'is_cross_instance'
|
||||
, dop path 'dop'
|
||||
, instances path 'instances'
|
||||
, px_servers_requested path 'px_servers_requested'
|
||||
, px_servers_allocated path 'px_servers_allocated'
|
||||
, duration path 'stats/stat[@name="duration"]'
|
||||
, elapsed_time path 'stats/stat[@name="elapsed_time"]'
|
||||
, cpu_time path 'stats/stat[@name="cpu_time"]'
|
||||
, user_io_wait_time path 'stats/stat[@name="user_io_wait_time"]'
|
||||
, application_wait_time path 'stats/stat[@name="application_wait_time"]'
|
||||
, concurrency_wait_time path 'stats/stat[@name="concurrency_wait_time"]'
|
||||
, cluster_wait_time path 'stats/stat[@name="cluster_wait_time"]'
|
||||
, plsql_exec_time path 'stats/stat[@name="plsql_exec_time"]'
|
||||
, other_wait_time path 'stats/stat[@name="other_wait_time"]'
|
||||
, buffer_gets path 'stats/stat[@name="buffer_gets"]'
|
||||
, read_reqs path 'stats/stat[@name="read_reqs"]'
|
||||
, read_bytes path 'stats/stat[@name="read_bytes"]'
|
||||
) x
|
||||
where &&1
|
||||
and t.COMPONENT_NAME = 'sqlmonitor'
|
||||
and to_date(t.key3,'MM:DD:YYYY HH24:MI:SS') between &&2 and &&3
|
||||
order by &&order_by_clause
|
||||
/
|
||||
|
||||
@@myfooter.sql
|
||||
|
||||
|
||||
121
my/bak/sqlmon_lsrep_01.sql
Normal file
121
my/bak/sqlmon_lsrep_01.sql
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
|
||||
Usage:
|
||||
@sqlmon_lsrep <condition> <start_time> <end_time> <order_by_clause>
|
||||
|
||||
Examples:
|
||||
|
||||
@sqlmon_lsrep 1=1 sysdate-1 sysdate
|
||||
@sqlmon_lsrep "sql_id='c5wnbwzzc7h3k'" sysdate-31 sysdate
|
||||
@sqlmon_lsrep 1=1 "timestamp'2023-02-12 19:31:10'" "timestamp'2023-02-12 22:00:31'"
|
||||
@sqlmon_lsrep "t.session_id=303 and session_serial#=59545" sysdate-10 sysdate "6 asc"
|
||||
|
||||
*/
|
||||
|
||||
@@myheader.sql
|
||||
|
||||
COLUMN _order_by_clause NEW_VALUE order_by_clause NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
DECODE('&&4','','1,4 ASC','&&4') "_order_by_clause"
|
||||
FROM DUAL;
|
||||
set term on
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * List SQL Monitor reports
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - where clause = &&1
|
||||
PROMPT * - min timestamp = &&2
|
||||
PROMPT * - min timestamp = &&3
|
||||
PROMPT * - order by list = &&order_by_clause
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
set pages 50
|
||||
|
||||
column report_id format 99999 heading 'Report|ID'
|
||||
column status format a15 heading 'Status'
|
||||
column sql_id format a17 heading 'SQL_ID'
|
||||
column plan_hash format a15 heading 'Plan|hash value'
|
||||
column sql_exec_start format a21 heading 'SQL|start'
|
||||
column sql_exec_id format a12 heading 'SQL|exec ID'
|
||||
column elap_sec format 9999.99 heading 'Elapsed|sec'
|
||||
column cpu_sec format 9999.99 heading 'CPU|sec'
|
||||
column io_sec format 9999.99 heading 'IO|sec'
|
||||
column buffer_gets format a9 heading 'Buffer|gets'
|
||||
column px_servers_requested format a3 heading 'PX|req'
|
||||
column px_servers_allocated format a3 heading 'PW|all'
|
||||
column sess format a16 heading 'Session'
|
||||
column username format a15 heading 'Username'
|
||||
|
||||
|
||||
|
||||
SELECT /*+ NO_XML_QUERY_REWRITE */
|
||||
t.report_id
|
||||
, t.key1 sql_id
|
||||
, t.key2 sql_exec_id
|
||||
, to_char(to_date(t.key3,'MM:DD:YYYY HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') sql_exec_start
|
||||
, x.plan_hash
|
||||
, x.elapsed_time/1000000 elap_sec
|
||||
, x.cpu_time/1000000 cpu_sec
|
||||
, x.user_io_wait_time/1000000 io_sec
|
||||
, x.buffer_gets
|
||||
, x.username
|
||||
, ''''||t.session_id||','||t.session_serial#||'@'||t.instance_number||'''' sess
|
||||
, x.px_servers_requested
|
||||
, x.px_servers_allocated
|
||||
, x.status
|
||||
FROM dba_hist_reports t
|
||||
, xmltable('/report_repository_summary/sql'
|
||||
PASSING xmlparse(document t.report_summary)
|
||||
COLUMNS
|
||||
sql_id path '@sql_id'
|
||||
, sql_exec_start path '@sql_exec_start'
|
||||
, sql_exec_id path '@sql_exec_id'
|
||||
, status path 'status'
|
||||
, sql_text path 'sql_text'
|
||||
, first_refresh_time path 'first_refresh_time'
|
||||
, last_refresh_time path 'last_refresh_time'
|
||||
, refresh_count path 'refresh_count'
|
||||
, inst_id path 'inst_id'
|
||||
, session_id path 'session_id'
|
||||
, session_serial path 'session_serial'
|
||||
, user_id path 'user_id'
|
||||
, username path 'user'
|
||||
, con_id path 'con_id'
|
||||
, con_name path 'con_name'
|
||||
, modul path 'module'
|
||||
, action path 'action'
|
||||
, service path 'service'
|
||||
, program path 'program'
|
||||
, plan_hash path 'plan_hash'
|
||||
, is_cross_instance path 'is_cross_instance'
|
||||
, dop path 'dop'
|
||||
, instances path 'instances'
|
||||
, px_servers_requested path 'px_servers_requested'
|
||||
, px_servers_allocated path 'px_servers_allocated'
|
||||
, duration path 'stats/stat[@name="duration"]'
|
||||
, elapsed_time path 'stats/stat[@name="elapsed_time"]'
|
||||
, cpu_time path 'stats/stat[@name="cpu_time"]'
|
||||
, user_io_wait_time path 'stats/stat[@name="user_io_wait_time"]'
|
||||
, application_wait_time path 'stats/stat[@name="application_wait_time"]'
|
||||
, concurrency_wait_time path 'stats/stat[@name="concurrency_wait_time"]'
|
||||
, cluster_wait_time path 'stats/stat[@name="cluster_wait_time"]'
|
||||
, plsql_exec_time path 'stats/stat[@name="plsql_exec_time"]'
|
||||
, other_wait_time path 'stats/stat[@name="other_wait_time"]'
|
||||
, buffer_gets path 'stats/stat[@name="buffer_gets"]'
|
||||
, read_reqs path 'stats/stat[@name="read_reqs"]'
|
||||
, read_bytes path 'stats/stat[@name="read_bytes"]'
|
||||
) x
|
||||
where &&1
|
||||
and t.COMPONENT_NAME = 'sqlmonitor'
|
||||
and to_date(t.key3,'MM:DD:YYYY HH24:MI:SS') between &&2 and &&3
|
||||
order by &&order_by_clause
|
||||
/
|
||||
|
||||
@@myfooter.sql
|
||||
|
||||
|
||||
484
my/coe_xfr_sql_profile.sql
Normal file
484
my/coe_xfr_sql_profile.sql
Normal file
@@ -0,0 +1,484 @@
|
||||
SPO coe_xfr_sql_profile.log;
|
||||
SET DEF ON TERM OFF ECHO ON FEED OFF VER OFF HEA ON LIN 2000 PAGES 100 LONG 8000000 LONGC 800000 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 NUMF "" SQLP SQL>;
|
||||
SET SERVEROUT ON SIZE UNL;
|
||||
REM
|
||||
REM $Header: 215187.1 coe_xfr_sql_profile.sql 11.4.5.5 2013/03/01 carlos.sierra $
|
||||
REM
|
||||
REM Copyright (c) 2000-2013, Oracle Corporation. All rights reserved.
|
||||
REM
|
||||
REM AUTHOR
|
||||
REM carlos.sierra@oracle.com
|
||||
REM
|
||||
REM SCRIPT
|
||||
REM coe_xfr_sql_profile.sql
|
||||
REM
|
||||
REM DESCRIPTION
|
||||
REM This script generates another that contains the commands to
|
||||
REM create a manual custom SQL Profile out of a known plan from
|
||||
REM memory or AWR. The manual custom profile can be implemented
|
||||
REM into the same SOURCE system where the plan was retrieved,
|
||||
REM or into another similar TARGET system that has same schema
|
||||
REM objects referenced by the SQL that generated the known plan.
|
||||
REM
|
||||
REM PRE-REQUISITES
|
||||
REM 1. Oracle Tuning Pack license.
|
||||
REM
|
||||
REM PARAMETERS
|
||||
REM 1. SQL_ID (required)
|
||||
REM 2. Plan Hash Value for which a manual custom SQL Profile is
|
||||
REM needed (required). A list of known plans is presented.
|
||||
REM You may choose from list provided or enter a valid phv
|
||||
REM from a version of the SQL modified with Hints.
|
||||
REM
|
||||
REM EXECUTION
|
||||
REM 1. Connect into SQL*Plus as user with access to data dictionary.
|
||||
REM Do not use SYS.
|
||||
REM 2. Execute script coe_xfr_sql_profile.sql passing SQL_ID and
|
||||
REM plan hash value (parameters can be passed inline or until
|
||||
REM requested).
|
||||
REM
|
||||
REM EXAMPLE
|
||||
REM # sqlplus system
|
||||
REM SQL> START coe_xfr_sql_profile.sql [SQL_ID] [PLAN_HASH_VALUE];
|
||||
REM SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm 2055843663;
|
||||
REM SQL> START coe_xfr_sql_profile.sql gnjy0mn4y9pbm;
|
||||
REM SQL> START coe_xfr_sql_profile.sql;
|
||||
REM
|
||||
REM NOTES
|
||||
REM 1. For possible errors see coe_xfr_sql_profile.log
|
||||
REM 2. If SQLT is installed in SOURCE, you can use instead:
|
||||
REM sqlt/utl/sqltprofile.sql
|
||||
REM 3. Be aware that using DBMS_SQLTUNE requires a license for
|
||||
REM Oracle Tuning Pack.
|
||||
REM 4. Use a DBA user but not SYS.
|
||||
REM
|
||||
SET TERM ON ECHO OFF;
|
||||
PRO
|
||||
PRO Parameter 1:
|
||||
PRO SQL_ID (required)
|
||||
PRO
|
||||
DEF sql_id = '&1';
|
||||
PRO
|
||||
WITH
|
||||
p AS (
|
||||
SELECT plan_hash_value
|
||||
FROM gv$sql_plan
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND other_xml IS NOT NULL
|
||||
UNION
|
||||
SELECT plan_hash_value
|
||||
FROM dba_hist_sql_plan
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND other_xml IS NOT NULL ),
|
||||
m AS (
|
||||
SELECT plan_hash_value,
|
||||
SUM(elapsed_time)/SUM(executions) avg_et_secs
|
||||
FROM gv$sql
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND executions > 0
|
||||
GROUP BY
|
||||
plan_hash_value ),
|
||||
a AS (
|
||||
SELECT plan_hash_value,
|
||||
SUM(elapsed_time_total)/SUM(executions_total) avg_et_secs
|
||||
FROM dba_hist_sqlstat
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND executions_total > 0
|
||||
GROUP BY
|
||||
plan_hash_value )
|
||||
SELECT p.plan_hash_value,
|
||||
ROUND(NVL(m.avg_et_secs, a.avg_et_secs)/1e6, 3) avg_et_secs
|
||||
FROM p, m, a
|
||||
WHERE p.plan_hash_value = m.plan_hash_value(+)
|
||||
AND p.plan_hash_value = a.plan_hash_value(+)
|
||||
ORDER BY
|
||||
avg_et_secs NULLS LAST;
|
||||
PRO
|
||||
PRO Parameter 2:
|
||||
PRO PLAN_HASH_VALUE (required)
|
||||
PRO
|
||||
DEF plan_hash_value = '&2';
|
||||
PRO
|
||||
PRO Values passed to coe_xfr_sql_profile:
|
||||
PRO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
PRO SQL_ID : "&&sql_id."
|
||||
PRO PLAN_HASH_VALUE: "&&plan_hash_value."
|
||||
PRO
|
||||
SET TERM OFF ECHO ON;
|
||||
WHENEVER SQLERROR EXIT SQL.SQLCODE;
|
||||
|
||||
-- trim parameters
|
||||
COL sql_id NEW_V sql_id FOR A30;
|
||||
COL plan_hash_value NEW_V plan_hash_value FOR A30;
|
||||
SELECT TRIM('&&sql_id.') sql_id, TRIM('&&plan_hash_value.') plan_hash_value FROM DUAL;
|
||||
|
||||
VAR sql_text CLOB;
|
||||
VAR sql_text2 CLOB;
|
||||
VAR other_xml CLOB;
|
||||
EXEC :sql_text := NULL;
|
||||
EXEC :sql_text2 := NULL;
|
||||
EXEC :other_xml := NULL;
|
||||
|
||||
-- get sql_text from memory
|
||||
DECLARE
|
||||
l_sql_text VARCHAR2(32767);
|
||||
BEGIN -- 10g see bug 5017909
|
||||
FOR i IN (SELECT DISTINCT piece, sql_text
|
||||
FROM gv$sqltext_with_newlines
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
ORDER BY 1, 2)
|
||||
LOOP
|
||||
IF :sql_text IS NULL THEN
|
||||
DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
|
||||
DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
|
||||
END IF;
|
||||
-- removes NUL characters
|
||||
l_sql_text := REPLACE(i.sql_text, CHR(00), ' ');
|
||||
-- adds a NUL character at the end of each line
|
||||
DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
|
||||
END LOOP;
|
||||
-- if found in memory then sql_text is not null
|
||||
IF :sql_text IS NOT NULL THEN
|
||||
DBMS_LOB.CLOSE(:sql_text);
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting sql_text from memory: '||SQLERRM);
|
||||
:sql_text := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT :sql_text FROM DUAL;
|
||||
|
||||
-- get sql_text from awr
|
||||
DECLARE
|
||||
l_sql_text VARCHAR2(32767);
|
||||
l_clob_size NUMBER;
|
||||
l_offset NUMBER;
|
||||
BEGIN
|
||||
IF :sql_text IS NULL OR NVL(DBMS_LOB.GETLENGTH(:sql_text), 0) = 0 THEN
|
||||
SELECT sql_text
|
||||
INTO :sql_text2
|
||||
FROM dba_hist_sqltext
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND sql_text IS NOT NULL
|
||||
AND ROWNUM = 1;
|
||||
END IF;
|
||||
-- if found in awr then sql_text2 is not null
|
||||
IF :sql_text2 IS NOT NULL THEN
|
||||
l_clob_size := NVL(DBMS_LOB.GETLENGTH(:sql_text2), 0);
|
||||
l_offset := 1;
|
||||
DBMS_LOB.CREATETEMPORARY(:sql_text, TRUE);
|
||||
DBMS_LOB.OPEN(:sql_text, DBMS_LOB.LOB_READWRITE);
|
||||
-- store in clob as 64 character pieces plus a NUL character at the end of each piece
|
||||
WHILE l_offset < l_clob_size
|
||||
LOOP
|
||||
IF l_clob_size - l_offset > 64 THEN
|
||||
l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, 64, l_offset), CHR(00), ' ');
|
||||
ELSE -- last piece
|
||||
l_sql_text := REPLACE(DBMS_LOB.SUBSTR(:sql_text2, l_clob_size - l_offset + 1, l_offset), CHR(00), ' ');
|
||||
END IF;
|
||||
DBMS_LOB.WRITEAPPEND(:sql_text, LENGTH(l_sql_text) + 1, l_sql_text||CHR(00));
|
||||
l_offset := l_offset + 64;
|
||||
END LOOP;
|
||||
DBMS_LOB.CLOSE(:sql_text);
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting sql_text from awr: '||SQLERRM);
|
||||
:sql_text := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT :sql_text2 FROM DUAL;
|
||||
SELECT :sql_text FROM DUAL;
|
||||
|
||||
-- validate sql_text
|
||||
SET TERM ON;
|
||||
BEGIN
|
||||
IF :sql_text IS NULL THEN
|
||||
RAISE_APPLICATION_ERROR(-20100, 'SQL_TEXT for SQL_ID &&sql_id. was not found in memory (gv$sqltext_with_newlines) or AWR (dba_hist_sqltext).');
|
||||
END IF;
|
||||
END;
|
||||
/
|
||||
SET TERM OFF;
|
||||
|
||||
-- get other_xml from memory
|
||||
BEGIN
|
||||
FOR i IN (SELECT other_xml
|
||||
FROM gv$sql_plan
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||
AND other_xml IS NOT NULL
|
||||
ORDER BY
|
||||
child_number, id)
|
||||
LOOP
|
||||
:other_xml := i.other_xml;
|
||||
EXIT; -- 1st
|
||||
END LOOP;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
|
||||
:other_xml := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
-- get other_xml from awr
|
||||
BEGIN
|
||||
IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||
FOR i IN (SELECT other_xml
|
||||
FROM dba_hist_sql_plan
|
||||
WHERE sql_id = TRIM('&&sql_id.')
|
||||
AND plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||
AND other_xml IS NOT NULL
|
||||
ORDER BY
|
||||
id)
|
||||
LOOP
|
||||
:other_xml := i.other_xml;
|
||||
EXIT; -- 1st
|
||||
END LOOP;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
|
||||
:other_xml := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
-- get other_xml from memory from modified SQL
|
||||
BEGIN
|
||||
IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||
FOR i IN (SELECT other_xml
|
||||
FROM gv$sql_plan
|
||||
WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||
AND other_xml IS NOT NULL
|
||||
ORDER BY
|
||||
child_number, id)
|
||||
LOOP
|
||||
:other_xml := i.other_xml;
|
||||
EXIT; -- 1st
|
||||
END LOOP;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting other_xml from memory: '||SQLERRM);
|
||||
:other_xml := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
-- get other_xml from awr from modified SQL
|
||||
BEGIN
|
||||
IF :other_xml IS NULL OR NVL(DBMS_LOB.GETLENGTH(:other_xml), 0) = 0 THEN
|
||||
FOR i IN (SELECT other_xml
|
||||
FROM dba_hist_sql_plan
|
||||
WHERE plan_hash_value = TO_NUMBER(TRIM('&&plan_hash_value.'))
|
||||
AND other_xml IS NOT NULL
|
||||
ORDER BY
|
||||
id)
|
||||
LOOP
|
||||
:other_xml := i.other_xml;
|
||||
EXIT; -- 1st
|
||||
END LOOP;
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('getting other_xml from awr: '||SQLERRM);
|
||||
:other_xml := NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
SELECT :other_xml FROM DUAL;
|
||||
|
||||
-- validate other_xml
|
||||
SET TERM ON;
|
||||
BEGIN
|
||||
IF :other_xml IS NULL THEN
|
||||
RAISE_APPLICATION_ERROR(-20101, 'PLAN for SQL_ID &&sql_id. and PHV &&plan_hash_value. was not found in memory (gv$sql_plan) or AWR (dba_hist_sql_plan).');
|
||||
END IF;
|
||||
END;
|
||||
/
|
||||
SET TERM OFF;
|
||||
|
||||
-- generates script that creates sql profile in target system:
|
||||
SET ECHO OFF;
|
||||
PRO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql.
|
||||
SET FEED OFF LIN 666 TRIMS ON TI OFF TIMI OFF SERVEROUT ON SIZE 1000000 FOR WOR;
|
||||
SET SERVEROUT ON SIZE UNL FOR WOR;
|
||||
SPO OFF;
|
||||
SPO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql;
|
||||
DECLARE
|
||||
l_pos NUMBER;
|
||||
l_clob_size NUMBER;
|
||||
l_offset NUMBER;
|
||||
l_sql_text VARCHAR2(32767);
|
||||
l_len NUMBER;
|
||||
l_hint VARCHAR2(32767);
|
||||
BEGIN
|
||||
DBMS_OUTPUT.PUT_LINE('SPO coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..log;');
|
||||
DBMS_OUTPUT.PUT_LINE('SET ECHO ON TERM ON LIN 2000 TRIMS ON NUMF 99999999999999999999;');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM $Header: 215187.1 coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql 11.4.4.4 '||TO_CHAR(SYSDATE, 'YYYY/MM/DD')||' carlos.sierra $');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM Copyright (c) 2000-2012, Oracle Corporation. All rights reserved.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM AUTHOR');
|
||||
DBMS_OUTPUT.PUT_LINE('REM carlos.sierra@oracle.com');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM SCRIPT');
|
||||
DBMS_OUTPUT.PUT_LINE('REM coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM DESCRIPTION');
|
||||
DBMS_OUTPUT.PUT_LINE('REM This script is generated by coe_xfr_sql_profile.sql');
|
||||
DBMS_OUTPUT.PUT_LINE('REM It contains the SQL*Plus commands to create a custom');
|
||||
DBMS_OUTPUT.PUT_LINE('REM SQL Profile for SQL_ID &&sql_id. based on plan hash');
|
||||
DBMS_OUTPUT.PUT_LINE('REM value &&plan_hash_value..');
|
||||
DBMS_OUTPUT.PUT_LINE('REM The custom SQL Profile to be created by this script');
|
||||
DBMS_OUTPUT.PUT_LINE('REM will affect plans for SQL commands with signature');
|
||||
DBMS_OUTPUT.PUT_LINE('REM matching the one for SQL Text below.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM Review SQL Text and adjust accordingly.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM PARAMETERS');
|
||||
DBMS_OUTPUT.PUT_LINE('REM None.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM EXAMPLE');
|
||||
DBMS_OUTPUT.PUT_LINE('REM SQL> START coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql;');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('REM NOTES');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 1. Should be run as SYSTEM or SYSDBA.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 2. User must have CREATE ANY SQL PROFILE privilege.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 3. SOURCE and TARGET systems can be the same or similar.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 4. To drop this custom SQL Profile after it has been created:');
|
||||
DBMS_OUTPUT.PUT_LINE('REM EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE(''coe_&&sql_id._&&plan_hash_value.'');');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 5. Be aware that using DBMS_SQLTUNE requires a license');
|
||||
DBMS_OUTPUT.PUT_LINE('REM for the Oracle Tuning Pack.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM 6. If you modified a SQL putting Hints in order to produce a desired');
|
||||
DBMS_OUTPUT.PUT_LINE('REM Plan, you can remove the artifical Hints from SQL Text pieces below.');
|
||||
DBMS_OUTPUT.PUT_LINE('REM By doing so you can create a custom SQL Profile for the original');
|
||||
DBMS_OUTPUT.PUT_LINE('REM SQL but with the Plan captured from the modified SQL (with Hints).');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('WHENEVER SQLERROR EXIT SQL.SQLCODE;');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('VAR signature NUMBER;');
|
||||
DBMS_OUTPUT.PUT_LINE('VAR signaturef NUMBER;');
|
||||
DBMS_OUTPUT.PUT_LINE('REM');
|
||||
DBMS_OUTPUT.PUT_LINE('DECLARE');
|
||||
DBMS_OUTPUT.PUT_LINE('sql_txt CLOB;');
|
||||
DBMS_OUTPUT.PUT_LINE('h SYS.SQLPROF_ATTR;');
|
||||
DBMS_OUTPUT.PUT_LINE('PROCEDURE wa (p_line IN VARCHAR2) IS');
|
||||
DBMS_OUTPUT.PUT_LINE('BEGIN');
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_LOB.WRITEAPPEND(sql_txt, LENGTH(p_line), p_line);');
|
||||
DBMS_OUTPUT.PUT_LINE('END wa;');
|
||||
DBMS_OUTPUT.PUT_LINE('BEGIN');
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_LOB.CREATETEMPORARY(sql_txt, TRUE);');
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_LOB.OPEN(sql_txt, DBMS_LOB.LOB_READWRITE);');
|
||||
DBMS_OUTPUT.PUT_LINE('-- SQL Text pieces below do not have to be of same length.');
|
||||
DBMS_OUTPUT.PUT_LINE('-- So if you edit SQL Text (i.e. removing temporary Hints),');
|
||||
DBMS_OUTPUT.PUT_LINE('-- there is no need to edit or re-align unmodified pieces.');
|
||||
l_clob_size := NVL(DBMS_LOB.GETLENGTH(:sql_text), 0);
|
||||
l_offset := 1;
|
||||
WHILE l_offset < l_clob_size
|
||||
LOOP
|
||||
l_pos := DBMS_LOB.INSTR(:sql_text, CHR(00), l_offset);
|
||||
IF l_pos > 0 THEN
|
||||
l_len := l_pos - l_offset;
|
||||
ELSE -- last piece
|
||||
l_len := l_clob_size - l_pos + 1;
|
||||
END IF;
|
||||
l_sql_text := DBMS_LOB.SUBSTR(:sql_text, l_len, l_offset);
|
||||
/* cannot do such 3 replacement since a line could end with a comment using "--"
|
||||
l_sql_text := REPLACE(l_sql_text, CHR(10), ' '); -- replace LF with SP
|
||||
l_sql_text := REPLACE(l_sql_text, CHR(13), ' '); -- replace CR with SP
|
||||
l_sql_text := REPLACE(l_sql_text, CHR(09), ' '); -- replace TAB with SP
|
||||
*/
|
||||
l_offset := l_offset + l_len + 1;
|
||||
IF l_len > 0 THEN
|
||||
IF INSTR(l_sql_text, '''[') + INSTR(l_sql_text, ']''') = 0 THEN
|
||||
l_sql_text := '['||l_sql_text||']';
|
||||
ELSIF INSTR(l_sql_text, '''{') + INSTR(l_sql_text, '}''') = 0 THEN
|
||||
l_sql_text := '{'||l_sql_text||'}';
|
||||
ELSIF INSTR(l_sql_text, '''<') + INSTR(l_sql_text, '>''') = 0 THEN
|
||||
l_sql_text := '<'||l_sql_text||'>';
|
||||
ELSIF INSTR(l_sql_text, '''(') + INSTR(l_sql_text, ')''') = 0 THEN
|
||||
l_sql_text := '('||l_sql_text||')';
|
||||
ELSIF INSTR(l_sql_text, '''"') + INSTR(l_sql_text, '"''') = 0 THEN
|
||||
l_sql_text := '"'||l_sql_text||'"';
|
||||
ELSIF INSTR(l_sql_text, '''|') + INSTR(l_sql_text, '|''') = 0 THEN
|
||||
l_sql_text := '|'||l_sql_text||'|';
|
||||
ELSIF INSTR(l_sql_text, '''~') + INSTR(l_sql_text, '~''') = 0 THEN
|
||||
l_sql_text := '~'||l_sql_text||'~';
|
||||
ELSIF INSTR(l_sql_text, '''^') + INSTR(l_sql_text, '^''') = 0 THEN
|
||||
l_sql_text := '^'||l_sql_text||'^';
|
||||
ELSIF INSTR(l_sql_text, '''@') + INSTR(l_sql_text, '@''') = 0 THEN
|
||||
l_sql_text := '@'||l_sql_text||'@';
|
||||
ELSIF INSTR(l_sql_text, '''#') + INSTR(l_sql_text, '#''') = 0 THEN
|
||||
l_sql_text := '#'||l_sql_text||'#';
|
||||
ELSIF INSTR(l_sql_text, '''%') + INSTR(l_sql_text, '%''') = 0 THEN
|
||||
l_sql_text := '%'||l_sql_text||'%';
|
||||
ELSIF INSTR(l_sql_text, '''$') + INSTR(l_sql_text, '$''') = 0 THEN
|
||||
l_sql_text := '$'||l_sql_text||'$';
|
||||
ELSE
|
||||
l_sql_text := CHR(96)||l_sql_text||CHR(96);
|
||||
END IF;
|
||||
DBMS_OUTPUT.PUT_LINE('wa(q'''||l_sql_text||''');');
|
||||
END IF;
|
||||
END LOOP;
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_LOB.CLOSE(sql_txt);');
|
||||
DBMS_OUTPUT.PUT_LINE('h := SYS.SQLPROF_ATTR(');
|
||||
DBMS_OUTPUT.PUT_LINE('q''[BEGIN_OUTLINE_DATA]'',');
|
||||
FOR i IN (SELECT /*+ opt_param('parallel_execution_enabled', 'false') */
|
||||
SUBSTR(EXTRACTVALUE(VALUE(d), '/hint'), 1, 4000) hint
|
||||
FROM TABLE(XMLSEQUENCE(EXTRACT(XMLTYPE(:other_xml), '/*/outline_data/hint'))) d)
|
||||
LOOP
|
||||
l_hint := i.hint;
|
||||
WHILE NVL(LENGTH(l_hint), 0) > 0
|
||||
LOOP
|
||||
IF LENGTH(l_hint) <= 500 THEN
|
||||
DBMS_OUTPUT.PUT_LINE('q''['||l_hint||']'',');
|
||||
l_hint := NULL;
|
||||
ELSE
|
||||
l_pos := INSTR(SUBSTR(l_hint, 1, 500), ' ', -1);
|
||||
DBMS_OUTPUT.PUT_LINE('q''['||SUBSTR(l_hint, 1, l_pos)||']'',');
|
||||
l_hint := ' '||SUBSTR(l_hint, l_pos);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
DBMS_OUTPUT.PUT_LINE('q''[END_OUTLINE_DATA]'');');
|
||||
DBMS_OUTPUT.PUT_LINE(':signature := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt);');
|
||||
DBMS_OUTPUT.PUT_LINE(':signaturef := DBMS_SQLTUNE.SQLTEXT_TO_SIGNATURE(sql_txt, TRUE);');
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_SQLTUNE.IMPORT_SQL_PROFILE (');
|
||||
DBMS_OUTPUT.PUT_LINE('sql_text => sql_txt,');
|
||||
DBMS_OUTPUT.PUT_LINE('profile => h,');
|
||||
DBMS_OUTPUT.PUT_LINE('name => ''coe_&&sql_id._&&plan_hash_value.'',');
|
||||
DBMS_OUTPUT.PUT_LINE('description => ''coe &&sql_id. &&plan_hash_value. ''||:signature||'' ''||:signaturef||'''',');
|
||||
DBMS_OUTPUT.PUT_LINE('category => ''DEFAULT'',');
|
||||
DBMS_OUTPUT.PUT_LINE('validate => TRUE,');
|
||||
DBMS_OUTPUT.PUT_LINE('replace => TRUE,');
|
||||
DBMS_OUTPUT.PUT_LINE('force_match => FALSE /* TRUE:FORCE (match even when different literals in SQL). FALSE:EXACT (similar to CURSOR_SHARING) */ );');
|
||||
DBMS_OUTPUT.PUT_LINE('DBMS_LOB.FREETEMPORARY(sql_txt);');
|
||||
DBMS_OUTPUT.PUT_LINE('END;');
|
||||
DBMS_OUTPUT.PUT_LINE('/');
|
||||
DBMS_OUTPUT.PUT_LINE('WHENEVER SQLERROR CONTINUE');
|
||||
DBMS_OUTPUT.PUT_LINE('SET ECHO OFF;');
|
||||
DBMS_OUTPUT.PUT_LINE('PRINT signature');
|
||||
DBMS_OUTPUT.PUT_LINE('PRINT signaturef');
|
||||
DBMS_OUTPUT.PUT_LINE('PRO');
|
||||
DBMS_OUTPUT.PUT_LINE('PRO ... manual custom SQL Profile has been created');
|
||||
DBMS_OUTPUT.PUT_LINE('PRO');
|
||||
DBMS_OUTPUT.PUT_LINE('SET TERM ON ECHO OFF LIN 80 TRIMS OFF NUMF "";');
|
||||
DBMS_OUTPUT.PUT_LINE('SPO OFF;');
|
||||
DBMS_OUTPUT.PUT_LINE('PRO');
|
||||
DBMS_OUTPUT.PUT_LINE('PRO COE_XFR_SQL_PROFILE_&&sql_id._&&plan_hash_value. completed');
|
||||
END;
|
||||
/
|
||||
SPO OFF;
|
||||
SET DEF ON TERM ON ECHO OFF FEED 6 VER ON HEA ON LIN 80 PAGES 14 LONG 80 LONGC 80 TRIMS OFF TI OFF TIMI OFF SERVEROUT OFF NUMF "" SQLP SQL>;
|
||||
SET SERVEROUT OFF;
|
||||
PRO
|
||||
PRO Execute coe_xfr_sql_profile_&&sql_id._&&plan_hash_value..sql
|
||||
PRO on TARGET system in order to create a custom SQL Profile
|
||||
PRO with plan &&plan_hash_value linked to adjusted sql_text.
|
||||
PRO
|
||||
UNDEFINE 1 2 sql_id plan_hash_value
|
||||
CL COL
|
||||
PRO
|
||||
PRO COE_XFR_SQL_PROFILE completed.
|
||||
56
my/help2.sql
Normal file
56
my/help2.sql
Normal file
@@ -0,0 +1,56 @@
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- File name: help.sql
|
||||
-- Purpose: Help
|
||||
-- Author: Tomasz Sroka
|
||||
-- Usage: @help <string>
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
--ACCEPT search_string CHAR PROMPT "Search: [%] "
|
||||
|
||||
DEFINE amp=chr(38)
|
||||
DEFINE nl=chr(10)
|
||||
DEFINE search_string=&1
|
||||
|
||||
COLUMN name FORMAT A30 TRUNC
|
||||
COLUMN description FORMAT A60 WORD_WRAP
|
||||
COLUMN usage FORMAT A115
|
||||
|
||||
WITH q AS (
|
||||
SELECT name, description, usage
|
||||
FROM (
|
||||
SELECT 'stats_opls.sql' AS name, 'List stats operations' AS description, '@stats_opls <since> <until> <level> <format>'||&nl||'@stats_opls sysdate-14 sysdate BASIC TEXT'||&nl||'@stats_opls "timestamp''2023-01-12 14:00:00''" "timestamp''2023-02-12 14:00:00''" TYPICAL HTML' AS usage FROM dual UNION ALL
|
||||
SELECT 'stats_opdet.sql' AS name, 'Display details of a stats operation' AS description, '@stats_opdet <operation_id> <level> <format>'||&nl||'@stats_opdet 1482'||&nl||'@stats_opdet 1482 TYPICAL HTML
|
||||
' AS usage FROM dual UNION ALL
|
||||
SELECT 'histo_endpoints.sql' AS name, 'List bucket details in histograms' AS description, '@histo_endpoints.sql <SCHEMA>.<TABLE_NAME> <COLUMN>' AS usage FROM dual UNION ALL
|
||||
SELECT 'sqlmon_sqlid.sql' AS name, 'SQL Monitor reports list of sql_id' AS description, '@sqlmon_sqlid 8c2mb6gp8w8zy sysdate-1 sysdate'||&nl||'@sqlmon_sqlid 8c2mb6gp8w8zy "timestamp''2023-04-22 09:30:45''" "timestamp''2023-04-22 12:00:00''"' AS usage FROM dual UNION ALL
|
||||
SELECT 'sqlmon_rep.sql' AS name, 'Display a SQL Monitor report' AS description, '@sqlmon_rep.sql <report_id> <report_type>(default=TEXT)'||&nl||'@sqlmon_rep.sql 553 '||&nl||'@sqlmon_rep.sql 553 HTML'||&nl||'@sqlmon_rep.sql 553 ACTIVE' AS usage FROM dual UNION ALL
|
||||
SELECT 'stdby_redolog' AS name, 'List standby redolog status' AS description, '@stdby_redolog' AS usage FROM dual UNION ALL
|
||||
SELECT 'mv_m_logtable.sql' AS name, '(matview) Log table of a master table' AS description, '@mv_m_logtable.sql <master_table>_owner> <master_table_name>' AS usage FROM dual UNION ALL
|
||||
SELECT 'mv_m_refreshlog.sql' AS name, '(matview) Refresh history of a master table' AS description, '@mv_m_refreshlog.sql <master_table>_owner> <master_table_name>' AS usage FROM dual UNION ALL
|
||||
SELECT 'mv_m_registeredsnap.sql' AS name, '(matview) Registered snapshots a master table' AS description, '@mv_m_registeredsnap.sql <master_table>_owner> <master_table_name>' AS usage FROM dual UNION ALL
|
||||
SELECT 'awrsqlid.sql' AS name, 'sql_id AWR execution history' AS description, '@awrsqlid <sql_id> <snap_begin_time> <snap_end_time>' ||&nl||'@awrsqlid 2qr52n47vt2aj sysdate-1000 sysdate'||&nl||'@awrsqlid 2qr52n47vt2aj "timestamp''2023-06-10 02:30:00''" "timestamp''2023-06-12 02:30:00''"' AS usage FROM dual UNION ALL
|
||||
SELECT 'monitoring/code_dep_on.sql' AS name, 'Displays all objects dependant on the specified object' AS description, '@monitoring/code_dep_on.sql <owner> <object_name>' AS usage FROM dual UNION ALL
|
||||
SELECT 'monitoring/code_dep.sql' AS name, 'Displays all dependencies of specified object' AS description, '@monitoring/code_dep.sql <owner> <object_name>' AS usage FROM dual UNION ALL
|
||||
SELECT 'transactions.sql' AS name, '(VG) Displays transactions' AS description, '@transactions <where clause>'||&nl||'@transactions "and 1=1"'||&nl||'@transactions "and sid=506"' AS usage FROM dual UNION ALL
|
||||
SELECT 'transaction_long_running.sql' AS name, '(VG) Displays long transactions' AS description, '@transaction_long_running.sql <where clause>'||&nl||'@transaction_long_running "and 1=1"'||&nl||'@transaction_long_running "and sid=506"' AS usage FROM dual UNION ALL
|
||||
SELECT 'racasqlmon.sql' AS name, '(RAC aware) Report SQL-monitoring-style drill-down into where in an execution plan the execution time is spent (ASH based)' AS description, '@racasqlmon <sql_id> <child#> <from_time> <to_time>'||&nl||'@racasqlmon 7q729nhdgtsqq 0 sysdate-1/24 sysdate'||&nl||'@racasqlmon 7q729nhdgtsqq % sysdate-1 sysdate' AS usage FROM dual UNION ALL
|
||||
SELECT 'stats_history.sql' AS name, '(VG) Display table/index/partition statistics history' AS description, '@stats_history.sql USR <owner> <object_name> <partition_name> <object_type> '||&nl||'@stats_history.sql USR T1 % %'||&nl||'@stats_history.sql USR IDX_T1_BLOCKS % INDEX' AS usage FROM dual UNION ALL
|
||||
SELECT '' AS name, '' AS description, '' AS usage FROM dual UNION ALL
|
||||
SELECT '' AS name, '' AS description, '' AS usage FROM dual
|
||||
)
|
||||
)
|
||||
SELECT * FROM q
|
||||
WHERE
|
||||
(upper(name) LIKE upper ('%&search_string%') OR regexp_like(name, '&search_string', 'i'))
|
||||
OR (upper(description) LIKE upper ('%&search_string%') OR regexp_like(description, '&search_string', 'i'))
|
||||
-- OR (upper(usage) LIKE upper ('%&search_string%') OR regexp_like(usage, '&search_string', 'i'))
|
||||
ORDER BY
|
||||
name
|
||||
/
|
||||
|
||||
UNDEFINE search_string
|
||||
CLEAR COLUMNS
|
||||
43
my/hist_cross_freq.sql
Normal file
43
my/hist_cross_freq.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
set verify off
|
||||
|
||||
col value head 'Value'
|
||||
col f1 format 999,999,999 head 'Table #1 | frequency'
|
||||
col f2 format 999,999,999 head 'Table #2 | frequency'
|
||||
column product format 999,999,999 head 'Tables join | frequency | (product)'
|
||||
|
||||
|
||||
break on report skip 1
|
||||
compute sum of product on report
|
||||
|
||||
WITH f1
|
||||
AS (
|
||||
SELECT endpoint_value value
|
||||
,endpoint_number - lag(endpoint_number, 1, 0) OVER (
|
||||
ORDER BY endpoint_number
|
||||
) frequency
|
||||
FROM dba_tab_histograms
|
||||
WHERE OWNER = '&1'
|
||||
AND table_name = '&2'
|
||||
AND column_name = '&3'
|
||||
ORDER BY endpoint_value
|
||||
)
|
||||
,f2
|
||||
AS (
|
||||
SELECT endpoint_value value
|
||||
,endpoint_number - lag(endpoint_number, 1, 0) OVER (
|
||||
ORDER BY endpoint_number
|
||||
) frequency
|
||||
FROM dba_tab_histograms
|
||||
WHERE OWNER = '&4'
|
||||
AND table_name = '&5'
|
||||
AND column_name = '&6'
|
||||
ORDER BY endpoint_value
|
||||
)
|
||||
SELECT f1.value
|
||||
,f1.frequency f1
|
||||
,f2.frequency f2
|
||||
,f1.frequency * f2.frequency product
|
||||
FROM f1
|
||||
,f2
|
||||
WHERE f2.value = f1.value;
|
||||
|
||||
55
my/histo_endpoints.sql
Normal file
55
my/histo_endpoints.sql
Normal file
@@ -0,0 +1,55 @@
|
||||
set verify off
|
||||
|
||||
-- arguments:
|
||||
-- table name as SCHEMA.TABLE_NAME
|
||||
-- column name
|
||||
|
||||
col endpoint_number format 999,999,999 head 'Endpoint|number'
|
||||
col endpoint_value format 999,999,999 head 'Endpoint|value'
|
||||
col frequency format 999,999,999 head 'Frequency'
|
||||
col endpoint_repeat_count format 999,999,999 head 'Endpoint|repeat count'
|
||||
|
||||
|
||||
col column_name format a30
|
||||
|
||||
SELECT column_id,
|
||||
column_name,
|
||||
histogram
|
||||
FROM user_tab_columns
|
||||
WHERE upper(table_name) LIKE
|
||||
upper(CASE
|
||||
WHEN INSTR('&1','.') > 0 THEN
|
||||
SUBSTR('&1',INSTR('&1','.')+1)
|
||||
ELSE
|
||||
'&1'
|
||||
END
|
||||
) ESCAPE '\'
|
||||
and COLUMN_NAME='&2'
|
||||
ORDER BY column_id;
|
||||
|
||||
|
||||
break on report skip 1
|
||||
compute sum of frequency on report
|
||||
compute sum of endpoint_repeat_count on report
|
||||
|
||||
select
|
||||
endpoint_number,
|
||||
endpoint_value,
|
||||
endpoint_number - LAG(endpoint_number, 1, 0) OVER (ORDER BY endpoint_value, endpoint_number) AS frequency,
|
||||
endpoint_repeat_count
|
||||
from
|
||||
dba_tab_histograms
|
||||
where
|
||||
upper(table_name) LIKE
|
||||
upper(CASE
|
||||
WHEN INSTR('&1','.') > 0 THEN
|
||||
SUBSTR('&1',INSTR('&1','.')+1)
|
||||
ELSE
|
||||
'&1'
|
||||
END
|
||||
) ESCAPE '\'
|
||||
and COLUMN_NAME='&2'
|
||||
order by
|
||||
endpoint_number
|
||||
;
|
||||
|
||||
36
my/mv_m_logtable.sql
Normal file
36
my/mv_m_logtable.sql
Normal file
@@ -0,0 +1,36 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
DEFINE owner="&&1"
|
||||
DEFINE table="&&2"
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT *************************************************
|
||||
PROMPT * Log table of a master table
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - owner = '&&owner'
|
||||
PROMPT * - table = '&&table'
|
||||
PROMPT *************************************************
|
||||
|
||||
|
||||
set lines 256
|
||||
|
||||
col log_table for a30
|
||||
col log_trigger for a30
|
||||
col primary_key for a3 head PK
|
||||
|
||||
select
|
||||
log_table
|
||||
,log_trigger
|
||||
,primary_key
|
||||
from
|
||||
dba_mview_logs
|
||||
where
|
||||
log_owner like'&&owner' and master like '&&table';
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
37
my/mv_m_refreshlog.sql
Normal file
37
my/mv_m_refreshlog.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
DEFINE owner="&&1"
|
||||
DEFINE table="&&2"
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT *************************************************
|
||||
PROMPT * Registerd napshots on MASTER site
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - owner = '&&owner'
|
||||
PROMPT * - table = '&&table'
|
||||
PROMPT *************************************************
|
||||
|
||||
|
||||
set lines 256
|
||||
|
||||
col mowner for a15
|
||||
col master for a25
|
||||
|
||||
col snapname for a30
|
||||
col snapsite for a30
|
||||
col snaptime for a30
|
||||
|
||||
select
|
||||
r.name snapname, snapid, nvl(r.snapshot_site, 'not registered') snapsite, snaptime
|
||||
from
|
||||
sys.slog$ s, dba_registered_snapshots r
|
||||
where
|
||||
s.snapid=r.snapshot_id(+) and mowner like '&&owner' and master like '&&table';
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
33
my/mv_m_registeredsnap.sql
Normal file
33
my/mv_m_registeredsnap.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
DEFINE owner="&&1"
|
||||
DEFINE table="&&2"
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT *************************************************
|
||||
PROMPT * Snapshot logs on MASTER site
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - owner = '&&owner'
|
||||
PROMPT * - table = '&&table'
|
||||
PROMPT *************************************************
|
||||
|
||||
|
||||
set lines 256
|
||||
|
||||
col mowner for a15
|
||||
col master for a25
|
||||
|
||||
select
|
||||
*
|
||||
from
|
||||
sys.slog$ slog
|
||||
where
|
||||
slog.mowner like '&&owner' and slog.master like '&&table';
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
32
my/myfooter.sql
Normal file
32
my/myfooter.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Based on Vishal Gupta script
|
||||
*/
|
||||
|
||||
CLEAR COLUMNS
|
||||
CLEAR BREAKS
|
||||
CLEAR COMPUTES
|
||||
|
||||
set trimspool on
|
||||
set feed on
|
||||
set arraysize 5000
|
||||
set lines 80
|
||||
set pages 80
|
||||
set verify on
|
||||
set sqlblankline on
|
||||
set serveroutput on
|
||||
set tab off
|
||||
set term on
|
||||
--start backupenv
|
||||
|
||||
DEFINE 1=""
|
||||
DEFINE 2=""
|
||||
DEFINE 3=""
|
||||
DEFINE 4=""
|
||||
DEFINE 5=""
|
||||
DEFINE 6=""
|
||||
DEFINE 7=""
|
||||
DEFINE 8=""
|
||||
DEFINE 9=""
|
||||
DEFINE 10=""
|
||||
|
||||
PROMPT
|
||||
74
my/myheader.sql
Normal file
74
my/myheader.sql
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Based on Vishal Gupta script
|
||||
*/
|
||||
|
||||
set echo off
|
||||
set term off
|
||||
set trimspool on
|
||||
set tab off
|
||||
set feed off
|
||||
set arraysize 5000
|
||||
set lines 250
|
||||
set pages 5000
|
||||
set verify off
|
||||
set sqlblankline on
|
||||
|
||||
set serveroutput on
|
||||
|
||||
|
||||
-- Set the terminal output off. Otherwise it puts the blank lines on console for
|
||||
-- query executed with noprint option below to version variable
|
||||
|
||||
|
||||
define _IF_ORA_8i_OR_HIGHER="--"
|
||||
define _IF_ORA_9iR2_OR_HIGHER="--"
|
||||
define _IF_ORA_10gR1_OR_HIGHER="--"
|
||||
define _IF_ORA_10gR2_OR_HIGHER="--"
|
||||
define _IF_ORA_11gR1_OR_HIGHER="--"
|
||||
define _IF_ORA_11107_OR_HIGHER="--"
|
||||
define _IF_ORA_11gR2_OR_HIGHER="--"
|
||||
define _IF_ORA_11202_OR_HIGHER="--"
|
||||
define _IF_ORA_11204_OR_HIGHER="--"
|
||||
define _IF_ORA_12cR1_OR_HIGHER="--"
|
||||
|
||||
define _IF_ORA_9iR2_OR_LOWER="--"
|
||||
define _IF_ORA_10gR1_OR_LOWER="--"
|
||||
define _IF_ORA_10gR2_OR_LOWER="--"
|
||||
define _IF_ORA_11gR2_OR_LOWER="--"
|
||||
|
||||
col oraverion_8i_or_higher new_value _IF_ORA_8i_OR_HIGHER noprint
|
||||
col oraverion_9iR2_or_higher new_value _IF_ORA_9iR2_OR_HIGHER noprint
|
||||
col oraverion_10gR1_or_higher new_value _IF_ORA_10gR1_OR_HIGHER noprint
|
||||
col oraverion_10gR2_or_higher new_value _IF_ORA_10gR2_OR_HIGHER noprint
|
||||
col oraverion_11gR1_or_higher new_value _IF_ORA_11gR1_OR_HIGHER noprint
|
||||
col oraverion_11107_or_higher new_value _IF_ORA_11107_OR_HIGHER noprint
|
||||
col oraverion_11gR2_or_higher new_value _IF_ORA_11gR2_OR_HIGHER noprint
|
||||
col oraverion_11202_or_higher new_value _IF_ORA_11202_OR_HIGHER noprint
|
||||
col oraverion_11204_or_higher new_value _IF_ORA_11204_OR_HIGHER noprint
|
||||
col oraverion_12cR1_or_higher new_value _IF_ORA_12cR1_OR_HIGHER noprint
|
||||
|
||||
col oraverion_9iR2_or_lower new_value _IF_ORA_9iR2_OR_LOWER noprint
|
||||
col oraverion_10gR1_or_lower new_value _IF_ORA_10gR1_OR_LOWER noprint
|
||||
col oraverion_10gR2_or_lower new_value _IF_ORA_10gR2_OR_LOWER noprint
|
||||
col oraverion_11gR2_or_lower new_value _IF_ORA_11gR2_OR_LOWER noprint
|
||||
|
||||
|
||||
SELECT CASE WHEN &&_O_RELEASE >= 0801000000 THEN '' ELSE '--' END oraverion_8i_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 0902000000 THEN '' ELSE '--' END oraverion_9iR2_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1001000000 THEN '' ELSE '--' END oraverion_10gR1_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1002000000 THEN '' ELSE '--' END oraverion_10gR2_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1101000000 THEN '' ELSE '--' END oraverion_11gR1_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1101000700 THEN '' ELSE '--' END oraverion_11107_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1102000000 THEN '' ELSE '--' END oraverion_11gR2_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1102000200 THEN '' ELSE '--' END oraverion_11202_or_higher
|
||||
, CASE WHEN &&_O_RELEASE >= 1102000400 THEN '' ELSE '--' END oraverion_11204_or_higher
|
||||
, CASE WHEN &&_O_RELEASE < 1001000000 THEN '' ELSE '--' END oraverion_9iR2_or_lower
|
||||
, CASE WHEN &&_O_RELEASE < 1002000000 THEN '' ELSE '--' END oraverion_10gR1_or_lower
|
||||
, CASE WHEN &&_O_RELEASE < 1101000000 THEN '' ELSE '--' END oraverion_10gR2_or_lower
|
||||
, CASE WHEN &&_O_RELEASE < 1201000000 THEN '' ELSE '--' END oraverion_11gR2_or_lower
|
||||
, CASE WHEN &&_O_RELEASE >= 1201000000 THEN '' ELSE '--' END oraverion_12cR1_or_higher
|
||||
FROM dual
|
||||
;
|
||||
|
||||
set term on
|
||||
|
||||
2
my/myhelp.sql
Normal file
2
my/myhelp.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
@help &&1
|
||||
@help2 &&1
|
||||
25
my/mytemp.sql
Normal file
25
my/mytemp.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
@@myheader.sql
|
||||
|
||||
|
||||
COLUMN _wh NEW_VALUE wh NOPRINT
|
||||
COLUMN _ob NEW_VALUE ob NOPRINT
|
||||
|
||||
select
|
||||
LENGTH(TRIM('&&1'))
|
||||
from dual;
|
||||
|
||||
|
||||
select
|
||||
CASE WHEN '&&1' is null THEN
|
||||
'Defa'
|
||||
ELSE
|
||||
'&&1'
|
||||
END
|
||||
from dual;
|
||||
|
||||
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
|
||||
|
||||
114
my/racasqlmon.sql
Normal file
114
my/racasqlmon.sql
Normal file
@@ -0,0 +1,114 @@
|
||||
-- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com
|
||||
-- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions.
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
--
|
||||
-- File name: asqlmon.sql (v1.3)
|
||||
--
|
||||
-- Purpose: Report SQL-monitoring-style drill-down into where in an execution plan the execution time is spent
|
||||
--
|
||||
-- Author: Tanel Poder
|
||||
--
|
||||
-- Copyright: (c) http://blog.tanelpoder.com - All rights reserved.
|
||||
--
|
||||
-- Disclaimer: This script is provided "as is", no warranties nor guarantees are
|
||||
-- made. Use at your own risk :)
|
||||
--
|
||||
-- Usage: @asqlmon <sqlid> <child#> <from_time> <to_time>
|
||||
--
|
||||
-- Notes: This script runs on Oracle 11g+ and you should have the
|
||||
-- Diagnostics pack license for using it as it queries
|
||||
-- some separately licensed views.
|
||||
--
|
||||
------------------------------------------------------------------------------------------------------------------------
|
||||
SET LINESIZE 999 PAGESIZE 5000 TRIMOUT ON TRIMSPOOL ON
|
||||
|
||||
COL asqlmon_operation HEADING Plan_Operation FORMAT A72
|
||||
COL asqlmon_predicates HEAD PREDICATES FOR a100 word_wrap
|
||||
COL obj_alias_qbc_name FOR a40
|
||||
COL options FOR a30
|
||||
|
||||
COL asqlmon_plan_hash_value HEAD PLAN_HASH_VALUE FOR 99999999999
|
||||
COL asqlmon_sql_id HEAD SQL_ID
|
||||
COL asqlmon_sql_child HEAD CHILD FOR 999999
|
||||
|
||||
COL pct_child HEAD "Activity %" FOR A8
|
||||
COL pct_child_vis HEAD "Visual" FOR A12
|
||||
|
||||
COL asqlmon_id HEAD "ID" FOR 9999
|
||||
COL asqlmon_parent_id HEAD "PID" FOR 9999
|
||||
|
||||
COL inst_id HEAD "I#" FOR 99
|
||||
|
||||
BREAK ON asqlmon_sql_id SKIP 1 ON asqlmon_sql_child SKIP 1 ON asqlmon_plan_hash_value SKIP 1 ON asqlmon_operation
|
||||
|
||||
PROMPT
|
||||
PROMPT -- ASQLMon v1.3 - by Tanel Poder ( https://tanelpoder.com ) - Display SQL execution plan line level activity breakdown from ASH
|
||||
|
||||
WITH sample_times AS (
|
||||
select * from dual
|
||||
),
|
||||
sq AS (
|
||||
SELECT
|
||||
count(*) samples
|
||||
, ash.inst_id
|
||||
, ash.sql_id
|
||||
, ash.sql_child_number
|
||||
, ash.sql_plan_hash_value
|
||||
, NVL(ash.sql_plan_line_id,1) sql_plan_line_id -- this is because simple "planless" operations like single-row insert
|
||||
, ash.sql_plan_operation
|
||||
, ash.sql_plan_options
|
||||
, ash.session_state
|
||||
, ash.event
|
||||
-- , AVG(ash.p3) avg_p3 -- p3 is sometimes useful for listing block counts for IO wait events
|
||||
FROM
|
||||
gv$active_session_history ash
|
||||
WHERE
|
||||
1=1
|
||||
AND ash.sql_id LIKE '&1'
|
||||
AND ash.sql_child_number LIKE '&2'
|
||||
AND ash.sample_time BETWEEN &3 AND &4
|
||||
GROUP BY
|
||||
ash.inst_id
|
||||
, ash.sql_id
|
||||
, ash.sql_child_number
|
||||
, ash.sql_plan_hash_value
|
||||
, NVL(ash.sql_plan_line_id,1)
|
||||
, ash.sql_plan_operation
|
||||
, ash.sql_plan_options
|
||||
, ash.session_state
|
||||
, ash.event
|
||||
)
|
||||
SELECT
|
||||
sq.inst_id
|
||||
, plan.child_number asqlmon_sql_child
|
||||
, plan.plan_hash_value asqlmon_plan_hash_value
|
||||
, sq.samples seconds
|
||||
, LPAD(TO_CHAR(ROUND(RATIO_TO_REPORT(sq.samples) OVER (PARTITION BY sq.sql_id, sq.sql_plan_hash_value) * 100, 1), 999.9)||' %',8) pct_child
|
||||
, '|'||RPAD( NVL( LPAD('#', ROUND(RATIO_TO_REPORT(sq.samples) OVER (PARTITION BY sq.sql_id, sq.sql_plan_hash_value) * 10), '#'), ' '), 10,' ')||'|' pct_child_vis
|
||||
--, LPAD(plan.id,4)||CASE WHEN parent_id IS NULL THEN ' ' ELSE ' <- ' END||LPAD(plan.parent_id,4) asqlmon_plan_id
|
||||
, plan.id asqlmon_id
|
||||
, plan.parent_id asqlmon_parent_id
|
||||
, LPAD(' ', depth, ' ') || plan.operation ||' '|| plan.options || NVL2(plan.object_name, ' ['||plan.object_name ||']', null) asqlmon_operation
|
||||
, sq.session_state
|
||||
, sq.event
|
||||
-- , sq.avg_p3
|
||||
, plan.object_alias || CASE WHEN plan.qblock_name IS NOT NULL THEN ' ['|| plan.qblock_name || ']' END obj_alias_qbc_name
|
||||
-- , CASE WHEN plan.access_predicates IS NOT NULL THEN '[A:] '|| SUBSTR(plan.access_predicates,1,1990) END || CASE WHEN plan.filter_predicates IS NOT NULL THEN ' [F:] ' || SUBSTR(plan.filter_predicates,1,1990) END asqlmon_predicates
|
||||
-- , plan.projection
|
||||
FROM
|
||||
gv$sql_plan plan
|
||||
, sq
|
||||
WHERE
|
||||
1=1
|
||||
AND sq.sql_id(+) = plan.sql_id
|
||||
AND sq.sql_child_number(+) = plan.child_number
|
||||
AND sq.sql_plan_line_id(+) = plan.id
|
||||
AND sq.sql_plan_hash_value(+) = plan.plan_hash_value
|
||||
AND plan.sql_id LIKE '&1'
|
||||
AND plan.child_number LIKE '&2'
|
||||
ORDER BY
|
||||
plan.child_number
|
||||
, plan.plan_hash_value
|
||||
, plan.id
|
||||
/
|
||||
80
my/raclocks.sql
Normal file
80
my/raclocks.sql
Normal file
@@ -0,0 +1,80 @@
|
||||
-- https://easyteam.fr/dealing-with-lock-issues-in-oracle-rac-environnement/
|
||||
|
||||
@@myheader.sql
|
||||
|
||||
col running_session for a20
|
||||
col machine for a30
|
||||
col osuser for a20
|
||||
col username for a20
|
||||
col module for a20
|
||||
col event for a30
|
||||
col wait_class for a20
|
||||
col inst_id for 9 head I#
|
||||
|
||||
WITH
|
||||
-- global lock view
|
||||
gl AS (
|
||||
select
|
||||
inst_id || '-' || sid instsid, id1, id2,
|
||||
ctime, lmode, block, request
|
||||
from
|
||||
gv$lock
|
||||
),
|
||||
-- joins the global lock view on itself to identify locks
|
||||
l AS (
|
||||
SELECT
|
||||
l1.instsid holding_session,
|
||||
l2.instsid waiting_session
|
||||
FROM
|
||||
gl l1,
|
||||
gl l2
|
||||
WHERE
|
||||
l1.block > 0
|
||||
AND l2.request > 0
|
||||
AND l1.id1=l2.id1
|
||||
AND l1.id2=l2.id2
|
||||
),
|
||||
-- result view (tree of locked sessions)
|
||||
rs AS (
|
||||
SELECT
|
||||
lpad(' ',3*(level-1),' ') || waiting_session running_session
|
||||
FROM (
|
||||
-- first insert as in utllockt
|
||||
(SELECT
|
||||
'-' holding_session, holding_session waiting_session
|
||||
FROM
|
||||
l
|
||||
MINUS
|
||||
SELECT
|
||||
'-', waiting_session
|
||||
FROM
|
||||
l
|
||||
)
|
||||
UNION ALL
|
||||
-- second insert as in utllockt
|
||||
SELECT
|
||||
holding_session, waiting_session
|
||||
FROM
|
||||
l
|
||||
)
|
||||
CONNECT BY PRIOR
|
||||
waiting_session = holding_session
|
||||
START WITH
|
||||
holding_session = '-'
|
||||
),
|
||||
-- useful session informations
|
||||
s AS (
|
||||
SELECT
|
||||
inst_id, sid,serial#, module,machine, osuser, username,
|
||||
nvl(sql_id, '-') sql_id, event, wait_class
|
||||
FROM gv$session
|
||||
)
|
||||
-- final tree
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
rs
|
||||
JOIN
|
||||
s ON ltrim(rs.running_session)=s.inst_id || '-' || s.sid;
|
||||
|
||||
@@myfooter.sql
|
||||
46
my/random_data/STORE_random_01.sql
Normal file
46
my/random_data/STORE_random_01.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
declare
|
||||
id VARCHAR2(40);
|
||||
firstname VARCHAR2(20);
|
||||
lastname VARCHAR2(20);
|
||||
name VARCHAR2(50);
|
||||
birthdate DATE;
|
||||
zip VARCHAR2(5);
|
||||
i NUMBER;
|
||||
rand1 NUMBER;
|
||||
rand2 NUMBER;
|
||||
rand3 NUMBER;
|
||||
max_id_firstname NUMBER;
|
||||
max_id_lastname NUMBER;
|
||||
max_id_city NUMBER;
|
||||
begin
|
||||
select max(id) into max_id_firstname from US_FIRSTNAME;
|
||||
select max(id) into max_id_lastname from US_LASTNAME;
|
||||
select max(id) into max_id_city from CITY;
|
||||
|
||||
for i in 1..1000000 loop
|
||||
rand1:=round(dbms_random.value(1,max_id_firstname));
|
||||
rand2:=round(dbms_random.value(1,max_id_lastname));
|
||||
rand3:=round(dbms_random.value(1,max_id_city));
|
||||
SELECT FIRSTNAME into firstname FROM US_FIRSTNAME where ID=rand1;
|
||||
SELECT LASTNAME into lastname FROM US_LASTNAME where ID=rand2;
|
||||
SELECT ZIP into zip FROM CITY where ID=rand3;
|
||||
|
||||
NAME:=FIRSTNAME ||' '|| LASTNAME;
|
||||
|
||||
SELECT TO_DATE(
|
||||
TRUNC(
|
||||
DBMS_RANDOM.VALUE(TO_CHAR(DATE '1960-01-01','J')
|
||||
,TO_CHAR(DATE '2011-12-31','J')
|
||||
)
|
||||
),'J'
|
||||
) into birthdate FROM DUAL;
|
||||
|
||||
insert into CLIENT(ID,NAME,BIRTHDATE,ZIP) values (i,NAME,BIRTHDATE,ZIP);
|
||||
if mod(i,10000)=0 then
|
||||
commit;
|
||||
end if;
|
||||
end loop;
|
||||
commit;
|
||||
end;
|
||||
/
|
||||
|
||||
26
my/random_data/STORE_random_02.sql
Normal file
26
my/random_data/STORE_random_02.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
declare
|
||||
max_id_client NUMBER;
|
||||
max_id_street NUMBER;
|
||||
i NUMBER;
|
||||
rand1 NUMBER;
|
||||
rand2 NUMBER;
|
||||
random_address VARCHAR2(50);
|
||||
random_street VARCHAR2(40);
|
||||
|
||||
begin
|
||||
select max(id) into max_id_client from CLIENT;
|
||||
select max(id) into max_id_street from US_STREET;
|
||||
|
||||
for i in 1..max_id_client loop
|
||||
rand1:=round(dbms_random.value(1,max_id_street));
|
||||
rand2:=round(dbms_random.value(1,400));
|
||||
|
||||
select FULLNAME into random_street from US_STREET where ID=rand1;
|
||||
random_address:=to_char(rand2)||' '||random_street;
|
||||
|
||||
update CLIENT set ADDRESS=random_address where ID=i;
|
||||
end loop;
|
||||
commit;
|
||||
end;
|
||||
/
|
||||
|
||||
97
my/random_data/scratch_01.sql
Normal file
97
my/random_data/scratch_01.sql
Normal file
@@ -0,0 +1,97 @@
|
||||
drop table R1 purge;
|
||||
create table R1 as
|
||||
select
|
||||
rownum ID,
|
||||
round(dbms_random.value(1,100000)) N1,
|
||||
round(dbms_random.value(1,1000)) N2,
|
||||
case
|
||||
when mod(rownum,10)=0 then 'BINGO'
|
||||
else
|
||||
dbms_random.string('X',5)
|
||||
end S1,
|
||||
TO_DATE(
|
||||
TRUNC(
|
||||
dbms_random.value(TO_CHAR(DATE '1960-01-01','J')
|
||||
,TO_CHAR(DATE '2011-12-31','J')
|
||||
)
|
||||
),'J'
|
||||
) D1,
|
||||
'Record #'||to_char(rownum) S2
|
||||
from
|
||||
dual
|
||||
connect by level<=100000;
|
||||
|
||||
|
||||
drop table R2 purge;
|
||||
create table R2 as
|
||||
select
|
||||
rownum ID,
|
||||
dbms_random.string('X',5) S1,
|
||||
case
|
||||
when mod(rownum,3)=0 then 'M3'
|
||||
else
|
||||
dbms_random.string('X',5)
|
||||
end S2,
|
||||
round(dbms_random.value(1,100)) N1,
|
||||
TO_DATE(
|
||||
TRUNC(
|
||||
dbms_random.value(TO_CHAR(DATE '1960-01-01','J')
|
||||
,TO_CHAR(DATE '2011-12-31','J')
|
||||
)
|
||||
),'J'
|
||||
) D1
|
||||
from
|
||||
dual
|
||||
connect by level<=1000;
|
||||
|
||||
drop table R3 purge;
|
||||
create table R3 as
|
||||
select
|
||||
rownum ID,
|
||||
dbms_random.string('X',5) S1,
|
||||
case
|
||||
when mod(rownum,2)=0 then 'M2'
|
||||
else
|
||||
dbms_random.string('X',5)
|
||||
end S2,
|
||||
round(dbms_random.value(1,1000)) N1
|
||||
from
|
||||
dual
|
||||
connect by level<=1000;
|
||||
|
||||
|
||||
drop table R4 purge;
|
||||
create table R4 as
|
||||
select
|
||||
rownum ID,
|
||||
dbms_random.string('X',5) S1,
|
||||
TO_DATE(
|
||||
TRUNC(
|
||||
dbms_random.value(TO_CHAR(DATE '1960-01-01','J')
|
||||
,TO_CHAR(DATE '2011-12-31','J')
|
||||
)
|
||||
),'J'
|
||||
) D1
|
||||
from
|
||||
dual
|
||||
connect by level<=10000;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE R1 MODIFY (ID NOT NULL);
|
||||
ALTER TABLE R1 ADD CONSTRAINT R1_PK PRIMARY KEY (ID) ENABLE;
|
||||
|
||||
ALTER TABLE R2 MODIFY (ID NOT NULL);
|
||||
ALTER TABLE R2 ADD CONSTRAINT R2_PK PRIMARY KEY (ID) ENABLE;
|
||||
|
||||
ALTER TABLE R3 MODIFY (ID NOT NULL);
|
||||
ALTER TABLE R3 ADD CONSTRAINT R3_PK PRIMARY KEY (ID) ENABLE;
|
||||
|
||||
ALTER TABLE R4 MODIFY (ID NOT NULL);
|
||||
ALTER TABLE R4 ADD CONSTRAINT R4_PK PRIMARY KEY (ID) ENABLE;
|
||||
|
||||
|
||||
ALTER TABLE R1 ADD CONSTRAINT R1_FK1 FOREIGN KEY(N2) REFERENCES R2(ID) ENABLE;
|
||||
ALTER TABLE R3 ADD CONSTRAINT R3_FK1 FOREIGN KEY(N1) REFERENCES R2(ID) ENABLE;
|
||||
ALTER TABLE R2 ADD CONSTRAINT R2_FK1 FOREIGN KEY(N1) REFERENCES R4(ID) ENABLE;
|
||||
|
||||
1
my/sess.sql
Symbolic link
1
my/sess.sql
Symbolic link
@@ -0,0 +1 @@
|
||||
../idev/sess_users.sql
|
||||
1
my/sessa.sql
Symbolic link
1
my/sessa.sql
Symbolic link
@@ -0,0 +1 @@
|
||||
../idev/sess_users_active.sql
|
||||
35
my/sqlmon_rep.sql
Normal file
35
my/sqlmon_rep.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
@@myheader.sql
|
||||
|
||||
set long 10000000 longchunksize 10000000 pages 0
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
UNDEFINE rid
|
||||
UNDEFINE type
|
||||
|
||||
DEFINE rid="&&1"
|
||||
DEFINE type="&&2"
|
||||
|
||||
COLUMN _type NEW_VALUE type NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
DECODE('&&type','','TEXT',UPPER('&&type')) "_type"
|
||||
FROM DUAL;
|
||||
set term on
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * SINGLE STATS OPERATION DETAIL
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - report id = '&&rid'
|
||||
PROMPT * - type = '&&type'
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
|
||||
select dbms_auto_report.report_repository_detail(rid => &&rid, type => '&&type')
|
||||
from dual;
|
||||
|
||||
@@myfooter.sql
|
||||
106
my/sqlmon_sqlid.sql
Normal file
106
my/sqlmon_sqlid.sql
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
|
||||
Usage:
|
||||
@sqlmon_sqlid <sql_id> <start_time> <end_time>
|
||||
|
||||
Examples:
|
||||
|
||||
@sqlmon_sqlid 8c2mb6gp8w8zy sysdate-1 sysdate
|
||||
@sqlmon_sqlid 8c2mb6gp8w8zy "timestamp'2023-04-22 09:30:45'" "timestamp'2023-04-22 12:00:00'"
|
||||
*/
|
||||
|
||||
@@myheader.sql
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * List SQL Monitor reports
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - sql_id = &&1
|
||||
PROMPT * - min timestamp = &&2
|
||||
PROMPT * - min timestamp = &&3
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
set pages 50
|
||||
|
||||
column report_id format 99999999999 heading 'Report|ID'
|
||||
column status format a15 heading 'Status'
|
||||
column sql_id format a17 heading 'SQL_ID'
|
||||
column plan_hash format a15 heading 'Plan|hash value'
|
||||
column sql_exec_start format a21 heading 'SQL|start'
|
||||
column sql_exec_id format a12 heading 'SQL|exec ID'
|
||||
column elap_sec format 9999.99 heading 'Elapsed|sec'
|
||||
column cpu_sec format 9999.99 heading 'CPU|sec'
|
||||
column io_sec format 9999.99 heading 'IO|sec'
|
||||
column buffer_gets format a9 heading 'Buffer|gets'
|
||||
column px_servers_requested format a3 heading 'PX|req'
|
||||
column px_servers_allocated format a3 heading 'PX|all'
|
||||
column sess format a16 heading 'Session'
|
||||
column username format a15 heading 'Username'
|
||||
|
||||
|
||||
SELECT /*+ NO_XML_QUERY_REWRITE */
|
||||
t.report_id
|
||||
, t.key1 sql_id
|
||||
, t.key2 sql_exec_id
|
||||
, to_char(to_date(t.key3,'MM:DD:YYYY HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS') sql_exec_start
|
||||
, x.plan_hash
|
||||
, x.elapsed_time/1000000 elap_sec
|
||||
, x.cpu_time/1000000 cpu_sec
|
||||
, x.user_io_wait_time/1000000 io_sec
|
||||
, x.buffer_gets
|
||||
, x.username
|
||||
, ''''||t.session_id||','||t.session_serial#||'@'||t.instance_number||'''' sess
|
||||
, x.px_servers_requested
|
||||
, x.px_servers_allocated
|
||||
, x.status
|
||||
FROM dba_hist_reports t
|
||||
, xmltable('/report_repository_summary/sql'
|
||||
PASSING xmlparse(document t.report_summary)
|
||||
COLUMNS
|
||||
sql_id path '@sql_id'
|
||||
, sql_exec_start path '@sql_exec_start'
|
||||
, sql_exec_id path '@sql_exec_id'
|
||||
, status path 'status'
|
||||
, sql_text path 'sql_text'
|
||||
, first_refresh_time path 'first_refresh_time'
|
||||
, last_refresh_time path 'last_refresh_time'
|
||||
, refresh_count path 'refresh_count'
|
||||
, inst_id path 'inst_id'
|
||||
, session_id path 'session_id'
|
||||
, session_serial path 'session_serial'
|
||||
, user_id path 'user_id'
|
||||
, username path 'user'
|
||||
, con_id path 'con_id'
|
||||
, con_name path 'con_name'
|
||||
, modul path 'module'
|
||||
, action path 'action'
|
||||
, service path 'service'
|
||||
, program path 'program'
|
||||
, plan_hash path 'plan_hash'
|
||||
, is_cross_instance path 'is_cross_instance'
|
||||
, dop path 'dop'
|
||||
, instances path 'instances'
|
||||
, px_servers_requested path 'px_servers_requested'
|
||||
, px_servers_allocated path 'px_servers_allocated'
|
||||
, duration path 'stats/stat[@name="duration"]'
|
||||
, elapsed_time path 'stats/stat[@name="elapsed_time"]'
|
||||
, cpu_time path 'stats/stat[@name="cpu_time"]'
|
||||
, user_io_wait_time path 'stats/stat[@name="user_io_wait_time"]'
|
||||
, application_wait_time path 'stats/stat[@name="application_wait_time"]'
|
||||
, concurrency_wait_time path 'stats/stat[@name="concurrency_wait_time"]'
|
||||
, cluster_wait_time path 'stats/stat[@name="cluster_wait_time"]'
|
||||
, plsql_exec_time path 'stats/stat[@name="plsql_exec_time"]'
|
||||
, other_wait_time path 'stats/stat[@name="other_wait_time"]'
|
||||
, buffer_gets path 'stats/stat[@name="buffer_gets"]'
|
||||
, read_reqs path 'stats/stat[@name="read_reqs"]'
|
||||
, read_bytes path 'stats/stat[@name="read_bytes"]'
|
||||
) x
|
||||
where
|
||||
t.key1= '&&1'
|
||||
and t.COMPONENT_NAME='sqlmonitor'
|
||||
and to_date(t.key3,'MM:DD:YYYY HH24:MI:SS') between &&2 and &&3
|
||||
order by sql_exec_start
|
||||
/
|
||||
|
||||
@@myfooter.sql
|
||||
131
my/stats_hhist.sql
Normal file
131
my/stats_hhist.sql
Normal file
@@ -0,0 +1,131 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
DEFINE tab="&&1"
|
||||
DEFINE col="&&2"
|
||||
|
||||
UNDEFINE owner
|
||||
UNDEFINE table_name
|
||||
UNDEFINE col_name
|
||||
|
||||
COLUMN _owner NEW_VALUE owner NOPRINT
|
||||
COLUMN _table_name NEW_VALUE table_name NOPRINT
|
||||
COLUMN _col_name NEW_VALUE col_name NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
upper(CASE
|
||||
WHEN INSTR('&&tab','.') > 0 THEN
|
||||
SUBSTR('&&tab',INSTR('&&tab','.')+1)
|
||||
ELSE
|
||||
'&tab'
|
||||
END
|
||||
)
|
||||
"_table_name"
|
||||
, upper(CASE
|
||||
WHEN INSTR('&&tab','.') > 0 THEN
|
||||
UPPER(SUBSTR('&&tab',1,INSTR('&&tab','.')-1))
|
||||
ELSE
|
||||
user
|
||||
END
|
||||
)
|
||||
"_owner"
|
||||
, upper('&&col')
|
||||
"_col_name"
|
||||
FROM DUAL;
|
||||
|
||||
|
||||
|
||||
set term on
|
||||
|
||||
PROMPT
|
||||
PROMPT *************************************************
|
||||
PROMPT * Historical column histogram values
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - owner = '&&owner'
|
||||
PROMPT * - table_name = '&&table_name'
|
||||
PROMPT * - col_name = '&&col_name'
|
||||
PROMPT *************************************************
|
||||
|
||||
/* ----------------------------------------------------------------------------------|
|
||||
|Author : Mohamed Houri |
|
||||
|Date : 03/07/2020 |
|
||||
|Scope : This script gives historical column histogram values |
|
||||
| -- I am using sys.WRI$_OPTSTAT_HISTHEAD_HISTORY for this purpose |
|
||||
| -- I am only able to say whether, previously, there was HISTOGRAM or not |
|
||||
| -- I can't show the historical type of Histogram |
|
||||
| | |
|
||||
-------------------------------------------------------------------------------------|*/
|
||||
|
||||
col object_name format a25
|
||||
col column_name format a25
|
||||
col last_analyzed format a20
|
||||
col prev_last_analyzed format a20
|
||||
col histogram format a16
|
||||
col prev_histogram format a16
|
||||
WITH sq AS
|
||||
(
|
||||
SELECT
|
||||
object_id
|
||||
,object_name
|
||||
,subobject_name
|
||||
FROM
|
||||
dba_objects
|
||||
WHERE
|
||||
object_name = upper ('&&table_name')
|
||||
AND owner = upper('&&owner')
|
||||
AND subobject_name IS NULL
|
||||
)
|
||||
SELECT
|
||||
object_name
|
||||
,column_name
|
||||
,lead(prev_histogram,1,histogram) over (order by last_analyzed) histogram
|
||||
,last_analyzed
|
||||
,prev_histogram
|
||||
,prev_last_analyzed
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
object_name
|
||||
,column_name
|
||||
,(select histogram from all_tab_col_statistics where owner = upper('&&owner')
|
||||
and table_name = upper('&&table_name') and column_name = upper('&&col_name')) histogram
|
||||
,last_analyzed
|
||||
,stat_time prev_last_analyzed
|
||||
,row_number() over (order by last_analyzed) rn
|
||||
,case when round(derivedDensity,9)= round(density,9) then 'NONE' else 'HISTOGRAM' end prev_histogram
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
object_name
|
||||
,column_name
|
||||
,to_char(savtime ,'yyyy-mm-dd hh24:mi:ss') last_analyzed
|
||||
,to_char(timestamp# ,'yyyy-mm-dd hh24:mi:ss') stat_time
|
||||
,density
|
||||
,1/distcnt derivedDensity
|
||||
,row_number() over (order by savtime) rn
|
||||
,lag(case when round(1/distcnt,9) = round(density,9) then 'NONE' else 'HISTOGRAM' end) over(order by savtime) hist_histogram
|
||||
FROM
|
||||
sys.WRI$_OPTSTAT_HISTHEAD_HISTORY
|
||||
INNER JOIN sq ON object_id = obj#
|
||||
INNER JOIN (SELECT
|
||||
column_id
|
||||
,column_name
|
||||
FROM
|
||||
dba_tab_columns
|
||||
WHERE
|
||||
column_name = upper('&&col_name')
|
||||
AND table_name = upper('&&table_name')
|
||||
AND owner = upper('&&owner')
|
||||
) ON intcol# = column_id
|
||||
)
|
||||
WHERE
|
||||
rn >= 1 --exlcude/include the very first dbms_stat
|
||||
)
|
||||
ORDER BY
|
||||
last_analyzed;
|
||||
|
||||
@@myfooter.sql
|
||||
43
my/stats_opdet.sql
Normal file
43
my/stats_opdet.sql
Normal file
@@ -0,0 +1,43 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
UNDEFINE opid
|
||||
UNDEFINE detail_level
|
||||
|
||||
DEFINE opid="&&1"
|
||||
DEFINE detail_level="&&2"
|
||||
DEFINE format="&&3"
|
||||
|
||||
COLUMN _opid NEW_VALUE opid NOPRINT
|
||||
COLUMN _detail_level NEW_VALUE detail_level NOPRINT
|
||||
COLUMN _format NEW_VALUE format NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
DECODE('&&detail_level','','BASIC',UPPER('&&detail_level')) "_detail_level"
|
||||
, DECODE('&&format','','TEXT',UPPER('&&format')) "_format"
|
||||
FROM DUAL;
|
||||
set term on
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * SINGLE STATS OPERATION DETAIL
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - opid = '&&opid'
|
||||
PROMPT * - detail_level = '&&detail_level'
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
select
|
||||
dbms_stats.report_single_stats_operation(
|
||||
opid => &&opid
|
||||
,detail_level => '&&detail_level'
|
||||
,format => '&&format'
|
||||
)
|
||||
from dual;
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
49
my/stats_opls.sql
Normal file
49
my/stats_opls.sql
Normal file
@@ -0,0 +1,49 @@
|
||||
@@myheader.sql
|
||||
|
||||
/************************************
|
||||
* INPUT PARAMETERS
|
||||
************************************/
|
||||
UNDEFINE since
|
||||
UNDEFINE until
|
||||
UNDEFINE detail_level
|
||||
UNDEFINE format
|
||||
|
||||
DEFINE since="&&1"
|
||||
DEFINE until="&&2"
|
||||
DEFINE detail_level="&&3"
|
||||
DEFINE format="&&4"
|
||||
|
||||
COLUMN _detail_level NEW_VALUE detail_level NOPRINT
|
||||
COLUMN _format NEW_VALUE format NOPRINT
|
||||
|
||||
set term off
|
||||
SELECT
|
||||
DECODE('&&detail_level','','BASIC',UPPER('&&detail_level')) "_detail_level"
|
||||
, DECODE('&&format','','TEXT',UPPER('&&format')) "_format"
|
||||
FROM DUAL;
|
||||
set term on
|
||||
|
||||
|
||||
PROMPT
|
||||
PROMPT ***********************************************************************
|
||||
PROMPT * STATS OPERATIONS
|
||||
PROMPT *
|
||||
PROMPT * Input Parameters
|
||||
PROMPT * - since = '&&since'
|
||||
PROMPT * - until = '&&until'
|
||||
PROMPT * - detail_level = '&&detail_level'
|
||||
PROMPT * - format = '&&format'
|
||||
PROMPT ***********************************************************************
|
||||
|
||||
|
||||
select
|
||||
DBMS_STATS.REPORT_STATS_OPERATIONS (
|
||||
since => &&since
|
||||
,until => &&until
|
||||
,detail_level => '&&detail_level'
|
||||
,format => '&&format'
|
||||
)
|
||||
from dual;
|
||||
|
||||
|
||||
@@myfooter.sql
|
||||
20
my/stdby_redolog.sql
Normal file
20
my/stdby_redolog.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
col thread# for 9999990
|
||||
col sequence# for 999999990
|
||||
col grp for 990
|
||||
col fnm for a50 head "File Name"
|
||||
col "Fisrt SCN Number" for 999999999999990
|
||||
break on thread
|
||||
|
||||
select
|
||||
a.thread#
|
||||
,a.sequence#
|
||||
,a.group# grp
|
||||
, a.bytes/1024/1024 Size_MB
|
||||
,a.status
|
||||
,a.archived
|
||||
,a.first_change# "First SCN Number"
|
||||
,to_char(FIRST_TIME,'YYYY-MM-DD HH24:MI:SS') "First SCN Time"
|
||||
,to_char(LAST_TIME,'YYYY-MM-DD HH24:MI:SS') "Last SCN Time"
|
||||
from
|
||||
gv$standby_log a order by 1,2,3,4
|
||||
/
|
||||
32
my/whoami.sql
Normal file
32
my/whoami.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- give information on the own session without needing additional privs
|
||||
-- credits to Uwe Hesse
|
||||
--
|
||||
-- changed to use select from dual instead of dbms_output
|
||||
|
||||
column username format a30
|
||||
column sess format a15
|
||||
column current_schema format a30
|
||||
column instance_name format a15
|
||||
column pdb_name format a15
|
||||
column database_role format a20
|
||||
column os_user format a20
|
||||
column client_ip format a20
|
||||
column server_hostname format a20
|
||||
column client_hostname format a20
|
||||
|
||||
select
|
||||
sys_context('userenv','session_user') as username,
|
||||
''''||sys_context('userenv','sid')||','||sys_context('userenv','sessionid')||'@'||sys_context('userenv','instance')||'''' as sess,
|
||||
sys_context('userenv','current_schema') as current_schema,
|
||||
sys_context('userenv','instance_name') as instance_name,
|
||||
sys_context('userenv','con_name') as pdb_name,
|
||||
sys_context('userenv','database_role') as database_role,
|
||||
sys_context('userenv','os_user') as os_user,
|
||||
sys_context('userenv','ip_address') as client_ip,
|
||||
sys_context('userenv','host') as client_hostname,
|
||||
sys_context('userenv','server_host') as server_hostname
|
||||
from
|
||||
dual
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user