Alert log information in 10g - oracle10g

I need some clarification on
Create, alter and drop SQL statements on databases,tablespaces and rollback segments.
related to ALERT LOG.
Does Alert log contain information about 'CREATE' or 'DROP' on tables?
Does Alert log contain information about 'WHO CREATED' or 'WHO DROPPED' tables?
P.S. The database version is 10.2.0.4 on windows 2003 operating system.

There are two ways: the first with audit
SQL> conn / as sysdba
Connected.
SQL> SHOW PARAMETER AUDIT
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
audit_file_dest string C:\ORACLEXE\APP\ORACLE\ADMIN\XE\ADUMP
audit_sys_operations boolean FALSE
audit_trail string NONE
SQL> ALTER SYSTEM SET audit_trail=db SCOPE=SPFILE;
System altered.
SQL> startup force
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2260048 bytes
Variable Size 616563632 bytes
Database Buffers 444596224 bytes
Redo Buffers 5517312 bytes
Database mounted.
Database opened.
SQL> AUDIT ALL BY hr BY ACCESS;
Audit succeeded.
SQL> conn hr/hr
Connected.
SQL> create table ttt(id number);
Table created.
SQL> drop table ttt;
Table dropped.
SQL> conn / as sysdba
Connected.
SQL> ed
Wrote file afiedt.buf
1 SELECT username
2 , extended_timestamp
3 , owner
4 , obj_name
5 , action_name
6 FROM dba_audit_trail
7* order by 2
SQL> /
USERNAME EXTENDED_TIMESTAMP OWNER OBJ_NAME ACTION_NAME
---------- ----------------------------------- ---------- ---------- ----------------------------
HR 14.08.14 18:00:35,606000 +04:00 LOGON
HR 14.08.14 18:00:48,651000 +04:00 HR TTT CREATE TABLE
HR 14.08.14 18:00:54,425000 +04:00 HR TTT DROP TABLE
HR 14.08.14 18:00:59,311000 +04:00 LOGOFF
Second with the DBMS_LOGMNR package.

Related

Postgres Audit - How to get information on who is performing the DDL operation?

I'm trying to enable pgaudit in an Azure Postgres Single Server. I have followed the instructions provided by Microsoft and also the documentation of Postgres.
These are my settings ( the 2 Selected in the picture below are DDL and ROLE )
Log parameters
Then I have configured a destination for the files using a storage account. So far so good. The I ran this test case
postgres=> create table test_audit ( c1 integer ) ;
CREATE TABLE
postgres=> \dt test_audit
List of relations
Schema | Name | Type | Owner
--------+------------+-------+------------
public | test_audit | table | posadmn001
(1 row)
postgres=> insert into test_audit values ( 1 ) ;
INSERT 0 1
postgres=> insert into test_audit values ( 2 ) ;
INSERT 0 1
postgres=> alter table test_audit add c2 integer ;
ALTER TABLE
postgres=> drop table test_audit ;
DROP TABLE
So I should expect only entries for DDL operations, not for the DML, and that is working fine.
Create Table
"message": "*AUDIT: SESSION,1,1,DDL,CREATE TABLE,TABLE,public.test_audit,create table test_audit ( c1 integer ) ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
Alter Table
"message": "AUDIT: SESSION,2,1,DDL,ALTER TABLE,TABLE,public.test_audit,alter table test_audit add c2 integer ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
Drop table
"message": "AUDIT: SESSION,1,1,DDL,DROP TABLE,TABLE,public.test_audit,drop table test_audit ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
However, the audit trails don't show who have performed such operations. I mean, if I review the logs line by line, obviously there is an entry for the connection itself by the admin user, but not related to the AUDIT itself. Is there any way to collect the user within the audit trail together with the DDL operation? So that when I am looking for messages with the word AUDIT, I can get the command and the user who did it.
Thank you for your help
You can get the user name in the log line prefix by adding %u to log_line_prefix. A useful setting might be
log_line_prefix = '%m [%p] %q%u#%d (%h) '

DB2 load fails with SQL3304N The table does not exist

I have created 2 tables in db2 11.5 LUW :
CREATE TABLE test.TABLE1(ONE INT,
TWO CHAR(10),
THREE DATE);
CREATE TABLE test.TABLE2(ONE INT,
TWO CHAR(10),
THREE DATE);
Both tables are selectable:
db2 => select * from test.table1;
ONE TWO THREE
----------- ---------- ----------
0 record(s) selected.
db2 => select * from test.table2;
ONE TWO THREE
----------- ---------- ----------
0 record(s) selected.
Trying to run load (even on empty tables):
db2 => DECLARE mycurs CURSOR FOR SELECT ONE, TWO, THREE FROM test.table1;
DB20000I The SQL command completed successfully.
db2 => LOAD FROM mycurs OF cursor INSERT INTO test.table2;
SQL3304N The table does not exist.
Any ideas why it happens?
I found the reason: it was the trailing semicolon.
This one fails - mind that the command ends with ;
db2 => LOAD FROM mycurs OF cursor INSERT INTO test.table2;
SQL3304N The table does not exist.
But, this one works - mind that the command does not end with ;
db2 => LOAD FROM mycurs OF cursor INSERT INTO test.table2
SQL3501W The table space(s) in which the table resides will not be placed in
backup pending state since forward recovery is disabled for the database.
SQL1193I The utility is beginning to load data from the SQL statement "
select * from test.table2".
...
I am used to oracle syntax , where ; is expected in the end of any command. I guess this is not the case in db2.

oracle 12c cursor_sharing alter multple sessions

Question:
Is there an equivalent to dbms_system.set_int_param_in_session that works for init paramters where the value is a character string rather than an integer or a boolean?
Backstory:
I've got a problem with a 3rd party application whose api's don't use bind variables. This causes high cpu and slow performance as the application issues the same sql over and over. (hard parsing) I've discovered that setting the cursor_sharing parameter to FORCE improves performance, however there are security issues with doing that. The 3rd party application maintains many sessions (~30-50) So my current approach is to set cursor_sharing to force during the time the 3rd party application is doing its thing and then set cursor_sharing back to exact when it is done. Kludgy? Yes, very. We did some research and found the dbms_system.set_int_param_in_session procedure which seems like it would be an adequate solution except that it only works with init parameters with data type integer. Is there an equivalent for parameters with values of data type string?
Though im not well versed with using dbms_system, based on the info available for dbms_system package, i tried to use add_parameter_value at session level and ended up with following error:
SQL> set serveroutput on
DECLARE
sid_value VARCHAR2(10);
BEGIN
dbms_system.get_env('ORACLE_SID', sid_value);
dbms_output.put_line(sid_value);
dbms_system.add_parameter_value('cursor_sharing', 'EXACT', 'MEMORY', sid_value, 4);
END;
/
show errorsSQL> 2 3 4 5 6 7 8 mydb
DECLARE
*
ERROR at line 1:
ORA-20004: cursor_sharing is not a list parameter
SQL>
So, tried the following trigger based approach which sets cursor_sharing to force only for user SCOTT which you can change as per your requirement.
SQL> create or replace trigger csf
after logon
on database
begin
if user='SCOTT' then
execute immediate 'alter session set cursor_sharing=force';
else
execute immediate 'alter session set cursor_sharing=exact';
end if;
end;
/ 2 3 4 5 6 7 8 9 10 11
Trigger created.
SQL>
SQL>
SQL> conn scott/tiger
Connected.
SQL> show parameter cursor_sharing
NAME TYPE VALUE
--------------------- --------- ---------------
cursor_sharing string FORCE
SQL>
SQL> conn system/manager
Connected.
SQL> show parameter cursor_sharing
NAME TYPE VALUE
--------------------- --------- ---------------
cursor_sharing string EXACT
SQL>
Hope this helps you avoid setting the value back to original value.

Drop table that has the name in lower case from the command line

I need to delete a table that has a lower case name, i.e. academy
However when I do db2 drop table academy or db2 drop table "academy" I get:
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0204N "DB2INST1.ACADEMY" is an undefined name. SQLSTATE=42704
The same command worked for upper case table names though.
When I list my tables I have > db2 LIST TABLES
Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
AA DB2INST1 T 2016-06-07-14.23.08.927146
MYNEWTABLE DB2INST1 T 2016-06-07-14.29.50.859806
academy DB2INST1 T 2016-06-07-17.05.27.510905
In db2 drop table "academy" quotes get swallowed by the shell. You'll need to escape them:
db2 drop table \"academy\"
or quote the entire statement:
db2 'drop table "academy"'
Try doing a select * from "academy" and see if it will even call the table. If it does you should be able to run the same query again, only replace the word "select" with "drop".

What's the PostgreSQL equivalent of SQL Servfer's CONTEXT_INFO?

In relation to my other question "What’s the best way to audit log DELETEs?". What's the PostgreSQL equivalent of CONTEXT_INFO?
I want to log deletes using a trigger, but since I'm not using the database user as my app's logical user, I cannot log the CURRENT_USER from the trigger code as the user who deleted the record. But for INSERT and UPDATE it is possible to log the record changes from trigger since you can just add a user field in the record, say inserted_by and last_updated_by, and use these fields to log to audit table.
http://www.postgres.cz/index.php/PostgreSQL_SQL_Tricks_II#Any_other_session_variables
PostgreSQL provides more variants, please, look to this site.
The accepted answer is outdated.
In recent versions of postgresql (since 9.3 or 9.4 I think), one can set / retrieve config variables are only alive for the current session [or transaction]. Documentation Reference
example of setting a session variable:
hal=# select set_config('myvar.foo', 'bar', false);
set_config
------------
bar
(1 row)
hal=# select current_setting('myvar.foo');
current_setting
-----------------
bar
(1 row)
It is possible to use the function current_setting as one would use other set returning functions.
example:
create table customers (id int);
insert into customers values (1), (2), (3), (4);
select c.*, s.*
from customers c
left join current_setting('myvar.foo') s
on c.id = length(s)