2026-03-12 20:23:15
This commit is contained in:
8
tpt/setup/README_rlwrap.txt
Normal file
8
tpt/setup/README_rlwrap.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
An example alias I use for connecting through rlwrap:
|
||||
|
||||
alias sl='rlwrap -D2 -irc -b'\''"@(){}[],+=&^%#;|\'\'' -f ~/work/oracle/tpt/setup/wordfile_11gR2.txt sqlplus sys/oracle@linux01/lin11g as sysdba'
|
||||
|
||||
You may want to generate your own completion dictionary using wordfile_11gR2.sql example
|
||||
|
||||
"man rlwrap" command is your friend!
|
||||
|
||||
77
tpt/setup/create_xviews.sql
Normal file
77
tpt/setup/create_xviews.sql
Normal file
@@ -0,0 +1,77 @@
|
||||
-- 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.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Name: create_xviews.sql
|
||||
-- Purpose: Create views, grants and synonyms for X$ fixed tables
|
||||
-- to be accessible for all users
|
||||
-- Usage: Run from sqlplus as SYS: @create_xviews.sql
|
||||
--
|
||||
--
|
||||
-- Author: (c) Tanel Poder http://www.tanelpoder.com
|
||||
--
|
||||
-- Other: WARNING!!! You probably don't want to create X$ views for all
|
||||
-- X$ tables in prodution environments!
|
||||
-- Some X$ tables may be dangerous for your databases performance
|
||||
-- and stability.
|
||||
--
|
||||
-- Also you may have issues with dropping those views after a database
|
||||
-- upgrade (ORA-600s when dropping them etc)
|
||||
-- So if you have such views, you should drop them before upgrade
|
||||
-- and recreate afterwards.
|
||||
--
|
||||
-- This script will not overwrite any existing X_$% SYS objects as
|
||||
-- those may be required by other performance tools
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@saveset
|
||||
|
||||
set pagesize 0
|
||||
set linesize 500
|
||||
set trimspool on
|
||||
set feedback off
|
||||
set termout off
|
||||
set echo off
|
||||
|
||||
|
||||
PROMPT Have you read the WARNING section in this scripts header?!
|
||||
PROMPT Press enter to create views for X$ tables or CTRL+C to cancel...
|
||||
|
||||
spool create_xviews.tmp
|
||||
|
||||
select 'create view '||replace(name,'X$','X_$')||' as select * from '||name||';'
|
||||
from (
|
||||
select name from v$fixed_table where name like 'X$%'
|
||||
minus
|
||||
select replace(object_name,'X_$','X$') from dba_objects where owner = 'SYS' and object_name like 'X\_$%' escape '\'
|
||||
);
|
||||
|
||||
|
||||
select 'grant select on SYS.'||replace(name,'X$','X_$')||' to public;'
|
||||
from (
|
||||
select name from v$fixed_table where name like 'X$%'
|
||||
minus
|
||||
select replace(object_name,'X_$','X$') from dba_objects where owner = 'SYS' and object_name like 'X\_$%' escape '\'
|
||||
);
|
||||
|
||||
select 'create public synonym '||name||' for SYS.'||replace(name,'X$','X_$')||';'
|
||||
from (
|
||||
select name from v$fixed_table where name like 'X$%'
|
||||
minus
|
||||
select replace(object_name,'X_$','X$') from dba_objects where owner = 'SYS' and object_name like 'X\_$%' escape '\'
|
||||
);
|
||||
|
||||
spool create_xviews.lst
|
||||
|
||||
set termout on echo on feedback on
|
||||
|
||||
@create_xviews.tmp
|
||||
|
||||
host rm create_xviews.tmp
|
||||
host del create_xviews.tmp
|
||||
|
||||
@loadset
|
||||
|
||||
prompt Done.
|
||||
56
tpt/setup/drop_xviews.sql
Normal file
56
tpt/setup/drop_xviews.sql
Normal file
@@ -0,0 +1,56 @@
|
||||
-- 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.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Name: drop_xviews.sql
|
||||
-- Purpose: Drop custom views, grants and synonyms for X$ fixed tables
|
||||
-- Usage: Run from sqlplus as SYS: @drop_xviews.sql
|
||||
--
|
||||
--
|
||||
-- Author: (c) Tanel Poder http://www.tanelpoder.com
|
||||
--
|
||||
-- Other: Note that this script only generatesd drop commands for manual
|
||||
-- execution. Make sure that you don't drop any X$ tables required
|
||||
-- by other software like StatsPack and monitoring tools
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@saveset
|
||||
|
||||
set pagesize 0
|
||||
set linesize 200
|
||||
set trimspool on
|
||||
set feedback off
|
||||
|
||||
Prompt Generating drop script...
|
||||
|
||||
spool drop_xviews.tmp
|
||||
|
||||
set termout off
|
||||
|
||||
select 'drop view '||object_name||';'
|
||||
from (
|
||||
select object_name
|
||||
from dba_objects
|
||||
where owner = 'SYS'
|
||||
and object_name like 'X\_$%' escape '\'
|
||||
);
|
||||
|
||||
select 'drop public synonym '||synonym_name||';'
|
||||
from (
|
||||
select synonym_name
|
||||
from dba_synonyms
|
||||
where owner = 'PUBLIC'
|
||||
and synonym_name like 'X$%'
|
||||
);
|
||||
|
||||
spool off
|
||||
|
||||
set termout on
|
||||
|
||||
Prompt Done generating drop script.
|
||||
Prompt Now review and manually execute the file drop_xviews.tmp using @drop_xviews.tmp
|
||||
Prompt
|
||||
|
||||
@loadset
|
||||
37
tpt/setup/grant_snapper_privs.sql
Normal file
37
tpt/setup/grant_snapper_privs.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
-- generated using this OS command (and manually edited to remove duplicates):
|
||||
-- for word in $(grep -i 'v\$' snapper.sql) ; do echo $word ; done | sort | fgrep 'v$' | sort | uniq > snapper_privs.txt
|
||||
--
|
||||
-- You have to run this script as SYS!
|
||||
|
||||
DEFINE snapper_role=SNAPPER_ROLE
|
||||
|
||||
CREATE ROLE &snapper_role;
|
||||
|
||||
GRANT SELECT ON sys.gv_$enqueue_stat TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$latch TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$lock_type TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$process TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$px_session TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$sess_time_model TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$session TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$session_event TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$session_wait TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$sesstat TO &snapper_role;
|
||||
GRANT SELECT ON sys.gv_$sys_time_model TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$event_name TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$latchname TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$mystat TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$session TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$statname TO &snapper_role;
|
||||
GRANT SELECT ON sys.v_$version TO &snapper_role;
|
||||
|
||||
|
||||
-- On Oracle 18 and higher, Snapper automatically uses DBMS_SESSION.SLEEP which is accessible to PUBLIC by default
|
||||
-- On Oracle 12.2 and lower, DBMS_LOCK access is needed:
|
||||
GRANT EXECUTE ON sys.dbms_lock TO &snapper_role;
|
||||
|
||||
-- This optional, if you want Snapepr to log its output into a tracefile instead of DBMS_OUTPUT.
|
||||
-- Note that in latest Oracle versions, you need to be SYS for DBMS_SYSTEM tracing to work, regardless of the grant
|
||||
-- GRANT EXECUTE ON sys.dbms_system TO &snapper_role;
|
||||
|
||||
-- If you granted the privileges to a role (SNAPPER_ROLE) now you can grant this role to users that need it
|
||||
25
tpt/setup/logon_trigger_ospid.sql
Normal file
25
tpt/setup/logon_trigger_ospid.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- GRANT SELECT ON v_$process TO system;
|
||||
-- GRANT SELECT ON v_$session TO system;
|
||||
|
||||
|
||||
-- Put OS PID into v$session.client_identifier so that it'd get recorded in ASH
|
||||
-- This works with dedicated sessions. With Oracle shared servers (MTS)
|
||||
-- the OS PID that was used during logon will be recorded (not necessarily the
|
||||
-- process ID that gets used later)
|
||||
|
||||
-- If you don't want to overwrite the client_identifier, you could just append
|
||||
-- the ospid= string into the end of current client id.
|
||||
|
||||
CREATE OR REPLACE TRIGGER logon_trigger_ospid
|
||||
AFTER LOGON ON DATABASE
|
||||
DECLARE
|
||||
ospid NUMBER;
|
||||
BEGIN
|
||||
SELECT spid INTO ospid
|
||||
FROM v$process
|
||||
WHERE addr = (SELECT paddr FROM v$session WHERE sid = USERENV('sid'));
|
||||
|
||||
DBMS_SESSION.SET_IDENTIFIER('ospid='||TRIM(TO_CHAR(ospid)));
|
||||
END;
|
||||
/
|
||||
|
||||
115
tpt/setup/tptcreate.sql
Normal file
115
tpt/setup/tptcreate.sql
Normal file
@@ -0,0 +1,115 @@
|
||||
-- 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: TPT helper functions (TPT = Tanel Poder's Tuning package)
|
||||
-- Purpose: Create TPT package
|
||||
--
|
||||
--
|
||||
-- Author: Tanel Poder
|
||||
-- Copyright: (c) http://www.tanelpoder.com
|
||||
--
|
||||
-- Contents: tpt.sleep function and procedure (implement sleeping via dbms_lock.sleep)
|
||||
-- tpt.sqlid_to_sqlhash
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
CREATE OR REPLACE PACKAGE tpt AUTHID DEFINER AS
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Package: TPT helper functions (TPT = Tanel Poder's Tuning package)
|
||||
-- Purpose: Helper functions like sleep function, convert sql id to hash value
|
||||
--
|
||||
--
|
||||
-- Author: Tanel Poder
|
||||
-- Copyright: (c) http://www.tanelpoder.com
|
||||
--
|
||||
-- Contents: tpt.sleep function and procedure (implement sleeping via dbms_lock.sleep)
|
||||
-- tpt.sqlid_to_sqlhash
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
FUNCTION sleep (seconds IN NUMBER DEFAULT 1) RETURN NUMBER;
|
||||
PROCEDURE sleep (seconds IN NUMBER DEFAULT 1);
|
||||
FUNCTION sqlid_to_sqlhash (sqlid IN VARCHAR2) RETURN NUMBER;
|
||||
FUNCTION get_sql_hash (name IN VARCHAR2) RETURN NUMBER;
|
||||
|
||||
END; -- tpt
|
||||
/
|
||||
SHOW ERRORS
|
||||
|
||||
CREATE OR REPLACE PACKAGE BODY tpt AS
|
||||
--------------------------------------------------------------------------------
|
||||
--
|
||||
-- Package: TPT helper functions (TPT = Tanel Poder's Tuning package)
|
||||
-- Purpose: Helper functions like sleep function, convert sql id to hash value
|
||||
--
|
||||
--
|
||||
-- Author: Tanel Poder
|
||||
-- Copyright: (c) http://www.tanelpoder.com
|
||||
--
|
||||
-- Contents: tpt.sleep function and procedure (implement sleeping via dbms_lock.sleep)
|
||||
-- tpt.sqlid_to_sqlhash
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
FUNCTION sleep (seconds IN NUMBER DEFAULT 1) RETURN NUMBER AS
|
||||
BEGIN
|
||||
DBMS_LOCK.SLEEP(seconds);
|
||||
RETURN 1;
|
||||
END; -- sleep
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
PROCEDURE sleep (seconds IN NUMBER DEFAULT 1) AS
|
||||
tmp NUMBER;
|
||||
BEGIN
|
||||
tmp := sleep(seconds);
|
||||
END; -- sleep
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
FUNCTION sqlid_to_sqlhash (sqlid IN VARCHAR2) RETURN NUMBER AS
|
||||
r NUMBER := 0;
|
||||
j NUMBER := 0;
|
||||
a NUMBER := 0;
|
||||
convstr VARCHAR2(32) := '0123456789abcdfghjkmnpqrstuvwxyz';
|
||||
base NUMBER := 32;
|
||||
BEGIN
|
||||
FOR i IN 1..LENGTH(sqlid) LOOP
|
||||
j := LENGTH(sqlid) - i + 1;
|
||||
a := (( POWER(base, j-1) * (INSTR(convstr,SUBSTR(sqlid,i,1))-1) ));
|
||||
r := r + a;
|
||||
END LOOP;
|
||||
|
||||
RETURN TRUNC(MOD(r,POWER(2,32)));
|
||||
END; -- sqlid_to_sqlhash
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
FUNCTION get_sql_hash (name IN VARCHAR2) RETURN NUMBER AS
|
||||
md5_raw RAW(16);
|
||||
pre10hash NUMBER;
|
||||
hash NUMBER;
|
||||
BEGIN
|
||||
hash := DBMS_UTILITY.GET_SQL_HASH(name, md5_raw, pre10hash);
|
||||
--DBMS_OUTPUT.PUT_LINE(rawtohex(hash_raw));
|
||||
RETURN hash;
|
||||
END;
|
||||
|
||||
END; -- tpt
|
||||
/
|
||||
SHOW ERRORS
|
||||
|
||||
|
||||
GRANT EXECUTE ON tpt TO PUBLIC;
|
||||
|
||||
BEGIN
|
||||
EXECUTE IMMEDIATE 'drop public synonym tpt';
|
||||
EXCEPTION
|
||||
WHEN others THEN NULL;
|
||||
END;
|
||||
/
|
||||
|
||||
CREATE PUBLIC SYNONYM tpt FOR tpt;
|
||||
40
tpt/setup/tptsleep.sql
Normal file
40
tpt/setup/tptsleep.sql
Normal file
@@ -0,0 +1,40 @@
|
||||
-- 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: tptsleep
|
||||
|
||||
-- Purpose: Create tpt$sleep function which allows sleeping during SQL
|
||||
-- execution
|
||||
--
|
||||
-- Author: Tanel Poder
|
||||
-- Copyright: (c) http://www.tanelpoder.com
|
||||
--
|
||||
-- Usage: select a,b,c,tpt$sleep(10) from t
|
||||
|
||||
--
|
||||
-- Other: Used for high frequency V$/X$ sampling via plain SQL
|
||||
--
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
create or replace function tptsleep (sec in number default 1) return number as
|
||||
--------------------------------------------------------------------------------
|
||||
-- tpt$sleep by Tanel Poder ( http://www.tanelpoder.com )
|
||||
--------------------------------------------------------------------------------
|
||||
begin
|
||||
dbms_lock.sleep(sec);
|
||||
return 1;
|
||||
end;
|
||||
/
|
||||
|
||||
grant execute on tptsleep to public;
|
||||
|
||||
begin
|
||||
execute immediate 'drop public synonym tptsleep';
|
||||
exception
|
||||
when others then null;
|
||||
end;
|
||||
/
|
||||
|
||||
create public synonym tptsleep for tptsleep;
|
||||
27
tpt/setup/wordfile_11gR2.sql
Normal file
27
tpt/setup/wordfile_11gR2.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- 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.
|
||||
|
||||
set lines 300 trimspool on pages 0 head off feedback off termout off
|
||||
|
||||
SELECT DISTINCT name FROM (
|
||||
select lower(keyword) name from v$reserved_words union all
|
||||
select upper(table_name) from dict union all
|
||||
select upper(column_name) from dict_columns union all
|
||||
-- select object_name from dba_objects union all
|
||||
select upper(object_name||'.'||procedure_name) from dba_procedures union all
|
||||
-- select '"'||table_name||'".'||column_name from dba_tab_columns union all
|
||||
select ksppinm from x$ksppi union all
|
||||
select name from v$sql_hint
|
||||
)
|
||||
WHERE length(name) > 2
|
||||
ORDER BY 1
|
||||
.
|
||||
|
||||
spool wordfile_11gR2.txt
|
||||
/
|
||||
spool off
|
||||
|
||||
|
||||
-- you can also add TPT scripts by running this in TPT script dir:
|
||||
-- find . -type f -name "*.sql" | sed 's/^\.\///' | awk '{ print "@" $1 }' >> ~/work/oracle/wordfile_11gR2.txt
|
||||
-- or you could just run rlwrap sqlplus being in the directory where the scripts are located!!
|
||||
37155
tpt/setup/wordfile_11gR2.txt
Normal file
37155
tpt/setup/wordfile_11gR2.txt
Normal file
File diff suppressed because it is too large
Load Diff
27
tpt/setup/wordfile_12cR1.sql
Normal file
27
tpt/setup/wordfile_12cR1.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- 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.
|
||||
|
||||
set lines 300 trimspool on pages 0 head off feedback off termout off
|
||||
|
||||
SELECT DISTINCT name FROM (
|
||||
select lower(keyword) name from v$reserved_words union all
|
||||
select upper(table_name) from dict union all
|
||||
select upper(column_name) from dict_columns union all
|
||||
-- select object_name from dba_objects union all
|
||||
select upper(object_name||'.'||procedure_name) from dba_procedures union all
|
||||
-- select '"'||table_name||'".'||column_name from dba_tab_columns union all
|
||||
select ksppinm from x$ksppi union all
|
||||
select name from v$sql_hint
|
||||
)
|
||||
WHERE length(name) > 2
|
||||
ORDER BY 1
|
||||
.
|
||||
|
||||
spool wordfile_12cR1.txt
|
||||
/
|
||||
spool off
|
||||
|
||||
|
||||
-- you can also add TPT scripts by running this in TPT script dir:
|
||||
-- find . -type f -name "*.sql" | sed 's/^\.\///' | awk '{ print "@" $1 }' >> ~/work/oracle/wordfile_12cR1.txt
|
||||
-- or you could just run rlwrap sqlplus while being in the directory where the scripts are located!!
|
||||
42044
tpt/setup/wordfile_12cR1.txt
Normal file
42044
tpt/setup/wordfile_12cR1.txt
Normal file
File diff suppressed because it is too large
Load Diff
27
tpt/setup/wordfile_18c.sql
Normal file
27
tpt/setup/wordfile_18c.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- 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.
|
||||
|
||||
set lines 300 trimspool on pages 0 head off feedback off termout off
|
||||
|
||||
SELECT DISTINCT name FROM (
|
||||
select lower(keyword) name from v$reserved_words union all
|
||||
select upper(table_name) from dict union all
|
||||
select upper(column_name) from dict_columns union all
|
||||
-- select object_name from dba_objects union all
|
||||
select upper(object_name||'.'||procedure_name) from dba_procedures union all
|
||||
-- select '"'||table_name||'".'||column_name from dba_tab_columns union all
|
||||
select ksppinm from x$ksppi union all
|
||||
select name from v$sql_hint
|
||||
)
|
||||
WHERE length(name) > 2
|
||||
ORDER BY 1
|
||||
.
|
||||
|
||||
spool wordfile_18c.txt
|
||||
/
|
||||
spool off
|
||||
|
||||
|
||||
-- you can also add TPT scripts by running this in TPT script dir:
|
||||
-- find . -type f -name "*.sql" | sed 's/^\.\///' | awk '{ print "@" $1 }' >> ~/work/oracle/wordfile_18c.txt
|
||||
-- or you could just run rlwrap sqlplus while being in the directory where the scripts are located!!
|
||||
43329
tpt/setup/wordfile_18c.txt
Normal file
43329
tpt/setup/wordfile_18c.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user