Wednesday, 22 May 2019
You Cannot Analyze a Table Through a Synonym
This was tested on an Oracle 12 database. First I created a table and analyzed it:
$ sqlplus "/as sysdba"
SQL*Plus: Release 12.1.0.2.0 Production on Wed May 22 08:56:23 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> create table wasiq11 (one_col number);
Table created.
SQL> analyze table wasiq11 compute statistics;
Table analyzed.
Then I created a synonym for the table
SQL> create synonym wasiq22 for wasiq11;
Synonym created.
I found that I was able to describe the table via the synonym
SQL> desc wasiq22
Name Null? Type
----------------------------------------- -------- ----------------------------
ONE_COL NUMBER
but I could not able to analyze the table through a synonym
SQL> analyze table wasiq22 compute statistics;
analyze table wasiq22 compute statistics
*
ERROR at line 1:
ORA-00942: table or view does not exist
sqlplus /nolog
This allows you to start a SQL*Plus session without connecting to a database:
-bash-3.2$ sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Wed May 22 08:27:44 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
SQL> select sysdate from dual;
SP2-0640: Not connected
SQL> show user
USER is ""
SQL>
-bash-3.2$ sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Wed May 22 08:27:44 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
SQL> select sysdate from dual;
SP2-0640: Not connected
SQL> show user
USER is ""
SQL>
Tuesday, 21 May 2019
Oracle: Show installed components/options and feature-usage
To check which components are installed in a database:
SELECT * FROM DBA_REGISTRY;
This view also shows the coresponding schema to a component – and also it’s related schemas.
To check which options are enabled:
SELECT * FROM V$OPTION;
To check which features are used:
SELECT * FROM DBA_FEATURE_USAGE_STATISTICS;
SELECT * FROM DBA_REGISTRY;
This view also shows the coresponding schema to a component – and also it’s related schemas.
To check which options are enabled:
SELECT * FROM V$OPTION;
To check which features are used:
SELECT * FROM DBA_FEATURE_USAGE_STATISTICS;
Oracle script to check the database growth
SET LINESIZE 200
SET PAGESIZE 200
COL "Database Size" FORMAT a13
COL "Used Space" FORMAT a11
COL "Used in %" FORMAT a11
COL "Free in %" FORMAT a11
COL "Database Name" FORMAT a13
COL "Free Space" FORMAT a12
COL "Growth DAY" FORMAT a11
COL "Growth WEEK" FORMAT a12
COL "Growth DAY in %" FORMAT a16
COL "Growth WEEK in %" FORMAT a16
SELECT
(select min(creation_time) from v$datafile) "Create Time",
(select name from v$database) "Database Name",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2) || ' MB' "Database Size",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 ),2) || ' MB' "Used Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 )) / ROUND(SUM(USED.BYTES) / 1024 / 1024 ,2)*100,2) || '% MB' "Used in %",
ROUND((FREE.P / 1024 / 1024 ),2) || ' MB' "Free Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - ((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 )))/ROUND(SUM(USED.BYTES) / 1024 / 1024,2 )*100,2) || '% MB' "Free in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile),2) || ' MB' "Growth DAY",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100,3) || '% MB' "Growth DAY in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)*7,2) || ' MB' "Growth WEEK",
ROUND((((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100)*7,3) || '% MB' "Growth WEEK in %"
FROM (SELECT BYTES FROM V$DATAFILE
UNION ALL
SELECT BYTES FROM V$TEMPFILE
UNION ALL
SELECT BYTES FROM V$LOG) USED,
(SELECT SUM(BYTES) AS P FROM DBA_FREE_SPACE) FREE
GROUP BY FREE.P;
The below script lists the details of database growth per month:
select to_char(creation_time, 'MM-RRRR') "Month", sum(bytes)/1024/1024/1024 "Growth in GB"
from sys.v_$datafile
where to_char(creation_time,'RRRR')='2014'
group by to_char(creation_time, 'MM-RRRR')
order by to_char(creation_time, 'MM-RRRR');
SQL> select to_char(creation_time, 'MM-RRRR') "Month", sum(bytes)/1024/1024/1024 "Growth in GB"
from sys.v_$datafile
where to_char(creation_time,'RRRR')='2014'
group by to_char(creation_time, 'MM-RRRR')
order by to_char(creation_time, 'MM-RRRR'); 2 3 4 5
Month Growth in GB
------- ------------
05-2014 3
08-2014 7.953125
SQL>
SET PAGESIZE 200
COL "Database Size" FORMAT a13
COL "Used Space" FORMAT a11
COL "Used in %" FORMAT a11
COL "Free in %" FORMAT a11
COL "Database Name" FORMAT a13
COL "Free Space" FORMAT a12
COL "Growth DAY" FORMAT a11
COL "Growth WEEK" FORMAT a12
COL "Growth DAY in %" FORMAT a16
COL "Growth WEEK in %" FORMAT a16
SELECT
(select min(creation_time) from v$datafile) "Create Time",
(select name from v$database) "Database Name",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2) || ' MB' "Database Size",
ROUND((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 ),2) || ' MB' "Used Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 )) / ROUND(SUM(USED.BYTES) / 1024 / 1024 ,2)*100,2) || '% MB' "Used in %",
ROUND((FREE.P / 1024 / 1024 ),2) || ' MB' "Free Space",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - ((SUM(USED.BYTES) / 1024 / 1024 ) - ROUND(FREE.P / 1024 / 1024 )))/ROUND(SUM(USED.BYTES) / 1024 / 1024,2 )*100,2) || '% MB' "Free in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile),2) || ' MB' "Growth DAY",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100,3) || '% MB' "Growth DAY in %",
ROUND(((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)*7,2) || ' MB' "Growth WEEK",
ROUND((((SUM(USED.BYTES) / 1024 / 1024 ) - (FREE.P / 1024 / 1024 ))/(select sysdate-min(creation_time) from v$datafile)/ROUND((SUM(USED.BYTES) / 1024 / 1024 ),2)*100)*7,3) || '% MB' "Growth WEEK in %"
FROM (SELECT BYTES FROM V$DATAFILE
UNION ALL
SELECT BYTES FROM V$TEMPFILE
UNION ALL
SELECT BYTES FROM V$LOG) USED,
(SELECT SUM(BYTES) AS P FROM DBA_FREE_SPACE) FREE
GROUP BY FREE.P;
The below script lists the details of database growth per month:
select to_char(creation_time, 'MM-RRRR') "Month", sum(bytes)/1024/1024/1024 "Growth in GB"
from sys.v_$datafile
where to_char(creation_time,'RRRR')='2014'
group by to_char(creation_time, 'MM-RRRR')
order by to_char(creation_time, 'MM-RRRR');
SQL> select to_char(creation_time, 'MM-RRRR') "Month", sum(bytes)/1024/1024/1024 "Growth in GB"
from sys.v_$datafile
where to_char(creation_time,'RRRR')='2014'
group by to_char(creation_time, 'MM-RRRR')
order by to_char(creation_time, 'MM-RRRR'); 2 3 4 5
Month Growth in GB
------- ------------
05-2014 3
08-2014 7.953125
SQL>
Find out CPU usage for each session
Below query will be useful to find out CPU usage for each session.
select nvl(ss.USERNAME,'ORACLE USER') username, se.SID, VALUE cpu_usage
from v$session ss, v$sesstat se, v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
order by VALUE desc;
Sample output:
SQL> select nvl(ss.USERNAME,'ORACLE USER') username, se.SID, VALUE cpu_usage
from v$session ss, v$sesstat se, v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
order by VALUE desc; 2 3 4 5 6
USERNAME SID CPU_USAGE
------------------------------ ---------- ----------
ORACLE USER 234 13270
ORACLE USER 305 9523
APPS 721 7309
APPS 114 4497
APPS 300 3482
APPS 817 2820
APPS 873 2784
APPS 849 2515
APPS 545 2130
APPS 482 1792
ORACLE USER 297 1655
APPS 985 1459
APPS 738 1458
APPS 682 1433
APPS 609 1160
APPS 251 1148
APPS 409 1016
APPS 154 864
APPS 801 863
APPS 27 827
APPS 178 789
APPS 164 754
select nvl(ss.USERNAME,'ORACLE USER') username, se.SID, VALUE cpu_usage
from v$session ss, v$sesstat se, v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
order by VALUE desc;
Sample output:
SQL> select nvl(ss.USERNAME,'ORACLE USER') username, se.SID, VALUE cpu_usage
from v$session ss, v$sesstat se, v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
order by VALUE desc; 2 3 4 5 6
USERNAME SID CPU_USAGE
------------------------------ ---------- ----------
ORACLE USER 234 13270
ORACLE USER 305 9523
APPS 721 7309
APPS 114 4497
APPS 300 3482
APPS 817 2820
APPS 873 2784
APPS 849 2515
APPS 545 2130
APPS 482 1792
ORACLE USER 297 1655
APPS 985 1459
APPS 738 1458
APPS 682 1433
APPS 609 1160
APPS 251 1148
APPS 409 1016
APPS 154 864
APPS 801 863
APPS 27 827
APPS 178 789
APPS 164 754
Here;
USERNAME - Name of the user
SID - Session id
CPU Usage - CPU centi-seconds used by this session (divide by 100 to get real CPU seconds)
USERNAME - Name of the user
SID - Session id
CPU Usage - CPU centi-seconds used by this session (divide by 100 to get real CPU seconds)
Check redo log group status:
SQL> select group#, status from v$log;
GROUP# STATUS
---------- ----------------
1 INACTIVE
2 INACTIVE
3 CURRENT
SQL>
Drop old redo log group which is inactive using below command:
ALTER DATABASE DROP LOGFILE GROUP 1;
ALTER DATABASE DROP LOGFILE GROUP 2;
Add the redo log group with the require size :
ALTER DATABASE ADD LOGFILE GROUP 1 ('+DATA','+DATA') SIZE 300m;
ALTER DATABASE ADD LOGFILE GROUP 2 ('+DATA','+DATA') SIZE 300m;
switch logfile and make inactive third log group and drop it.
ALTER DATABASE DROP LOGFILE GROUP 3;
ALTER DATABASE ADD LOGFILE GROUP 3 ('+DATA','+DATA') SIZE 300m;
ALTER DATABASE ADD LOGFILE GROUP 4 ('+DATA','+DATA') SIZE 300m;
ALTER DATABASE ADD LOGFILE GROUP 5 ('+DATA','+DATA') SIZE 300m;
col member for a35
SELECT a.group#, a.member, b.bytes FROM v$logfile a, v$log b WHERE a.group# = b.group#;
GROUP# MEMBER BYTES
---------- ----------------------------------- ----------
3 +DATA/BIPROD/ONLINELOG/group_3.284. 314572800
912853377
3 +DATA/BIPROD/ONLINELOG/group_3.267. 314572800
912853385
2 +DATA/BIPROD/ONLINELOG/group_2.283. 314572800
912853625
2 +DATA/BIPROD/ONLINELOG/group_2.265. 314572800
912853785
GROUP# MEMBER BYTES
---------- ----------------------------------- ----------
1 +DATA/BIPROD/ONLINELOG/group_1.282. 314572800
912853269
1 +DATA/BIPROD/ONLINELOG/group_1.263. 314572800
912853307
4 +DATA/BIPROD/ONLINELOG/group_4.266. 314572800
912854001
4 +DATA/BIPROD/ONLINELOG/group_4.268. 314572800
GROUP# MEMBER BYTES
---------- ----------------------------------- ----------
912854067
5 +DATA/BIPROD/ONLINELOG/group_5.264. 314572800
912854213
5 +DATA/BIPROD/ONLINELOG/group_5.286. 314572800
912854339
10 rows selected.
SQL>
We have 5 redo log group and each group contain 2 members of sizes 300m.
Below setting will generate archive for every 10 mins .
SQL> alter system set archive_lag_target=600 scope=spfile;
System altered.
SQL>
How to check if TDE or TSE is enabled in database (Doc ID 2169007.1)
TDE is encryption is table column level
TSE us encryption in table space level
To check if your table space is encrypted, run below query
sql > SELECT tablespace_name, encrypted, status FROM dba_tablespaces where tablespace_name = "<TS name>"
To check if you have encrypted columns use
sql > SELECT * FROM dba_encrypted_columns;
To check TDE is enabled on all tablespaces.
Queries to check data guard is in sync with production
Primary:
select thread#, max(sequence#) "Last Primary Seq Generated"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
group by thread# order by 1;
Physical standby:
select thread#, max(sequence#) "Last Standby Seq Received"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
group by thread# order by 1;
Physical standby:
select thread#, max(sequence#) "Last Standby Seq Applied"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
and val.applied in ('YES','IN-MEMORY')
group by thread# order by 1;
select thread#, max(sequence#) "Last Primary Seq Generated"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
group by thread# order by 1;
Physical standby:
select thread#, max(sequence#) "Last Standby Seq Received"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
group by thread# order by 1;
Physical standby:
select thread#, max(sequence#) "Last Standby Seq Applied"
from v$archived_log val, v$database vdb
where val.resetlogs_change# = vdb.resetlogs_change#
and val.applied in ('YES','IN-MEMORY')
group by thread# order by 1;
All about Huge Pages
ODA Oracle Database Appliance Huge Page / Large page sizing (Doc ID 2108596.1)
NOTE:1598563.1 - Exadata Kernel Tuning: Compute Node /etc/sysctl.conf parameters: Settings which and are candidates to adjust when adding or removing physical memory (RAM).
NOTE:2220254.1 - ODA HA: Use OAKCLI RECONFIGURE OSPARAMS to Calculate, Update and Set Kernel / Memory Values Including Hugepages
NOTE:1392497.1 - USE_LARGE_PAGES To Enable HugePages
NOTE:401749.1 - Oracle Linux: Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration
NOTE:361323.1 - HugePages on Linux: What It Is... and What It Is Not...
Initialize parameters for ODA
grep "initParam name" /opt/oracle/oak/onecmd/templates/OAK_oltp.dbt <initParam name="AUDIT_SYS_OPERATIONS" value="TRUE"/> <initParam name="AUDIT_TRAIL" value="DB"/> <initParam name="GLOBAL_NAMES" value="TRUE"/> <initParam name="OS_AUTHENT_PREFIX" value=""/> <initParam name="SQL92_SECURITY" value="TRUE"/> <initParam name="PARALLEL_ADAPTIVE_MULTI_USER" value="FALSE"/> <initParam name="PARALLEL_EXECUTION_MESSAGE_SIZE" value="16384"/> <initParam name="PARALLEL_THREADS_PER_CPU" value="2"/> <initParam name="_disable_interface_checking" value="TRUE"/> <initParam name="_gc_undo_affinity" value="FALSE"/> <initParam name="_gc_policy_time" value="0"/> <initParam name="SESSION_CACHED_CURSORS" value="100"/> <initParam name="OPEN_CURSORS" value="1000"/> <initParam name="CURSOR_SHARING" value="EXACT"/> <initParam name="_ENABLE_NUMA_SUPPORT" value="FALSE"/> <initParam name="DB_LOST_WRITE_PROTECT" value="TYPICAL"/> <initParam name="DB_BLOCK_CHECKSUM" value="FULL"/> <initParam name="DB_BLOCK_CHECKING" value="FULL"/> <initParam name="FAST_START_MTTR_TARGET" value="300"/> <initParam name="UNDO_RETENTION" value="900"/> <initParam name="_FILE_SIZE_INCREASE_INCREMENT" value="2143289344"/> <initParam name="FILESYSTEMIO_OPTIONS" value="setall"/> <initParam name="use_large_pages" value="only"/> <initParam name="DB_FILES" value="1024"/> <initParam name="processes" value="4800"/> <initParam name="pga_aggregate_target" value="49152" unit="MB"/> <initParam name="sga_target" value="98304" unit="MB"/> <initParam name="db_create_file_dest" value="+DATA"/> <initParam name="log_buffer" value="64000000" /> <initParam name="cpu_count" value="48"/> <initParam name="pga_aggregate_limit" value="49152" unit="MB"/> <initParam name="_datafile_write_errors_crash_instance" value="false"/> <initParam name="_fix_control" value="18960760:on"/> <initParam name="db_block_size" value="8" unit="KB"/> <initParam name="compatible" value="11.2.0.x.0"/> <initParam name="undo_tablespace" value="UNDOTBS1"/> <initParam name="control_files" value="("{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/control01.ctl")"/> <initParam name="audit_file_dest" value="{ORACLE_BASE}/admin/{DB_UNIQUE_NAME}/adump"/> <initParam name="audit_trail" value="db"/> <initParam name="diagnostic_dest" value="{ORACLE_BASE}"/> <initParam name="remote_login_passwordfile" value="EXCLUSIVE"/> <initParam name="dispatchers" value="(PROTOCOL=TCP) (SERVICE={SID}XDB)"/> <initParam name="db_recovery_file_dest" value="+RECO"/> <initParam name="db_recovery_file_dest_size" value="1843200" unit="MB"/> <initParam name="db_create_online_log_dest_1" value="+REDO" />
<initParam name="_db_writer_coalesce_area_size" value="16777216"/>
NOTE:1598563.1 - Exadata Kernel Tuning: Compute Node /etc/sysctl.conf parameters: Settings which and are candidates to adjust when adding or removing physical memory (RAM).
NOTE:2220254.1 - ODA HA: Use OAKCLI RECONFIGURE OSPARAMS to Calculate, Update and Set Kernel / Memory Values Including Hugepages
NOTE:1392497.1 - USE_LARGE_PAGES To Enable HugePages
NOTE:401749.1 - Oracle Linux: Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration
NOTE:361323.1 - HugePages on Linux: What It Is... and What It Is Not...
Initialize parameters for ODA
grep "initParam name" /opt/oracle/oak/onecmd/templates/OAK_oltp.dbt <initParam name="AUDIT_SYS_OPERATIONS" value="TRUE"/> <initParam name="AUDIT_TRAIL" value="DB"/> <initParam name="GLOBAL_NAMES" value="TRUE"/> <initParam name="OS_AUTHENT_PREFIX" value=""/> <initParam name="SQL92_SECURITY" value="TRUE"/> <initParam name="PARALLEL_ADAPTIVE_MULTI_USER" value="FALSE"/> <initParam name="PARALLEL_EXECUTION_MESSAGE_SIZE" value="16384"/> <initParam name="PARALLEL_THREADS_PER_CPU" value="2"/> <initParam name="_disable_interface_checking" value="TRUE"/> <initParam name="_gc_undo_affinity" value="FALSE"/> <initParam name="_gc_policy_time" value="0"/> <initParam name="SESSION_CACHED_CURSORS" value="100"/> <initParam name="OPEN_CURSORS" value="1000"/> <initParam name="CURSOR_SHARING" value="EXACT"/> <initParam name="_ENABLE_NUMA_SUPPORT" value="FALSE"/> <initParam name="DB_LOST_WRITE_PROTECT" value="TYPICAL"/> <initParam name="DB_BLOCK_CHECKSUM" value="FULL"/> <initParam name="DB_BLOCK_CHECKING" value="FULL"/> <initParam name="FAST_START_MTTR_TARGET" value="300"/> <initParam name="UNDO_RETENTION" value="900"/> <initParam name="_FILE_SIZE_INCREASE_INCREMENT" value="2143289344"/> <initParam name="FILESYSTEMIO_OPTIONS" value="setall"/> <initParam name="use_large_pages" value="only"/> <initParam name="DB_FILES" value="1024"/> <initParam name="processes" value="4800"/> <initParam name="pga_aggregate_target" value="49152" unit="MB"/> <initParam name="sga_target" value="98304" unit="MB"/> <initParam name="db_create_file_dest" value="+DATA"/> <initParam name="log_buffer" value="64000000" /> <initParam name="cpu_count" value="48"/> <initParam name="pga_aggregate_limit" value="49152" unit="MB"/> <initParam name="_datafile_write_errors_crash_instance" value="false"/> <initParam name="_fix_control" value="18960760:on"/> <initParam name="db_block_size" value="8" unit="KB"/> <initParam name="compatible" value="11.2.0.x.0"/> <initParam name="undo_tablespace" value="UNDOTBS1"/> <initParam name="control_files" value="("{ORACLE_BASE}/oradata/{DB_UNIQUE_NAME}/control01.ctl")"/> <initParam name="audit_file_dest" value="{ORACLE_BASE}/admin/{DB_UNIQUE_NAME}/adump"/> <initParam name="audit_trail" value="db"/> <initParam name="diagnostic_dest" value="{ORACLE_BASE}"/> <initParam name="remote_login_passwordfile" value="EXCLUSIVE"/> <initParam name="dispatchers" value="(PROTOCOL=TCP) (SERVICE={SID}XDB)"/> <initParam name="db_recovery_file_dest" value="+RECO"/> <initParam name="db_recovery_file_dest_size" value="1843200" unit="MB"/> <initParam name="db_create_online_log_dest_1" value="+REDO" />
<initParam name="_db_writer_coalesce_area_size" value="16777216"/>
Scripts to check backup status and timings of database backups
This script will report on all backups – full, incremental and archivelog backups
col STATUS format a9
col hrs format 999.99
select SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,
elapsed_seconds/3600 hrs
from V$RMAN_BACKUP_JOB_DETAILS
order by session_key;
SQL> @backup_details.sql
SESSION_KEY INPUT_TYPE STATUS START_TIME END_TIME HRS
----------- ------------- --------- -------------- -------------- -------
165 ARCHIVELOG FAILED 03/25/18 19:28 03/25/18 19:28 .00
174 DB FULL FAILED 03/25/18 20:31 03/25/18 21:07 .61
180 ARCHIVELOG FAILED 06/16/18 15:12 06/16/18 15:12 .01
185 DB FULL COMPLETED 06/16/18 15:19 06/16/18 16:39 1.34
203 ARCHIVELOG FAILED 06/18/18 17:52 06/18/18 17:52 .00
210 DB FULL COMPLETED 06/18/18 18:02 06/18/18 19:14 1.20
6 rows selected.
SQL>
col STATUS format a9
col hrs format 999.99
select SESSION_KEY, INPUT_TYPE, STATUS,
to_char(START_TIME,'mm/dd/yy hh24:mi') start_time,
to_char(END_TIME,'mm/dd/yy hh24:mi') end_time,
elapsed_seconds/3600 hrs
from V$RMAN_BACKUP_JOB_DETAILS
order by session_key;
SQL> @backup_details.sql
SESSION_KEY INPUT_TYPE STATUS START_TIME END_TIME HRS
----------- ------------- --------- -------------- -------------- -------
165 ARCHIVELOG FAILED 03/25/18 19:28 03/25/18 19:28 .00
174 DB FULL FAILED 03/25/18 20:31 03/25/18 21:07 .61
180 ARCHIVELOG FAILED 06/16/18 15:12 06/16/18 15:12 .01
185 DB FULL COMPLETED 06/16/18 15:19 06/16/18 16:39 1.34
203 ARCHIVELOG FAILED 06/18/18 17:52 06/18/18 17:52 .00
210 DB FULL COMPLETED 06/18/18 18:02 06/18/18 19:14 1.20
6 rows selected.
SQL>
Sunday, 12 May 2019
SQL SCRIPT
To check the long operation
set verify off
col opname format a40 trunc
col pctdone format 999
col mintogo format 9,999.90
accept trgtsid number default 0 prompt 'Limit to which SID : '
select s.sid,o.opname,s.sql_hash_value,o.sofar,o.totalwork,o.elapsed_seconds,
round(o.time_remaining/60,2) mintogo,
round(o.sofar/o.totalwork * 100,0) pctdone, o.message
from v$session_longops o, v$session s
where o.sid = s.sid
and sofar < totalwork
and (o.sid = &trgtsid or &trgtsid = 0)
/
-- sid generated archives
col value for 999999999999
select *
from ( select a.username,a.sid,b.value
from v$session a,v$sesstat b,v$statname c
where a.sid=b.sid
and b.statistic#=c.statistic#
and c.name='redo size'
order by b.value desc )
where rownum < 11;
SID EVENT
+++++++
set verify off
col event format a35
col total_waits format 999999999
col time_waited format 999999.90
accept trgtsid number default 0 prompt 'What is the SID:'
prompt Note - time is in seconds
select event,
e.total_waits,
e.time_waited
from v$session_event e
where e.total_waits > 0
and (e.sid = &trgtsid and &trgtsid > 0)
and e.event not like '%time%'
and e.event not like 'SQL*Net%client'
and e.event not like 'pipe%'
and e.event not like '%ipc%'
/
/* sidtime.sql
check sid for last call et
*/
col osuser format a10 trunc
col LastCallET format a11
col sid format 9999
col username format a10 trunc
col uprogram format a25 trunc
set linesize 132
set verify off
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.sid = &trgtsid
and &trgtsid > 0;
/* top10active.sql
shows the top 10 longest-active user sessions
*/
col osuser format a10 trunc
col LastCallET format 99,999
col username format a10 trunc
col uprogram format a25 trunc
col machine format a10 trunc
set linesize 132 pages 20
set verify off
accept trgtuser char default ALL prompt 'Limit to what userid <ALL> : '
select * from (
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram,
s.machine, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.type = 'USER'
and s.username is not null
and s.status = 'ACTIVE'
and (s.username = upper('&trgtuser') or upper('&trgtuser') = 'ALL')
order by 4 desc)
where rownum < 31;
To check single tablespace details
++++++++++++++++++++++++
column file_name format a55
set linesize 132
set pages 200
column tablespace_name format a11
set verify off
accept tbs prompt 'What is the Tablespace Name: '
SELECT dts.tablespace_name,
NVL(ddf.bytes / 1024 / 1024, 0) avail,
NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024 used,
NVL(dfs.bytes / 1024 / 1024, 0) free,
TO_CHAR(NVL((ddf.bytes - NVL(dfs.bytes, 0)) / ddf.bytes * 100, 0), '990.00')
"Used %" ,
TO_CHAR(NVL((ddf.bytes - NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)) / ddf.bytes
* 100, 0), '990.00') free_pct,
decode(sign(
(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 /
1024, 0)),-1,0,(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 / 1024, 0)) "Required MB"
FROM
sys.dba_tablespaces dts,
(select tablespace_name, sum(bytes) bytes
from dba_data_files group by tablespace_name) ddf,
(select tablespace_name, sum(bytes) bytes
from dba_free_space group by tablespace_name) dfs
WHERE
dts.tablespace_name = ddf.tablespace_name(+)
AND dts.tablespace_name = dfs.tablespace_name(+)
and dts.tablespace_name = '&tbs';
select file_name,bytes/1024/1024 from dba_data_files
where tablespace_name = '&tbs';
Check Hung update queries
+++++++++++++++++
column LOCKED_OBJECT format A35 wrapped
column ORACLE_USERNAME format A17 wrapped
column OS_USER_NAME format A12 wrapped
column SESSION_ID format 999999 wrapped
column SINCE format A21
select o.OWNER || '.' || o.OBJECT_NAME as LOCKED_OBJECT,
lo.ORACLE_USERNAME,
lo.OS_USER_NAME,
lo.SESSION_ID,
lo.PROCESS,
case lo.LOCKED_MODE
when 0 then 'none'
when 1 then 'null (NULL)'
when 2 then 'row-S (SS)'
when 3 then 'row-X (SX)'
when 4 then 'share (S)'
when 5 then 'S/Row-X (SSX)'
when 6 then 'exclusive (X)'
end as LOCKED_MODE,
cast(sysdate-(CTIME/(24*60*60)) as timestamp(0)) as SINCE
from DBA_OBJECTS o,
V$LOCKED_OBJECT lo,
V$LOCK l
where o.OBJECT_ID = lo.OBJECT_ID
and lo.OBJECT_ID = l.ID1 and lo.SESSION_ID = l.SID
order by LOCKED_OBJECT, ORACLE_USERNAME, OS_USER_NAME, SESSION_ID;
-- Description : print details for user sid and cpu consumption per sid.
set lines 180
select nvl(ss.USERNAME,'ORACLE PROC') username,
se.SID,ss.program ,
VALUE cpu_usage
from v$session ss,
v$sesstat se,
v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.SID = &SID
order by VALUE desc;
---- sid details ---
set verify off pages 10 linesize 132
col sid format 99999
col machine format a10
col program format a25 trunc
col username format a10
col logontime format a15
col osuser format a10 trunc
col proginfo format a30 trunc
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time,'mm/dd hh24:mi:ss') logontime,
s.sid,s.serial#,s.status,s.type,s.username,s.osuser,s.machine,
s.module || ' - ' || s.program proginfo,
s.process,p.spid, s.sql_hash_value, s.action
from v$session s, v$process p
where sid = &trgtsid
and p.addr = s.paddr;
--------Undo usage----------
Select status,sum(bytes)/1048576 "Bytes in MB"
from dba_undo_extents
where tablespace_name=(select VALUE from v$parameter where name = 'undo_tablespace')
group by status;
set verify off
col opname format a40 trunc
col pctdone format 999
col mintogo format 9,999.90
accept trgtsid number default 0 prompt 'Limit to which SID : '
select s.sid,o.opname,s.sql_hash_value,o.sofar,o.totalwork,o.elapsed_seconds,
round(o.time_remaining/60,2) mintogo,
round(o.sofar/o.totalwork * 100,0) pctdone, o.message
from v$session_longops o, v$session s
where o.sid = s.sid
and sofar < totalwork
and (o.sid = &trgtsid or &trgtsid = 0)
/
-- sid generated archives
col value for 999999999999
select *
from ( select a.username,a.sid,b.value
from v$session a,v$sesstat b,v$statname c
where a.sid=b.sid
and b.statistic#=c.statistic#
and c.name='redo size'
order by b.value desc )
where rownum < 11;
SID EVENT
+++++++
set verify off
col event format a35
col total_waits format 999999999
col time_waited format 999999.90
accept trgtsid number default 0 prompt 'What is the SID:'
prompt Note - time is in seconds
select event,
e.total_waits,
e.time_waited
from v$session_event e
where e.total_waits > 0
and (e.sid = &trgtsid and &trgtsid > 0)
and e.event not like '%time%'
and e.event not like 'SQL*Net%client'
and e.event not like 'pipe%'
and e.event not like '%ipc%'
/
/* sidtime.sql
check sid for last call et
*/
col osuser format a10 trunc
col LastCallET format a11
col sid format 9999
col username format a10 trunc
col uprogram format a25 trunc
set linesize 132
set verify off
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.sid = &trgtsid
and &trgtsid > 0;
/* top10active.sql
shows the top 10 longest-active user sessions
*/
col osuser format a10 trunc
col LastCallET format 99,999
col username format a10 trunc
col uprogram format a25 trunc
col machine format a10 trunc
set linesize 132 pages 20
set verify off
accept trgtuser char default ALL prompt 'Limit to what userid <ALL> : '
select * from (
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram,
s.machine, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.type = 'USER'
and s.username is not null
and s.status = 'ACTIVE'
and (s.username = upper('&trgtuser') or upper('&trgtuser') = 'ALL')
order by 4 desc)
where rownum < 31;
To check single tablespace details
++++++++++++++++++++++++
column file_name format a55
set linesize 132
set pages 200
column tablespace_name format a11
set verify off
accept tbs prompt 'What is the Tablespace Name: '
SELECT dts.tablespace_name,
NVL(ddf.bytes / 1024 / 1024, 0) avail,
NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024 used,
NVL(dfs.bytes / 1024 / 1024, 0) free,
TO_CHAR(NVL((ddf.bytes - NVL(dfs.bytes, 0)) / ddf.bytes * 100, 0), '990.00')
"Used %" ,
TO_CHAR(NVL((ddf.bytes - NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)) / ddf.bytes
* 100, 0), '990.00') free_pct,
decode(sign(
(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 /
1024, 0)),-1,0,(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 / 1024, 0)) "Required MB"
FROM
sys.dba_tablespaces dts,
(select tablespace_name, sum(bytes) bytes
from dba_data_files group by tablespace_name) ddf,
(select tablespace_name, sum(bytes) bytes
from dba_free_space group by tablespace_name) dfs
WHERE
dts.tablespace_name = ddf.tablespace_name(+)
AND dts.tablespace_name = dfs.tablespace_name(+)
and dts.tablespace_name = '&tbs';
select file_name,bytes/1024/1024 from dba_data_files
where tablespace_name = '&tbs';
Check Hung update queries
+++++++++++++++++
column LOCKED_OBJECT format A35 wrapped
column ORACLE_USERNAME format A17 wrapped
column OS_USER_NAME format A12 wrapped
column SESSION_ID format 999999 wrapped
column SINCE format A21
select o.OWNER || '.' || o.OBJECT_NAME as LOCKED_OBJECT,
lo.ORACLE_USERNAME,
lo.OS_USER_NAME,
lo.SESSION_ID,
lo.PROCESS,
case lo.LOCKED_MODE
when 0 then 'none'
when 1 then 'null (NULL)'
when 2 then 'row-S (SS)'
when 3 then 'row-X (SX)'
when 4 then 'share (S)'
when 5 then 'S/Row-X (SSX)'
when 6 then 'exclusive (X)'
end as LOCKED_MODE,
cast(sysdate-(CTIME/(24*60*60)) as timestamp(0)) as SINCE
from DBA_OBJECTS o,
V$LOCKED_OBJECT lo,
V$LOCK l
where o.OBJECT_ID = lo.OBJECT_ID
and lo.OBJECT_ID = l.ID1 and lo.SESSION_ID = l.SID
order by LOCKED_OBJECT, ORACLE_USERNAME, OS_USER_NAME, SESSION_ID;
-- Description : print details for user sid and cpu consumption per sid.
set lines 180
select nvl(ss.USERNAME,'ORACLE PROC') username,
se.SID,ss.program ,
VALUE cpu_usage
from v$session ss,
v$sesstat se,
v$statname sn
where se.STATISTIC# = sn.STATISTIC#
and NAME like '%CPU used by this session%'
and se.SID = ss.SID
and ss.SID = &SID
order by VALUE desc;
---- sid details ---
set verify off pages 10 linesize 132
col sid format 99999
col machine format a10
col program format a25 trunc
col username format a10
col logontime format a15
col osuser format a10 trunc
col proginfo format a30 trunc
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time,'mm/dd hh24:mi:ss') logontime,
s.sid,s.serial#,s.status,s.type,s.username,s.osuser,s.machine,
s.module || ' - ' || s.program proginfo,
s.process,p.spid, s.sql_hash_value, s.action
from v$session s, v$process p
where sid = &trgtsid
and p.addr = s.paddr;
-- description : Check whats going on tablespace who is eating up the space.
SELECT s.sid, s.status, sq.address, sq.sql_id, sq.sql_text
FROM v$session s, v$sql sq
WHERE s.status = 'ACTIVE'
and s.sql_hash_value = sq.hash_value
and s.sql_address = sq.address
and s.sid in (Select sid from v$session
where program not like '%oracle%' and username in (select username from dba_users where default_tablespace='&tbspace_name'));
SID TIME
+++++++++++
col osuser format a10 trunc
col LastCallET format a11
col sid format 9999
col username format a10 trunc
col uprogram format a25 trunc
set linesize 132
set verify off
accept trgtsid number default 0 prompt 'What is the SID : '
select to_char(s.logon_time, 'mm/dd hh:mi:ssAM') loggedon,
s.sid, s.status,
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) "LastCallET",
s.username, s.osuser,
p.spid, s.module || ' - ' || s.program uprogram, s.sql_hash_value
from v$session s, v$process p
where p.addr = s.paddr
and s.sid = &trgtsid
and &trgtsid > 0;
--------Undo usage----------
Select status,sum(bytes)/1048576 "Bytes in MB"
from dba_undo_extents
where tablespace_name=(select VALUE from v$parameter where name = 'undo_tablespace')
group by status;
To find all tablespace details from database
column file_name format a46
column tablespace_name format a11
set verify off
SELECT dts.tablespace_name,
NVL(ddf.bytes / 1024 / 1024, 0) avail,
NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024 used,
NVL(dfs.bytes / 1024 / 1024, 0) free,
TO_CHAR(NVL((ddf.bytes - NVL(dfs.bytes, 0)) / ddf.bytes * 100, 0), '990.00')
"Used %" ,
TO_CHAR(NVL((ddf.bytes - NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)) / ddf.bytes
* 100, 0), '990.00') free_pct,
decode(sign(
(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 /
1024, 0)),-1,0,(NVL(ddf.bytes - NVL(dfs.bytes, 0), 0)/1024/1024)/0.85 - NVL(ddf.bytes / 1024 / 1024, 0)) "Required MB"
FROM
sys.dba_tablespaces dts,
(select tablespace_name, sum(bytes) bytes
from dba_data_files group by tablespace_name) ddf,
(select tablespace_name, sum(bytes) bytes
from dba_free_space group by tablespace_name) dfs
WHERE
dts.tablespace_name = ddf.tablespace_name(+)
AND dts.tablespace_name = dfs.tablespace_name(+);
Subscribe to:
Posts (Atom)