What you can achieve ?
Monday, April 21, 2025
Thursday, March 20, 2025
Thursday, March 13, 2025
SQL styling and formatting !!!!!
2025-03-12 00:11:11 ERROR OGG-01169 Encountered an update where all key columns for target table SCHEMA.TABLE_NAME are not present
INDEX REBUILD TIME SQL
select sql_text,sql_id from gv$sqlstats where sql_text like '%SCHEMA.INDEX_NAME%';
abfxhr2v2bqgf
select sid,serial# from gv$session_longops where sql_id='abfxhr2v2bqgf ';
SID SERIAL#
----------------------------
2200 44444
select round(time_remaining/60) time_remaining_mins from gv$session_longops where sid='2200' and serial# = '44444';
TIME_REMAINING_MINS
----------------------------------
33
Wednesday, March 12, 2025
DBMS_METADATA package to extract objects DDL
Thursday, February 27, 2025
DBMS_STATS.GATHER_STATS for tables schemas indexes columns
| Action | Full Command | Description |
|---|---|---|
| Update statistics for a specific table | EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES'); | Updates statistics for the EMPLOYEES table in the HR schema. |
| Update statistics for a table and its indexes | EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES', cascade => TRUE); | Updates statistics for the EMPLOYEES table and all its indexes. |
| Update statistics for a specific index | EXEC DBMS_STATS.GATHER_INDEX_STATS('HR', 'EMP_SALARY_IDX'); | Updates statistics for the EMP_SALARY_IDX index in the HR schema. |
| Update statistics for all tables in a schema | EXEC DBMS_STATS.GATHER_SCHEMA_STATS('HR'); | Updates statistics for all tables and indexes in the HR schema. |
| Update statistics for the entire database | EXEC DBMS_STATS.GATHER_DATABASE_STATS; | Updates statistics for all schemas and tables in the database. (Time-consuming on large DBs) |
| Check last statistics update for a table | SELECT table_name, last_analyzed FROM user_tables WHERE table_name = 'EMPLOYEES'; | Shows the last time statistics were gathered for the EMPLOYEES table. |
| Check last statistics update for an index | SELECT index_name, last_analyzed FROM user_indexes WHERE table_name = 'EMPLOYEES'; | Shows the last time statistics were gathered for indexes of EMPLOYEES. |
| Update statistics in parallel for faster execution | EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES', degree => 4); | Runs statistics gathering in parallel for faster performance (using 4 CPU threads). |
| Update statistics for specific columns | EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES', columns => ('SALARY')); | Updates statistics only for the SALARY column. |
Best Practices:
✔ Use cascade => TRUE to update both table and indexes.
✔ Use degree => 4 for faster execution on large tables.
✔ Schedule statistics updates during off-peak hours.
Would you like a PL/SQL script to automate this for multiple tables? 😊
Thursday, June 20, 2024
Flush shared_pool & buffer_cache
Manually flush buffer cache & shared pool cache without bouncing the database:-
For Standalone Databases
alter system flush buffer_cache;
alter system flush shared_pool;
For RAC Databases
alter system flush buffer_cache global;
alter system flush shared_pool global;
------- only do in case of system performance issue or maintenance issue ----
Flush shared pool meaning flushing cached execution plan and sql Quries from memory.
Flush buffer cache meaning flushing cached data from memory.
Database restart which internally flush both
Friday, May 17, 2024
DML TRIGGERS IN ORACLE DB
-- Table for update trigger
id number primary key,
old_name varchar2(200),
new_name varchar2(200),
time_stamp varchar2(100),
message varchar2(200)
);
-- Table for insert and delete trigger
log_info varchar2(200),
time_stamp varchar2(100)
)
-- AFTER INSERT Trigger
AFTER INSERT ON student
FOR EACH ROW
BEGIN
-- Code to be executed after insert
-- For example, logging the insertion along with timestamp
INSERT INTO student_info (log_info , time_stamp)
VALUES ('New row inserted', TO_CHAR(SYSTIMESTAMP, 'DD-MON-YYYY HH:MI:SS AM'));
END;
/
-- After update trigger
AFTER UPDATE ON student
FOR EACH ROW
BEGIN
IF :OLD.name <> :NEW.name THEN
INSERT INTO student_update_info (id, old_name, new_name, update_date)
VALUES (:OLD.id, :OLD.name, :NEW.name, TO_CHAR(SYSTIMESTAMP, 'DD-MON-YYYY HH:MI:SS AM'));
END IF;
END;
/
-- AFTER DELETE Trigger
AFTER DELETE ON student
FOR EACH ROW
BEGIN
-- Code to be executed after delete
-- For example, logging the deletion
INSERT INTO student_info (log_info, time_stamp) VALUES ('Row deleted', TO_CHAR(SYSTIMESTAMP, 'DD-MON-YYYY HH:MI:SS AM'));
END;
/
Thursday, May 16, 2024
Load data from oracle db to csv or excel sheet
csv_fh utl_file.file_type;
begin
csv_fh := utl_file.fopen('/tmp', 'data_export.csv', 'W');
for r in ( select id,name from mydb) loop
utl_file.put_line(csv_fh, r.id||'|'||r.name);
end loop;
utl_file.fclose(csv_fh);
end;
CREATE DIRECTORY test_dir AS '/var/opt/oracle/lstest';
-- CREATE DIRECTORY test_dir AS '/tmp';
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp', 'test_file.txt', 'W');
UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid PATH FOR file.');
END;
/
utl_file_dir string /tmp
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp', 'test_file.txt', 'W');
UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid PATH FOR file.');
END;
/
PL/SQL procedure successfully completed.
SQL> ls -lrt /tmp
SP2-0734: unknown command beginning "ls -lrt /t..." - rest of line ignored.
SQL> ! cat /tmp/test_file.txt
Writing TO a file
SQL>
csv_fh utl_file.file_type;
begin
csv_fh := utl_file.fopen('/tmp', 'data_export.csv', 'W');
for r in ( select id,name from mydb) loop
utl_file.put_line(csv_fh, r.id||'|'||r.name);
end loop;
utl_file.fclose(csv_fh);
end;
PL/SQL procedure successfully completed.
rm command importance
2. To delete all files with the exception of filename1 and filename2:
$ rm -v !("filename1"|"filename2")
**********************************************************
*(pattern-list) – matches zero or more occurrences of the specified patterns
?(pattern-list) – matches zero or one occurrence of the specified patterns
+(pattern-list) – matches one or more occurrences of the specified patterns
@(pattern-list) – matches one of the specified patterns
!(pattern-list) – matches anything except one of the given patterns
*************************************************************
* – matches zero or more characters
? – matches any single character
[seq] – matches any character in seq
[!seq] – matches any character not in seq
****************************************************************
3. The example below shows how to remove all files other than all .zip files interactively:
$ rm -i !(*.zip)
=====================================================================
4. Next, you can delete all files in a directory apart from all .zip and .odt files as follows, while displaying what is being done:
$ rm -v !(*.zip|*.odt)
=========================================================================
. Using a pipeline and xargs, you can modify the case above as follows:
$ find . -type f -not -name '*gz' -print0 | xargs -0 -I {} rm -v {}
**********************************************************
diag_alert_500.log
you can do = rm diag_alert_*.log
********************************************************
--------------------------------------### Mostly successful command ###-------------------------------
find /path/to/folder -mtime +90 -exec rm {} +
find /path/to/folder -mtime +90 -delete
find /path/to/folder -mtime +90 -print
Enable OpenSSH on Windows 11
Step 1: Install OpenSSH Server You can do this via PowerShell (run as Administrator ): Check if it's already available: Get-WindowsCapab...
-
Action Full Command Description Update statistics for a specific table EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEES...
-
If the ALTER SYSTEM SUSPEND statement is entered on one system in an Oracle RAC configuration, then the internal locking mechanisms propagat...