Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • How to start CRS manually Oracle
  • Good notes for shared pool Oracle
  • replace alphabets using sed Linux/Unix
  • Oracle Support Metalink ID 161818.1 Oracle
  • Histogram information Oracle
  • Locally Managed Tablespace and Dictionary managed tablespace (LMT-DMT) Oracle
  • Oracle10g – Using SQLAccess Advisor (DBMS_ADVISOR) with the Automatic Workload Repository Oracle
  • initUOCIOTTO.ora Oracle
  • Specify the Rollback segment to use in Transaction Oracle
  • find_open_cur.sql Find open cursorts per session Oracle
  • find_cons.sql Oracle
  • sid_wise_cursor.sql find open cursor basis on username or SID Oracle
  • Running some SQL on multiple databases connecting using monitoring userid and password Linux/Unix
  • More info about /proc folder and its relation with processes. Linux/Unix
  • TRUNCATE Privs Oracle

Category: SQL scripts

findinfo.sql (SQL for getting CPU and Active session info)

Posted on 27-May-2025 By Admin No Comments on findinfo.sql (SQL for getting CPU and Active session info)

set lines 120 pages 200col dd format a20col inst_id format 99col metric_name format a30col value format 99.99 select x.dd, x.inst_id, x.metric_name, x.value “%CPU”, y.sessfrom(select to_char(sysdate, ‘DD-MON-RRRR:HH24:MI’) DD, inst_id, metric_name, valuefrom gv$sysmetricwhere metric_name like ‘Host CPU Utilization%’ and group_id=2 ) x,(select inst_id, count(1) sess from gv$sessionwhere status = ‘ACTIVE’ and osuser != ‘oracle’group by inst_id) ywhere…

Read More “findinfo.sql (SQL for getting CPU and Active session info)” »

Oracle, SQL scripts

SQL Tracker by SID sqltrackerbysid.sql

Posted on 22-Apr-202522-Apr-2025 By Admin No Comments on SQL Tracker by SID sqltrackerbysid.sql

col SAMPLE_TIME format a25col program format a20col SQL_EXEC_START format a25col machine format a15set lines 140 pages 200alter session set nls_date_format=’DD-MON-RRRR:HH24:MI:SS’; select SAMPLE_TIME, SESSION_ID, SESSION_SERIAL#, USER_ID, sql_ID, Machine, program, SQL_EXEC_STARTfrom gv$active_session_historywhere session_id = &v_session_idand sample_time > sysdate – 1/24order by sample_time/

Oracle, SQL scripts

Transfer SQL Profiles from One database to other database.

Posted on 05-Sep-2024 By Admin No Comments on Transfer SQL Profiles from One database to other database.

In this guide, I’ll walk you through moving SQL profiles using a staging table. SQL profiles help databases optimize query execution plans. Step#1 Create the Staging Table First, create a staging table to hold SQL profiles that need to be transferred. SQL> exec DBMS_SQLTUNE.CREATE_STGTAB_SQLPROF(table_name => ‘SQL_STG_TAB’, schema_name => ‘SYS’); This will create a table SQL_STG_TAB…

Read More “Transfer SQL Profiles from One database to other database.” »

Oracle, shell, SQL scripts

Creating never expiring DB user accounts in Oracle

Posted on 14-Sep-202314-Sep-2023 By Admin No Comments on Creating never expiring DB user accounts in Oracle

DB Users are required to reset the password periodically for better security. For some service accounts,  we need to make sure the password does not expire and does not impact the application. For this purpose, we need to update that user’s Profile. Each Profile has multiple security settings that controls Password_life_time, password_reuse_time, password_reuse_max  settings. These…

Read More “Creating never expiring DB user accounts in Oracle” »

Oracle, SQL scripts

Convert multiple rows to single column

Posted on 13-Sep-202313-Sep-2023 By Admin No Comments on Convert multiple rows to single column

Converting rows to single column: create table emp ( empno number, empname varchar2(100), deptno number); insert into emp values( 1, ’emp1′, 10); insert into emp values( 2, ’emp2′, 20); insert into emp values( 3, ’emp3′, 30); insert into emp values( 4, ’emp4′, 10); insert into emp values( 5, ‘paresh’, 30); insert into emp values( 6,…

Read More “Convert multiple rows to single column” »

Oracle, SQL scripts

Find all users who have DML privileges

Posted on 05-Sep-202305-Sep-2023 By Admin No Comments on Find all users who have DML privileges

Run following query as sysdba. alter session set nls_date_format=’DD-MON-RRRR:HH24:MI:SS’; alter session set nls_date_format=’DD-MON-RRRR:HH24:MI:SS’; select username, created, account_status /* Users who granted role with DML privs */ from dba_users where oracle_maintained = ‘N’ and username in (select grantee from dba_role_privs where granted_role in (select role from dba_roles where role in (select GRANTEE from dba_tab_privs where privilege…

Read More “Find all users who have DML privileges” »

Oracle, SQL scripts

Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle

Posted on 11-Jun-202311-Jun-2023 By Admin No Comments on Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle
Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle

If you want exclusive lock on any table, you need to make sure that no other session is  accessing it. This happens when you want to run DDL or any ALTER statements, that internally needs exclusive lock. Following script will to find the blocker session and provide killing statement for clearing locks.  col owner format…

Read More “Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle” »

Oracle, SQL scripts

GSQ.sql

Posted on 19-May-202325-May-2023 By Admin No Comments on GSQ.sql

This SQL will be used to identify SQL details of given Session. You need to pass SID and INSTANCE_ID as INPUT. This query will provide session details, SQL_ID, SQL_EXEC_START time and other transaction level details. set echo off feedback off verify offcol Transaction_id format a20col username format a8col days format 99.99col hours1 format 999999col TX_HRS…

Read More “GSQ.sql” »

Oracle, SQL scripts

Find_planinfo.sql

Posted on 08-Apr-202322-Apr-2025 By Admin No Comments on Find_planinfo.sql

/********************************************Author: Paresh MehtaScript Name : find_planinfo.sql********************************************/set lines 200set pages 500set echo offcol execs for 999,999,999col avg_etime for 999,999.999col avg_lio for 999,999,999.9col begin_interval_time for a30col node for 99999col plan_hash_value format 99999999999999col sql_profile format a30col intrvl format a29col component format a20alter session set nls_date_format=’DD-MON-RRRR:HH24:MI:SS’;–break on plan_hash_value,sql_profile on startup_time skip 1accept v_sql_id prompt ‘Enter SQL_ID ->’select s.instance_number, to_char(begin_interval_time,’DD-MON:HH24:MI’)…

Read More “Find_planinfo.sql” »

Oracle, SQL scripts

Wait.sql

Posted on 04-Apr-202322-Apr-2025 By Admin No Comments on Wait.sql

/********************************************Author: Paresh MehtaScript Name : waitt.sqlwaits order by sql start time********************************************/set feedback 1set pages 2000set lines 190column event format a45column machin format a12column modul format a10column prg format a10column osuser1 format a10column username format a10column sesinfo format a15column blockedby format a15alter session set nls_date_format=’DDMONRR:HH24:MI:SS’;select /*+ first_rows(100) */ a.sid || ‘,’ || a.serial# || ‘,@’ ||…

Read More “Wait.sql” »

Oracle, SQL scripts

Posts pagination

1 2 … 34 Next

Categories

  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • Oracle (388)
  • PHP/MYSQL/Wordpress (10)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (337)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • findinfo.sql (SQL for getting CPU and Active session info)27-May-2025
  • SQL Tracker by SID sqltrackerbysid.sql22-Apr-2025
  • How to connect to Oracle Database with Wallet with Python.21-Mar-2025
  • JSON/XML Types in Oracle18-Mar-2025
  • CPU Core related projections12-Mar-2025
  • Exadata Basics10-Dec-2024
  • Reading config file from other folder inside class24-Sep-2024
  • Python class import from different folders22-Sep-2024
  • Transfer SQL Profiles from One database to other database.05-Sep-2024
  • Load testing on Oracle 19C RAC with HammerDB18-Jan-2024

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to find where datafile is created dbf_info.sql Oracle
  • Nice Article about semaphores and init.ora Processes parameter relations Linux/Unix
  • cold backup scripts to copy locally Linux/Unix
  • pvmehta.com SQL scripts
    Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle Oracle
  • ORA-3136 Oracle
  • Resolving RMAN Hung Jobs Oracle
  • longtx.sql with the flag whether session is blocking any DML locks or not. Oracle
  • CTAS with LONG Column for 7.x and 8 and 8i Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme