mise à jour v2

Grosse mise à jour :
- style moderne des tableaux et code
- code structuré et factorisé
- sql et sh affinés
This commit is contained in:
Yacine31
2025-11-19 15:55:11 +01:00
parent 2832bd82e8
commit 4e7683aee2
66 changed files with 586 additions and 577 deletions

View File

@@ -1,6 +1,6 @@
prompt <h2>System Information</h2>
WITH /* 1a.1 */
rac AS (SELECT /*+ MATERIALIZE NO_MERGE */ COUNT(*) instances, CASE COUNT(*) WHEN 1 THEN 'Single-instance' ELSE COUNT(*)||'-node RAC cluster' END db_type FROM gv$instance),
rac AS (select /* db-html-report */ /*+ MATERIALIZE NO_MERGE */ COUNT(*) instances, CASE COUNT(*) WHEN 1 THEN 'Single-instance' ELSE COUNT(*)||'-node RAC cluster' END db_type FROM gv$instance),
hrac AS (SELECT /*+ MATERIALIZE NO_MERGE */ CASE 1 WHEN 1 THEN ' (historically Single-instance in AWR)' ELSE ' (historicly 1-node RAC cluster in AWR)' END db_type
FROM rac WHERE TO_CHAR(RAC.instances)<>1),
mem AS (SELECT /*+ MATERIALIZE NO_MERGE */ SUM(value) target FROM gv$system_parameter2 WHERE name = 'memory_target'),

View File

@@ -2,7 +2,7 @@ prompt <h2>Taille de la base de données :</h2>
WITH
sizes AS (
SELECT /*+ MATERIALIZE NO_MERGE */ /* 1f.60 */
select /* db-html-report */ /*+ MATERIALIZE NO_MERGE */ /* 1f.60 */
'Data' file_type,
SUM(bytes) bytes
FROM v$datafile

View File

@@ -1,7 +1,7 @@
prompt <h2>Database/Instance Status</h2>
alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';
SELECT 'DATABASE_NAME' AS property, name AS value FROM gv$database
select /* db-html-report */ 'DATABASE_NAME' AS property, name AS value FROM gv$database
UNION ALL
SELECT 'DATABASE_ROLE' AS property, DATABASE_ROLE AS value FROM gv$database
UNION ALL

View File

@@ -1,6 +1,6 @@
prompt <h2>Database/Version</h2>
SELECT
select /* db-html-report */
*
FROM
V$VERSION;

View File

@@ -1,6 +1,6 @@
prompt <h2>Paramèters de la base de données : </h2>
SELECT
select /* db-html-report */
NAME,
DISPLAY_VALUE,
DESCRIPTION,

View File

@@ -1,4 +1,3 @@
prompt <h2>Paramètres NLS au niveau de la base de données :</h2>
-- SELECT * FROM NLS_DATABASE_PARAMETERS ORDER BY PARAMETER;
select * from gv$nls_parameters order by PARAMETER ;
select /* db-html-report */ * from gv$nls_parameters order by PARAMETER ;

View File

@@ -1,6 +1,6 @@
prompt <h2>Database supplemental logging :</h2>
select 'force_logging' as property, force_logging as value from v$database
select /* db-html-report */ 'force_logging' as property, force_logging as value from v$database
union all
select 'supplemental_log_data_min' as property, supplemental_log_data_min as value from v$database
union all

View File

@@ -1,6 +1,6 @@
prompt <h2>Fonctionnalités installées dans la base de données (DBA_REGISTRY) :</h2>
SELECT
select /* db-html-report */
*
FROM
DBA_REGISTRY

View File

@@ -1,6 +1,6 @@
prompt <h2>Resource Limit (GV$RESOURCE_LIMIT)</h2>
SELECT
select /* db-html-report */
*
FROM
GV$RESOURCE_LIMIT

View File

@@ -1,7 +1,7 @@
prompt <h2>Memory Information</h2>
WITH
system_parameter AS (
SELECT inst_id,
select /* db-html-report */ inst_id,
name,
value
FROM gv$system_parameter2

View File

@@ -2,7 +2,7 @@ prompt <h2>Les 50 dernières opérations de Resize de la mémoire :</h2>
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
SELECT
select /* db-html-report */
*
FROM
GV$MEMORY_RESIZE_OPS

View File

@@ -1,6 +1,6 @@
prompt <h2>SGA Target Advice</h2>
SELECT
select /* db-html-report */
*
FROM
GV$SGA_TARGET_ADVICE;

View File

@@ -12,7 +12,7 @@ COL free FORMAT 99999999.00 HEAD "Free MB"
COL max FORMAT 99999999.00 HEAD "MaxSize MB"
COL Pct_Used FORMAT 999.00 HEAD "% Used"
select
select /* db-html-report */
a.tablespace_name,
t.bigfile,
a.bytes_alloc/1024/1024 alloc,

View File

@@ -1,49 +0,0 @@
prompt <h2>Détail des datafiles : </h2>
COL file_id HEAD "File ID"
COL file_name HEAD "Datafile"
COL tablespace_name FORMAT A20 HEAD "Tablespace"
COL file_size_mb FORMAT 999999999.00 HEAD "File Size MB"
COL space_used_mb FORMAT 999999999.00 HEAD "Space Used MB"
COL space_free_mb FORMAT 999999999.00 HEAD "Space Free MB"
COL maxsize_mb FORMAT 999999999.00 HEAD "Max Size MB"
COL percent_used FORMAT 999.00 HEAD "% Used"
COL autoextensible FORMAT A15 HEAD "Auto Extensible"
COL status head "Status"
COL online_status format a15 head "Online Status"
select
d.file_id,
d.file_name,
d.tablespace_name,
a.bytes_alloc/1024/1024 file_size_mb,
(a.bytes_alloc - nvl(b.bytes_free, 0))/1024/1024 space_used_mb,
nvl(b.bytes_free, 0)/1024/1024 space_free_mb,
a.maxbytes/1024/1024 maxsize_mb,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / a.maxbytes * 100,2) percent_used,
d.autoextensible,
d.status,
d.online_status
from
(
select
f.file_id,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible, 'YES', f.maxbytes, 'NO', f.bytes)) maxbytes
from dba_data_files f group by file_id
) a,
(
select
f.file_id,
sum(f.bytes) bytes_free
from dba_free_space f group by file_id
) b,
dba_data_files d
where
a.file_id = b.file_id (+) and d.file_id=a.file_id
order by
d.file_name
;

View File

@@ -20,7 +20,7 @@ WITH
-- Sous-requête pour les fichiers de données dans une CDB
cdb_files AS (
-- cdb_files.sql
SELECT
select /* db-html-report */
p.con_id AS pdb_id,
p.pdb_name AS pdb_name,
d.file_id,

View File

@@ -20,7 +20,7 @@ WITH
-- Sous-requête pour les fichiers de données dans une CDB
cdb_files AS (
-- cdb_files.sql
SELECT
select /* db-html-report */
p.con_id AS pdb_id,
p.pdb_name AS pdb_name,
d.file_id,

View File

@@ -1,6 +1,6 @@
prompt <h3>Détail du tablespace UNDO : </h3>
SELECT
select /* db-html-report */
a.tablespace_name,
a.file_id,
a.bytes / 1024 / 1024 AS size_mb,

View File

@@ -1,6 +1,6 @@
prompt <h2>Existance de blocks corrompus :</h2>
SELECT
select /* db-html-report */
*
FROM
V$DATABASE_BLOCK_CORRUPTION;

View File

@@ -2,7 +2,7 @@ prompt <h2>Fichiers de journalisation (Redolog) :</h2>
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
SELECT
select /* db-html-report */
*
FROM
V$LOG

View File

@@ -3,7 +3,7 @@ alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';
COL MEMBER FORMAT A90 WRAPPED
BREAK ON GROUP# SKIP 1 ON THREAD# ON SEQUENCE# ON TAILLE_MIB ON "STATUS(ARCHIVED)"
SELECT
select /* db-html-report */
'OnlineLog' t,
g.group#,
g.thread#,

View File

@@ -31,7 +31,7 @@ col 23 for 999
col 24 for 999
select to_char(first_time, 'YYYY/MM/dd') "Date",
select /* db-html-report */ to_char(first_time, 'YYYY/MM/dd') "Date",
count(1) "Total",
sum(decode(to_char(first_time, 'hh24'),'00',1,0)) "00",
sum(decode(to_char(first_time, 'hh24'),'01',1,0)) "01",

View File

@@ -1,6 +1,6 @@
prompt <h2>Taille des redolog par jour :</h2>
SELECT
select /* db-html-report */
TO_CHAR(FIRST_TIME, 'YYYY/MM/dd') "Jour",
COUNT(*) "Nbr de fichiers",
ROUND(SUM(BLOCKS*BLOCK_SIZE)/1024/1024, 0) "Taille_Mo"

View File

@@ -1,6 +1,6 @@
prompt <h2>Fast Recovery Area Usage</h2>
SELECT
select /* db-html-report */
'Taille FRA MiB' AS PROPERTY,
P.VALUE / 1024 / 1024 AS VALUE
FROM

View File

@@ -1,2 +1,2 @@
prompt <h2>Fast Recovery Area Usage</h2>
SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;
select /* db-html-report */ * FROM V$FLASH_RECOVERY_AREA_USAGE;

View File

@@ -1,6 +1,6 @@
prompt <h2>Les dernières erreurs de la base de données (Les 30 derniers jours et les 50 dernières lignes)</h2>
SELECT
select /* db-html-report */
TO_CHAR(ORIGINATING_TIMESTAMP, 'DD-MM-YYYY HH24:MM:SS') "Date",
MESSAGE_TEXT "Message"
FROM

View File

@@ -1,6 +1,6 @@
prompt <h2>Configuration RMAN: pramètres modifiés :</h2>
SELECT
select /* db-html-report */
*
FROM
V$RMAN_CONFIGURATION;

View File

@@ -2,7 +2,7 @@ prompt <h2>Les dernières sauvegardes RMAN (30 derniers jours/50 dernières lign
ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS';
SELECT
select /* db-html-report */
B.SESSION_KEY "Session Key",
B.INPUT_TYPE "Type",
TO_CHAR(B.START_TIME, 'DD-MM-YYYY HH24:MI') "Start Time",

View File

@@ -1,6 +1,6 @@
prompt <h2>SYSAUX Occupants</h2>
SELECT /*+ NO_MERGE */
select /* db-html-report */ /*+ NO_MERGE */
V.*,
ROUND(V.SPACE_USAGE_KBYTES / POWER(10, 6), 3) SPACE_USAGE_GBS
FROM

View File

@@ -2,7 +2,7 @@ prompt <h2>DBA Users </h2>
ALTER SESSION SET NLS_DATE_FORMAT ='YYYY/MM/DD HH24:MI';
SELECT
select /* db-html-report */
X.USERNAME,
X.USER_ID,
X.ACCOUNT_STATUS,

View File

@@ -1,6 +1,6 @@
prompt <h2>DBA_Profiles </h2>
SELECT
select /* db-html-report */
*
FROM
DBA_PROFILES

View File

@@ -1,6 +1,6 @@
prompt <h2>Taille des objets par schéma (Mo):</h2>
SELECT
select /* db-html-report */
DS.OWNER "Owner",
ROUND(SUM(DS.BYTES) / 1024 / 1024) "Schema Size MB",
DU.DEFAULT_TABLESPACE "Default Tablespace"

View File

@@ -2,7 +2,7 @@
prompt <h2>Sessions Aggregate per User and Type</h2>
WITH X AS (
SELECT
select /* db-html-report */
COUNT(*),
--con_id,
USERNAME,

View File

@@ -1,7 +1,7 @@
prompt <h2>Sessions Aggregate per Module and Action</h2>
WITH X AS (
SELECT
select /* db-html-report */
COUNT(*),
--con_id,
MODULE,

View File

@@ -10,7 +10,7 @@ col OSUSER for a10
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
SELECT
select /* db-html-report */
OSUSER,
MACHINE,
PROGRAM,

View File

@@ -1,6 +1,6 @@
prompt <h2>Invalid objects</h2>
SELECT
select /* db-html-report */
OWNER,
COUNT(*) "invalid objects"
FROM

View File

@@ -1,6 +1,6 @@
prompt <h2>Les objets par utilisateur</h2>
SELECT
select /* db-html-report */
*
FROM
(

View File

@@ -1,6 +1,6 @@
prompt <h2>Statut des jobs autotask </h2>
SELECT
select /* db-html-report */
CLIENT_NAME,
STATUS,
ATTRIBUTES,

View File

@@ -1,7 +1,7 @@
-- SCRIPT - to Set the 'SESSION_CACHED_CURSORS' and 'OPEN_CURSORS' Parameters Based on Usage (Doc ID 208857.1)
prompt <h2>Sessions and Cursors usage </h2>
SELECT
select /* db-html-report */
'session_cached_cursors' PARAMETER,
LPAD(VALUE, 5) VALUE,
DECODE(VALUE, 0, ' n/a', TO_CHAR(100 * USED / VALUE, '990')

View File

@@ -1,6 +1,6 @@
prompt <h2>Curseurs par Session (sans les users SYS, SYSTEM, SYSMAN)</h2>
select c.sid, s.username, count(*) open_cursors
select /* db-html-report */ c.sid, s.username, count(*) open_cursors
from gv$open_cursor c, gv$session s
where s.sid = c.sid
and s.username is not null and s.username not like 'SYS%'

View File

@@ -1,6 +1,6 @@
prompt <h2>Failed scheduled jobs </h2>
SELECT
select /* db-html-report */
OWNER,
JOB_NAME,
JOB_TYPE,

View File

@@ -3,7 +3,7 @@ prompt <h2>Table Statistics Summary</h2>
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
WITH X AS (
SELECT /*+ NO_MERGE */
select /* db-html-report */ /*+ NO_MERGE */
--con_id,
OWNER,
OBJECT_TYPE,

View File

@@ -1,6 +1,6 @@
prompt <h2>Dictionary Stats / Fixed Objects Stats</h2>
SELECT
select /* db-html-report */
TO_CHAR(MAX(END_TIME), 'dd/mm/yyyy hh24:mi') LATEST,
OPERATION
FROM

View File

@@ -2,7 +2,7 @@ prompt <h2>Les options utilisée (à partir de DBA_FEATURE_USAGE_STATISTICS): </
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
SELECT
select /* db-html-report */
NAME,
LAST_USAGE_DATE,
DETECTED_USAGES,

View File

@@ -1,8 +1,12 @@
prompt <h2>Liste des jobs dans : dba_jobs </h2>
prompt <h2>Liste des derniers jobs dans : CDB_SCHEDULER_JOB_LOG </h2>
ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';
SELECT
*
FROM
DBA_JOBS;
select /* db-html-report */
* from
(
select log_date, owner, job_name, status
from CDB_SCHEDULER_JOB_LOG
order by log_date desc
) where rownum <= 20
;

23
sql/41_sql_stat.sql Normal file
View File

@@ -0,0 +1,23 @@
prompt <h2>Top SQL</h2>
alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS';
select /* db-html-report */
* from (
select
a.inst_id,
a.sql_id,
a.elapsed_time / 1000000 as elapsed,
substrb(replace(a.sql_text,'',' '),1,55) as sql_text,
a.cpu_time / 1000000 as cpu_time,
a.buffer_gets, -- Lecture en memoire
a.disk_reads, -- Lecture sur disque
a.physical_read_bytes,
a.executions,
a.rows_processed,
a.last_active_time, -- Last time the statistics of a contributing cursor were updated
b.module
from gv$sqlstats a, gv$sql b
where a.sql_id=b.sql_id
order by a.elapsed_time desc
) where rownum <= 25;

View File

@@ -4,7 +4,7 @@ col application_root for a25
col application_pdb for a25
col application_seed for a25
SELECT
select /* db-html-report */
p.con_id,
p.dbid,
p.name,