Tuesday, July 21, 2020

Microsoft SQL Server, Error: 15023

USE MY_DB;

EXEC sp_change_users_login 'Auto_Fix', 'sa_web';

The row for user 'sa_web' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.

Monday, July 20, 2020

How to purge audit logs on Oracle 11g

https://docs.oracle.com/cd/E11882_01/network.112/e36292/auditing.htm#DBSEG472


Manually Purging the Audit Trail

You can manually purge the audit trail right away, without scheduling a purge job. Similar to a purge job, you can purge audit trail records that were created before an archive timestamp date or all the records in the audit trail.
Note the following about the DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL PL/SQL procedure:
  • Only the current audit directory is cleaned up when you run this procedure.
  • On Microsoft Windows, because the DBMS_AUDIT_MGMT package does not support cleanup of Windows Event Viewer, setting the AUDIT_TRAIL_TYPE property to DBMS_AUDIT_MGMT.AUDIT_TRAIL_OS has no effect. This is because operating system audit records on Windows are written to Windows Event Viewer. The DBMS_AUDIT_MGMT package does not support this type of cleanup operation.
  • On UNIX platforms, if you set the AUDIT_SYSLOG_LEVEL initialization parameter to a valid value as listed in Oracle Database Reference, then Oracle Database writes the operating system log files to syslog files. If you set the AUDIT_TRAIL_TYPE property to DBMS_AUDIT_MGMT.AUDIT_TRAIL_OS, then the procedure only removes .aud files under audit directory (This directory is specified by the AUDIT_FILE_DEST initialization parameter).
  • When the AUDIT_TRAIL_TYPE parameter is set to DBMS_AUDIT_MGMT.AUDIT_TRAIL_XML, this procedure only cleans up XML audit files (.xml) in the current audit directory. Oracle Database maintains an index file, called adx_$ORACLE_SID.txt, which lists the XML files that were generated by the XML auditing. The cleanup procedure does not remove this file.
For database audit trails, you must initialize the cleanup infrastructure by running the DBMS_AUDIT_MGMT.INIT_CLEANUP procedure, and then purging the database audit trail by using the method described in "Purging a Subset of Records from the Database Audit Trail".
To manually purge the audit trail:
  1. Purge the audit trail records by running the DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL PL/SQL procedure.
    For example:
    BEGIN
      DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL(
       AUDIT_TRAIL_TYPE           =>  DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
       USE_LAST_ARCH_TIMESTAMP    =>  TRUE );
    END;
    /
    
    In this example:
    • AUDIT_TRAIL_TYPE: Enter one of the following values:
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD: Standard audit trail table, AUD$
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_FGA_STD: Fine-grained audit trail table, FGA_LOG$
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_DB_STD: Both standard and fine-grained audit trail tables
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_OS: Operating system audit trail files with the .aud extension. (This setting does not apply to Windows Event Log entries.)
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_XML: XML audit trail files
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_FILES: Both operating system and XML audit trail files
      • DBMS_AUDIT_MGMT.AUDIT_TRAIL_ALL: All audit trail records, that is, both database audit trail and operating system audit trail types
    • USE_LAST_ARCH_TIMESTAMP: Enter either of the following settings:
      • TRUE: Deletes audit records created before the last archive timestamp. To set the archive timestamp, see "Step 4: Optionally, Set an Archive Timestamp for Audit Records". The default (and recommended) value is TRUE. Oracle recommends that you set USE_LAST_ARCH_TIMESTAMP to TRUE.
      • FALSE: Deletes all audit records without considering last archive timestamp. Be careful about using this setting, in case you inadvertently delete audit records that should have been deleted.

Purging a Subset of Records from the Database Audit Trail

You can manually remove records from the database audit trail tables. This method can be useful if you want to remove a specific subset of records. You can use this method if the database audit trail table is in any tablespace, including the SYSTEM tablespace.
For example, to delete audit records that were created later than the evening of February 28, 2009 but before March 28, 2009, enter the following statement:
DELETE FROM SYS.AUD$
   WHERE NTIMESTAMP# > TO_TIMESTAMP ('28-FEB-09 09.07.59.907000 PM') AND
   NTIMESTAMP# < TO_TIMESTAMP ('28-MAR-09 09.07.59.907000 PM');
Alternatively, to delete all audit records from the audit trail, enter the following statement:
DELETE FROM SYS.AUD$;
Only the user SYS or a user to whom SYS granted the DELETE privilege on SYS.AUD$ can delete records from the database audit trail.

Wednesday, July 15, 2020

Linux mount

 1  uname -a
    2  df -h
    3  fdisk -l
    4  fdisk /dev/sdb
    5  fdisk /dev/sdb -l
    6  fdisk /dev/sdc
    7  fdisk /dev/sdc -l
    8  fdisk /dev/sdd
    9  fdisk /dev/sde
   10  fdisk -l
   11  mkfs -t ext4 /dev/sdb1
   12  mkfs -t ext4 /dev/sdc1
   13  mkfs -t ext4 /dev/sdd1
   14  mkfs -t ext4 /dev/sde1
   15  cd /
   16  ll
   17  mkdir /u01 /u02
   18  ll
   19  mkdir /u03 /u04
   20  ll
   21  mount /dev/sdb1 /u01
   22  mount /dev/sdc1 /u02
   23  mount /dev/sdd1 /u03
   24  mount /dev/sde1 /u04
   25  df -h
   26  cd /u01
   27  touch angel.txt

Tuesday, June 23, 2020

Place Holder For Feature Usage Tracking Bugs (Doc ID 1309070.1)

Place Holder For Feature Usage Tracking Bugs (Doc ID 1309070.1)

SQL Server: Get Jobs and Objects owned by user

select s.name,l.name  
from  msdb..sysjobs s 
left join master.sys.syslogins l on s.owner_sid = l.sid 
where l.name is not null and l.name = 'Jeelan'
order by l.name

SELECT *
FROM sys.objects
WHERE schema_id = SCHEMA_ID('DBO');

Tuesday, June 16, 2020

How To Resize Partition in RHEL 7

root@apollo dbapps]# fdisk /dev/sdc

The number of cylinders for this disk is set to 54827.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdc: 450.9 GB, 450971566080 bytes
255 heads, 63 sectors/track, 54827 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       39162   314568733+  83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdc: 450.9 GB, 450971566080 bytes
255 heads, 63 sectors/track, 54827 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4) p
Partition number (1-4): 1
First cylinder (1-54827, default 1): [ENTER]
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-54827, default 54827): [ENTER]
Using default value 54827

Command (m for help): p

Disk /dev/sdc: 450.9 GB, 450971566080 bytes
255 heads, 63 sectors/track, 54827 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       54827   440397846   83  Linux

Command (m for help): wq
The partition table has been altered!


REBOOT

[root@apollo ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              16G  3.4G   12G  23% /
/dev/sda1             251M   17M  222M   7% /boot
tmpfs                 5.9G     0  5.9G   0% /dev/shm
/dev/sdc1             296G  245G   36G  88% /dbapps
[root@apollo ~]# resize2fs -p /dev/sdc1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/sdc1 is mounted on /dbapps; on-line resizing required
Performing an on-line resize of /dev/sdc1 to 110099461 (4k) blocks.
The filesystem on /dev/sdc1 is now 110099461 blocks long.

[root@apollo ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              16G  3.4G   12G  23% /
/dev/sda1             251M   17M  222M   7% /boot
tmpfs                 5.9G     0  5.9G   0% /dev/shm
/dev/sdc1             414G  245G  148G  63% /dbapps
[root@apollo ~]#

Monday, June 15, 2020

DISABLE AUTOMATIC SQL ADVISOR

Check if anything is enabled

select client_name, status from dba_autotask_operation;


SQL> select client_name, status from dba_autotask_operation;

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED
auto space advisor                                               ENABLED

sql tuning advisor                                               ENABLED


How to Enable or DISABLE Automatic SQL Tuning

To ENABLE Automatic SQL Tuning, use the ENABLE procedure as shown below
BEGIN
DBMS_AUTO_TASK_ADMIN.ENABLE(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
/
To DISABLE Automatic SQL Tuning, use the DISABLE procedure as shown below
BEGIN
DBMS_AUTO_TASK_ADMIN.DISABLE(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
Connected to:
Oracle Database 18c Standard Edition 2 Release 18.0.0.0.0 - Production
Version 18.3.0.0.0

SQL> select client_name, status from dba_autotask_operation;

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED
auto space advisor                                               ENABLED
sql tuning advisor                                               ENABLED

SQL> BEGIN
DBMS_AUTO_TASK_ADMIN.DISABLE(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;  2    3    4    5    6
  7  /

PL/SQL procedure successfully completed.

SQL> select client_name, status from dba_autotask_operation;

CLIENT_NAME                                                      STATUS
---------------------------------------------------------------- --------
auto optimizer stats collection                                  ENABLED
auto space advisor                                               ENABLED
sql tuning advisor                                               DISABLED

SQL>