Sunday, September 29, 2019

ORACLE AUDITING 01

I was seeing this on my OEM and try to remember what was it for 


These raised a couple of questions

1.  What are the current settings of audit in my database?

 Answer: show parameter audit

2. What can you audit?

  • Statements
  • Privileges
  • Objects
3. How do you turn on auditing?


To set the audit trail to OS, use the following and then restart the database:
SQL> alter system set audit_trail='os' scope=spfile;

To enable (or disable) the audit trail you need to set the AUDIT_TRAIL initialization parameter. You then need to restart the database. For example:
SQL> alter system set audit_trail=db scope=spfile;


4. What is being audited?

Seeing What is Being Audited
There are three views that show you what is currently being audited by the standard audit facility. DBA_STMT_AUDIT_OPTS shows you what statement auditing is enabled, DBA_PRIV_AUDIT_OPTS shows you what privilege auditing is enabled, and DBA_OBJ_AUDIT_OPTS shows you what object auditing is enabled.
SQL> select * from dba_stmt_audit_opts;
Reference

Friday, September 27, 2019

Find stored procedure by SID: SQL SERVER

select Object_Name(2103678542);

SELECT  requests.session_id,
        requests.status,
        requests.command,
        requests.statement_start_offset,
        requests.statement_end_offset,
        requests.total_elapsed_time,
        details.text
FROM    sys.dm_exec_requests requests
CROSS APPLY sys.dm_exec_sql_text (requests.sql_handle) details
WHERE   requests.session_id =194
ORDER BY total_elapsed_time DESC

SELECT  SUBSTRING(detail.text,
                  requests.statement_start_offset / 2,
                  (requests.statement_end_offset - requests.statement_start_offset) / 2)
FROM    sys.dm_exec_requests requests
CROSS APPLY sys.dm_exec_sql_text (requests.sql_handle) detail
WHERE   requests.session_id = 194

Thursday, September 26, 2019

SSMS stuck in Database (Expanding)

Check if you have query store enabled.

select * from sys.databases

alter database adventureworks SET QUERY_STORE = OFF

Tuesday, September 24, 2019

SQL Server Stored Procedure Example

use Halloween;
go

create procedure dbo.SelectEmployees
as
begin;
select * from dbo.Employee;
end;

exec dbo.SelectEmployees;

Thursday, September 12, 2019

Latest Query on SQL Server

SELECT dest.TEXT AS [Query],
deqs.execution_count [Count],
deqs.last_execution_time AS [Time]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC

Monday, September 2, 2019

SQL Server list partitioned tables

SELECT partition_number,rows,object_name(object_id)
FROM sys.partitions s
WHERE EXISTS(SELECT NULL
FROM sys.partitions s2
WHERE s.object_id = s2.object_id
AND partition_number > 1
AND s.index_id = s2.index_id);