Home Database Mysql Tutorial Oracle FGA审计

Oracle FGA审计

Jun 07, 2016 pm 05:30 PM

大家对trigger可能比较熟悉,但Oracle还有一个叫FGA的功能,它的作用和trigger类似,但功能更强大.它的全称是Fine-Grained Audit ,是

大家对trigger可能比较熟悉,但Oracle还有一个叫FGA的功能,它的作用和trigger类似,但功能更强大.它的全称是Fine-Grained Audit ,是Audit的一种特殊方式.使用FGA只要调用Oracle的包DBMS_FGA.ADD_POLICY创建一些policy(审计策略)就行.每个policy只能针对一个表或视图.建好策略后所以对表或视图的DML操作(select,insert,update,delete都可以记录到,当然也可以添加一些筛选条件只监测某些特殊的操作.

补充:所谓审计就是记录你的任意操作,假如你的操作(执行DML语句)符合指定的条件,则你执行的sql语句,将被记录到sys用户下的一些表中,还会将你的其他信息,比如执行时间,用户名,通过什么工具,机器名等.FGA在oracle 9i中就有了,但在9i中只能审计select语句.从10g开始才能审计所有的DML操作

FGA与Triger的明显区别:

1.FGA使用自治的事务,即使DML操作被rollback了,它仍然照样执行不会rollback.而trigger是会被rollback的.

2.做更新操作时trigger可以记录更新前的旧值和更新后的新值,而FGA是不记录旧值.

1.包DBMS_FGA.ADD_POLICY的用法

创建审计策略的语法

DBMS_FGA.ADD_POLICY (

object_schema VARCHAR2, --schema的名字,表或视图的拥有者

object_name VARCHAR2, --对象名,表或视图的名字

policy_name VARCHAR2, --审计策略名字,它和数据库中其他对象一样,需要有一个不重复,唯一的名字

audit_condition VARCHAR2, --筛选条件比如可以选择哪些符合条件的操作被记录

audit_column VARCHAR2, --表中的某一列,可以只记录对表中某一列的操作.如果不指定表示审计所有的列

handler_schema VARCHAR2, --是下面的handler_module的拥有者,其实也只能是创建policy的用户,而上面的object_schema可以是任意用户

handler_module VARCHAR2,--可以是一个一个存储过程或函数,但监测到任何一条符合条件的操作时执行它.

enable BOOLEAN, --true 或false表示policy是开启或关闭状态,如果是false表示不进行审计

statement_types VARCHAR2, --表示哪些操作将被审计,可以填上select,insert,update,delete中的一个或几个

audit_trail BINARY_INTEGER IN DEFAULT,--有参数db,xml表示审计到的信息保存到数据库中或是以xml文件形式保存到磁盘上

audit_column_opts BINARY_INTEGER IN DEFAULT); --这个选项其实只有在audt_column中指定了某列时才起作用.它有any_columns,all_columns两个选项假如表中有eno,ename两列,并在audit_column中指定了这两列,那么选any_columns表示只要操作其中的任意一列都将被记录,而这里指定all_columns的话是说只有一个sql语句同时操作了这两列才被记录

 

举例,假如创建表:create table temp(eno int,ename varchar2(30));针对这个表创建policy

每个策略只能针对一个表或视图,而一个表或视图可能对应多个策略.当表被删除时策略也随之默认被删除

BEGIN
SYS.DBMS_FGA.ADD_POLICY (
object_schema => 'ARWEN'
,object_name => 'TEMP'
,policy_name => 'FGA_TEMP'

,audit_condition => NULL
,audit_column => eno,ename
,handler_schema => null
,handler_module => null

,enable => TRUE
,statement_types =>'SELECT,INSERT,UPDATE,DELETE'
,audit_trail => SYS.DBMS_FGA.DB+SYS.DBMS_FGA.EXTENDED

--DBMS_FGA.DB表示记录将被保存到数据库中,DBMS_FGA.EXTENDED表示如果sql语句中带有绑定变量也会被记录下来.

--如果是这样选audit_trail => SYS.DBMS_FGA.DB表示不会记录绑定变量

--SYS.DBMS_FGA.DB+SYS.DBMS_FGA.EXTENDED改成SYS.DBMS_FGA.XML+SYS.DBMS_FGA.EXTENDED表示记录保存成xml文件

--xml文件所在目录可以通过SHOW PARAMETER AUDIT_FILE_DEST查看,如果要更改目录ALTER SYSTEM SET AUDIT_FILE_DEST = directory_path DEFERRED;

,audit_column_opts => SYS.DBMS_FGA.ALL_COLUMNS)
END;

 

查看创建好的policy对象和符合审计条件时被记录的操作

我们可以通过select * from dba_objects查看table,view等对象,类似的policy创建好后我们可以通过SELECT * FROM DBA_AUDIT_POLICIES来查看.

如果我们对表temp执行了DML操作,那些信息将会被操作到sys用户下的表中,Select* from sys.dba_fga_audit_trail可以查找到.(注意这只有前面设置将记录信息

保存到数据库才能这样查,如果保存到xml文件中可以Select *from V$XML_AUDIT_TRAIL)

 

2.删除审计策略,假如删除上面创建的策略

begin

SYS.DBMS_FGA.DROP_POLICY (

object_schema => 'ARWEN'

,object_name => 'TEMP'

,policy_name => 'FGA_TEMP'

);

end;

3.使用handler_module

 

假如你想在审计到某些操作时还进行进一步的处理,比如把信息写到自己创建的日志中,或者发送邮件通知相关人员.就要在创建policy时使用handler_module的功能,指定一个存储过程去做相应的处理.假如我创建一个存储过程temp_handler

CREATE OR REPLACE PROCEDURE temp_handler

( v_object_schema VARCHAR2

, v_object_name VARCHAR2

, v_policy_name VARCHAR2

)

IS

v_temp varchar2(30);

begin

null;

end temp_handler;

--这里的存储过程有点特殊,它必须带v_object_schema VARCHAR2, v_object_name VARCHAR2, v_policy_name VARCHAR2这三个参数才行,如果直接写一个一般的存储过程就会出错的.在policy中调用存储过程就这样 写

 

BEGIN
SYS.DBMS_FGA.ADD_POLICY (
object_schema => 'ARWEN'
,object_name => 'TEMP'
,policy_name => 'FGA_TEMP'

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

See all articles