Oracle hint cursor_sharing_exact using sql patch

Bind variable peeking is still a cause of plan instability, even after 11gR1’s introduction of adaptive cursor sharing. In my case adaptive cursor sharing wasn’t helpful for a daily batch job, because the sql was aged out of cache by the time the next scheduled run came around. Making everything worse was having parameter cursor_sharing […]

Read More Oracle hint cursor_sharing_exact using sql patch
November 9, 2015

Oracle select earliest and latest rows using keep group or first_value analytics

There are two ways of selecting the earliest and latest rows for each customer. 1) Keep group: SELECT t1.customer_ref , MAX ( t1.order_amount ) KEEP ( DENSE_RANK FIRST ORDER BY t1.order_date ASC ) AS earliest_order_amount , MAX ( t1.order_amount ) KEEP ( DENSE_RANK FIRST ORDER BY t1.order_date DESC ) AS latest_order_amount FROM t1 WHERE t1.order_amount […]

Read More Oracle select earliest and latest rows using keep group or first_value analytics
November 6, 2015

Windows PowerShell run script on all SQL Servers recovery mode

Micrsoft SQL Server databases should be kept in full recovery mode (the equivalent of Oracle’s archivelog mode) except for the master, tempdb, ReportServerTempDB databases. To check all databases in a SQL Server instance, run the below script in a SQL command window. Optionally uncomment the EXEC line to have this script switch databases to full […]

Read More Windows PowerShell run script on all SQL Servers recovery mode
November 5, 2015

Oracle Full Text simple example for like % grep wildcard

The equivalent of the grep command in oracle is like: SELECT * FROM dba_source s WHERE LOWER ( s.text ) LIKE ‘%within group%’ ; That works fast enough for querying dba_source, which is a small dataset. But for even medium sized tables, you really want a fast indexed query, which the “LIKE ‘%” syntax ordinarily […]

Read More Oracle Full Text simple example for like % grep wildcard
November 2, 2015

One Comment

Oracle top session info in RAC with tracefile name

See real time top session info in either RAC or standalone database, including tracefile name qualified by instance name, with: — ALTER SESSION SET nls_date_format = ‘Dy DD-Mon-YYYY HH24:MI:SS’ ; SELECT DISTINCT s.inst_id , s.sid , s.serial# , s.username , s.osuser , s.program || ‘ ‘ || s.module AS program , s.status , ROUND ( […]

Read More Oracle top session info in RAC with tracefile name
October 27, 2015

10046 trace a module using logon trigger

1) Update – thanks to Joaquin Gonzalez for pointing out a preferable safer method than logon trigger for 10046 tracing a particular module: EXEC DBMS_MONITOR.serv_mod_act_stat_enable ( service_name => ‘myservice’ , module_name => ‘myModule.exe’ , binds => TRUE ) You can verify service_name is what you expect by checking the column of the same name in […]

Read More 10046 trace a module using logon trigger
October 27, 2015

One Comment

mtputty directory path title

MtPuTTY multi tabbed putty is an improved variant of putty ssh client, easier to use if working on several servers at the same time. However it has an annoying tendency to display long directory paths in each tab title. You can switch that behaviour off with Tools > Settings > Show Display name. Microsoft Remote […]

Read More mtputty directory path title
October 17, 2015

Oracle date changed user changed columns and batch performance

Most core application tables benefit from columns like these: ALTER TABLE mytable ADD ( date_created DATE DEFAULT SYSDATE , user_created_by VARCHAR2(30) DEFAULT USER , date_changed DATE , user_changed_by VARCHAR2(30) ) ; The default values deal with inserts, for updates a trigger is needed: CREATE OR REPLACE TRIGGER tu_mytable BEFORE UPDATE ON mytable FOR EACH ROW […]

Read More Oracle date changed user changed columns and batch performance
October 16, 2015

Bash script to check for final closing /data xml tag in file

Bash script to check for final closing </data> xml tag in file: if [ -f file.xml ] then # if grep -1iq ‘</data>’ file.xml # simplest syntax # if tac file.xml | grep -1iq ‘</data>’ # faster syntax (tac is reverse cat) if tail -100 file.xml | grep -1iq ‘</data>’ # fastest syntax, assumes at […]

Read More Bash script to check for final closing /data xml tag in file
June 23, 2015

One Comment

List oracle indexes and their columns with listagg

List indexes on large tables, with listagg to show the indexed columns in a comma separated line, and outer join to include tables with no indexes: SELECT t.owner , t.table_name , ROUND ( t.blocks * 8 / 1024 / 1024 ) AS gb — assuming each block is default 8kb , t.num_rows , i.index_name , […]

Read More List oracle indexes and their columns with listagg
June 17, 2015