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 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'
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;
@fljdin
fljdin / Object privileges.sql
Last active September 21, 2017 09:07
Listing privileges
select
case when level = 1 then own || '.' || obj || ' (' || typ || ')' else
lpad (' ', 2*(level-1)) || obj || nvl2 (typ, ' (' || typ || ')', null)
end
from
(
/* THE OBJECTS */
select
null p1,
null p2,
set long 1000
set pagesize 0
select DBMS_METADATA.GET_DDL('OPS$DBO.INDEX','') from DUAL;
set line 200
col columns for a100
select i.table_name, i.index_name, listagg(i.column_name, ',') within group (order by i.column_position) columns
from dba_ind_columns i
left join dba_constraints c on i.index_name = c.index_name
where i.index_owner = '&owner' and i.table_name = '&table'
group by i.table_name, i.index_name;