Skip to content

Instantly share code, notes, and snippets.

@fljdin
fljdin / backup blocks statistics by days.sql
Created April 9, 2014 14:43
RMAN history and statistics
select To_Char(Start_Time, 'D') NUM_DAY, To_Char(Start_Time, 'Dy') DAY,
to_char(to_date(round(avg(ELAPSED_SECONDS)),'sssss'),'hh24:mi:ss') avg_time_taken,
round(avg(input_bytes_per_sec)/(1024*1024),2) || ' Mo/sec.' input_bytes_per_sec_mo,
round(avg(output_bytes_per_sec)/(1024*1024),2) || ' Mo/sec.' output_bytes_per_sec_mo,
round(avg(input_bytes)/(1024*1024*1024),2) || ' Go' input_bytes_go,
round(avg(output_bytes)/(1024*1024*1024),2) || ' Go'output_bytes_go
from V$RMAN_BACKUP_JOB_DETAILS
where input_type='DB INCR'
and status like 'COMPLETED%'
group by To_Char(Start_Time, 'D'),To_Char(Start_Time, 'Dy')
SET LINES 132
SELECT file_type
, round(space_limit*percent_space_used/100/1024/1024,0) used_mb
, round(percent_space_used,0) used_pct
, round(space_limit*percent_space_reclaimable/100/1024/1024,0) reclaimable_mb
, round(percent_space_reclaimable,0) reclaimable_pct
, frau.number_of_files num_of_files
FROM v$recovery_file_dest rfd, v$flash_recovery_area_usage frau
UNION ALL
alter system set undo_tablespace = 'UNDOTBS2' scope=both;
drop tablespace undotbs1 including contents and datafiles;
select count(sid) sessions, block, max(round(ctime/60)) duration
from gv$lock where type = 'TX' and lmode > 0 group by block;
set lines 255
col path for a35
col Diskgroup for a15
col DiskName for a25
col disk# for 999
col total_mb for 999,999,999
col free_mb for 999,999,999
compute sum of total_mb on DiskGroup
compute sum of free_mb on DiskGroup
break on DiskGroup skip 1 on report -
select ctime "Date",
decode(backup_type, 'L', 'Archive Log', 'D', 'Full', 'Incremental') backup_type,
bsize "Size MB"
from (
select trunc(bp.completion_time) ctime, backup_type,
round(sum(bp.bytes/1024/1024),2) bsize
from v$backup_set bs, v$backup_piece bp
where bs.set_stamp = bp.set_stamp
and bs.set_count = bp.set_count
and bp.status = 'A'
@fljdin
fljdin / tablespace files.sql
Last active July 16, 2018 15:19
Tablespace usage
set lines 160
set pages 200
col tablespace_name format A30
col file_name format A55
col pct_used format 999.99
set verify off
set trimout on
select f.tablespace_name, f.file_name
, round(f.bytes/1024/1024) as size_mb
DUPLICATE DATABASE TO dup11r2
UNTIL TIME "TO_DATE('29-MAY-2010 14:16:42','DD-MON-YYYYHH24:MI:SS')"
SPFILE
set control_files='D:\dup11r2\c1.ctl'
set db_file_name_convert='D:\Database\Ora11g2\ora11g2','d:\dup11r2'
set log_file_name_convert='D:\Database\Ora11g2\ora11g2','d:\dup11r2'
BACKUP LOCATION 'D:\dup11r2';
@fljdin
fljdin / postgresql evaluate next working day.sql
Last active August 29, 2015 14:03
Evaluate next french working day from a date and a frequency string
-- -----------------------------------
-- FUNCTION: easter_date
-- -----------------------------------
CREATE OR REPLACE FUNCTION easter_date(year integer)
RETURNS timestamp as $$
DECLARE
g integer := year % 19;
c integer := (year/100)::int;
h integer := ((c - (c/4)::int - ((8*c+13)/25)::int + 19*g + 15) % 30)::int;
i integer := h - (h/28)::int * (1 - (h/28)::int * (29/(h + 1))::int * ((21 - g)/11)::int);
@fljdin
fljdin / 01 create_unusable_index.sql
Last active August 29, 2015 14:07
Workaround ORA-01652 when creating function-based index on partitioned table
CREATE INDEX &schema.&index_part
ON &schema.&table_name(TO_NUMBER(TO_CHAR(TO_DATE(TO_CHAR(&column),'YYYYMMDD'),'IYYYIW')))
LOCAL UNUSABLE;