Showing posts with label oracle. Show all posts
Showing posts with label oracle. Show all posts

Saturday, January 4, 2014

Oracle: connect as sysdba without db user password

Oracle allows you connect as SYSDBA, if your Windows user is a member of  'ORA_sid_DBA' or 'ORA_DBA' group. Below are steps to do that:

1. Log in Windows as administrator

2. Check if your Windows has 'ORA_DBA' group. If not, let create it

3. Add your Windows user to 'ORA_DBA' group

4. Run TNSPING tool to check where SQLNET.ORA file is located, like the following:

C:\>tnsping orcl
 
TNS Ping Utility for 32-bit Windows: Version 10.2.0.4.0 - Production on 09-JUN-2009 14:50:20
 
Copyright (c) 1997,  2007, Oracle.  All rights reserved.
 
Used parameter files:
C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\sqlnet.ora


5. Add or remove comment for the following line:
SQLNET.AUTHENTICATION_SERVICES = (NTS)
6. Re-login Windows with the user mentioned above, try this line:
C:\>sqlplus / as sysdba
7. Then see if you can login successfully


Wednesday, October 2, 2013

Oracle: check history of executed queries

The view v$sql contains almost of queries which are executed in your Oracle DB. Basically you have privileges to query this view, you can check all from it. Below are some useful queries for you to do on this view.

1. Get latest query
select sql_text from v$sql where first_load_time=(select max(first_load_time) from v$sql)

2. Sort executed queries by load time
select sql_text, first_load_time from v$sql order by first_load_time desc

3. Get executed queries in a schema which have special text and sort by load time
select * from v$sql
where parsing_schema_name like 'YOUR_SCHEMA' and sql_text like '%YOUR_TEXT%'
order by first_load_time desc

4. Get 100 last executed queries
select sql_fulltext from
(select * from v$sql where parsing_schema_name like 'VHA' order by first_load_time desc)
where rownum < 101

5. Get 100 executed UPDATE or DELETE queries in a specific time period and sort by load time
select sql_text,sql_fulltext, first_load_time, parsing_schema_name from
(
  select * from v$sql
  where parsing_schema_name like 'YOUR_SCHEMA'
    and (sql_text like '%UPDATE %' or sql_text like '%INSERT %')
    and to_timestamp(first_load_time, 'YYYY-MM-DD/HH24:MI:SS') > to_timestamp('2012-09-27/14:06:00', 'YYYY-MM-DD/HH24:MI:SS')
  order by first_load_time desc
)
where rownum < 101

You can create your own queries to find out what queries you need to check. Remember this view v$sql doesn't store prepared statements.

Subscribe to RSS Feed Follow me on Twitter!