Author Archives: alesk
SQL*Net tracing in 11g
As you know, Oracle in 11g consolidated directories used for all kind of diagnostic operations, for better or worse. Anyway, that includes SQL*Net tracing at client side. On Windows (if not explicitly specified or turned off), trace files will end up deep down under your Documents and Settings folder, for example:
C:\Documents and Settings\alesk\Oracle\oradiag_alesk\diag\clients\user_alesk\host_34047044_11\trace
Fortunately, we can turn this pest off and trace the client the same way as we did before 11g:
sqlnet.ora
DIAG_ADR_ENABLED = OFF TRACE_LEVEL_CLIENT = 10 TRACE_FILE_CLIENT=11g_odac.trc TRACE_DIRECTORY_CLIENT=T:\TRACE ... ...
A short memo about _fix_control
While reading Jonathan Lewis blog about Histogram change I noticed interesting comment by Randolf Geist in which he mentioned a “feature” introduced in 10.2.0.2 – an undocumented parameter _fix_control that can be used to turn off/on a particular bug fix. I was not aware of this parameter until now.
Usually this sort of the parameter could be handy when some bug fix introduces more headache to a DBA than merits. One such example for a “bug fix” is the one Randolf and Jonathan discussed, Bug 5483301: Cardinality of 1 when predicate value non-existent in frequency histogram.
We could turn off this fix with the command:
alter system set "_fix_control"='5483301:off' scope=both; or for the session alter session set "_fix_control"='5483301:off';
Be careful using this parameter (or any other underscore parameter!) on your production servers. A quick search on Google revealed some “testimonials” such as the one at Pythian (see “Undocumented parameter _fix_control Or How to break your database”), where someone with the name Abel (apparently working in Oracle support) shed some light on this feature. According to Abel every bug fix that could be turned off must be registered (check v$system_fix_control), unless Oracle developer that wrote the bug fix code doesn’t want to register the patch or simply forgets to do the registration. Abel listed bug fixes related to the wrong results as the ones that are not registered on purpose. Forgotten bug numbers that users found should be reported to Oracle, so that they can take care about registration. Sweet.
That’s why it’s highly recommended that you beforehand check if particular bug fix is registered or not:
SQL> select bugno, value, description, optimizer_feature_enable from v$system_fix_control where bugno=5483301;
BUGNO VALUE DESCRIPTION OPTIMIZER_FEATURE_ENABLE
---------- ---------- --------------------- -------------------------
5483301 1 Use min repeat count 10.2.0.4
in freq histogram to
compute the density
Personally, I would use _fix_control as my last resort, turning off individual fixes sounds to me a risky business due to the fact that such combination is very likely not regression tested. On the other hand, it can be handy when trying to prove some thesis on non-production servers, a real time saver compared with fresh server installation with lower patch set version.
Python articles on OTN
Here I’ll try to maintain a list of articles published on OTN about python & Oracle:
- Python cx_Oracle 5.0 New Features Overview
- High Concurrency with Python and Oracle Database
- Python Data Persistence with Oracle Database
- Using Python with TurboGears
- Mastering Oracle+Python, Part 1: Querying Best Practices
- Mastering Oracle+Python, Part 2: Working with Times and Dates
- Mastering Oracle+Python, Part 3: Data Parsing
- Mastering Oracle+Python, Part 4: Transactions and large objects
- Mastering Oracle+Python, Part 5: Stored Procedures, Programming Python
- Build a Rapid Web Development Environment for Python Server Pages and Oracle
- Wrapping Your Brain Around Oracle + Python
- Using Python With Oracle 11g
Python minidom snippet (converting xml file produced by SQL Developer to csv)
I wrote a simple python script for converting xml export files generated by SQL Developer to csv format.
Let’s first see what is the output from SQL Developer. Export file of the Oracle table EMP generated by SQL Developer looks like this:
<?xml version='1.0' encoding='Cp1250' ?> <RESULTS> <ROW> <COLUMN NAME="COMM"><![CDATA[]]></COLUMN> <COLUMN NAME="DEPTNO"><![CDATA[20]]></COLUMN> <COLUMN NAME="EMPNO"><![CDATA[7369]]></COLUMN> <COLUMN NAME="ENAME"><![CDATA[SMITH]]></COLUMN> <COLUMN NAME="HIREDATE"><![CDATA[17.12.1980]]></COLUMN> <COLUMN NAME="JOB"><![CDATA[CLERK]]></COLUMN> <COLUMN NAME="MGR"><![CDATA[7902]]></COLUMN> <COLUMN NAME="SAL"><![CDATA[800]]></COLUMN> </ROW> <ROW> <COLUMN NAME="COMM"><![CDATA[300]]></COLUMN> <COLUMN NAME="DEPTNO"><![CDATA[30]]></COLUMN> <COLUMN NAME="EMPNO"><![CDATA[7499]]></COLUMN> <COLUMN NAME="ENAME"><![CDATA[ALLEN]]></COLUMN> <COLUMN NAME="HIREDATE"><![CDATA[20.02.1981]]></COLUMN> <COLUMN NAME="JOB"><![CDATA[SALESMAN]]></COLUMN> <COLUMN NAME="MGR"><![CDATA[7698]]></COLUMN> <COLUMN NAME="SAL"><![CDATA[1600]]></COLUMN> </ROW> <ROW> <COLUMN NAME="COMM"><![CDATA[500]]></COLUMN> <COLUMN NAME="DEPTNO"><![CDATA[30]]></COLUMN> <COLUMN NAME="EMPNO"><![CDATA[7521]]></COLUMN> <COLUMN NAME="ENAME"><![CDATA[WARD]]></COLUMN> <COLUMN NAME="HIREDATE"><![CDATA[22.02.1981]]></COLUMN> <COLUMN NAME="JOB"><![CDATA[SALESMAN]]></COLUMN> <COLUMN NAME="MGR"><![CDATA[7698]]></COLUMN> <COLUMN NAME="SAL"><![CDATA[1250]]></COLUMN> </ROW> </RESULTS>
And my goal was to convert xml file to csv format:
COMM;DEPTNO;EMPNO;ENAME;HIREDATE;JOB;MGR;SAL;
;20;7369;SMITH;17.12.1980;CLERK;7902;800;
300;30;7499;ALLEN;20.02.1981;SALESMAN;7698;1600;
500;30;7521;WARD;22.02.1981;SALESMAN;7698;1250;
In this “exercise” I decided to use minidom for xml parsing which is quite easy to code with, but at the same time is suitable only for small xml files, such as exports of database code books. Perhaps I’ll publish similar python script, where I’ll parse xml with sax module.
# -*- coding: cp1250 -*-
# xml2csv.py -- AlesK, 2009
#
# Purpose:
# simple python code snippet that shows how to use python minidom module
# to convert export file produced by Oracle SQL Developer (Table->Export->to xml)
# to csv format. Note that minidom (DOM) as such is suitable for parsing
# small xml files, such as database codebooks!
#
# Note: Script doesn't even try to do any error handling at all and
# as such is far away from being anything more than a simple demo.
#
# Example:
# cmd> python xml2csv.py emp.xml > emp.csv
#
import sys
import xml.dom.minidom
doc = xml.dom.minidom.parse(sys.argv[1])
# if encoding is not explicitly declared in xml header then
# I'm assuming Cp1250 for the output file
if doc.encoding:
encode = doc.encoding
else:
# Cp1250 is my personal preference if encoding is not
# specified in xml header
encode = 'Cp1250'
# fields delimiter
csv = ';'
# during the pass of the first ROW collect
# column names (for csv file header)
firstRowPass = True
header = ''
for row in doc.getElementsByTagName("ROW"):
row_data = ''
for column in row.getElementsByTagName("COLUMN"):
for column_value in column.childNodes:
row_data += column_value.data
row_data += csv
if firstRowPass:
header += column.getAttribute('NAME') + csv
if firstRowPass:
print header.encode(encode)
firstRowPass = False
print row_data.encode(encode)
doc.unlink()
#
# End xml2csv.py
#
ShellRunas
Recently I’m more involved with Windows 2008 Server and nuances Microsoft delivered with this release (ok, they started with Vista, but this is an OS I simply don’t care about). One such odd decision that MS team made was to replace “Run As…” in Explorer shell with Run As Administrator, removing the option to enter alternative account.
You can still use command line tool runas in the same way you can on XP/2003, which is fine if you want to create permanent shortcut on your desktop to launch some application as some other user (not necessarily Administrator).
It’s silly that they removed “Run As…” from the Explorer Shell as this was really a convenient way for me — all I needed to do is to right click target application, select Run As, enter proper (“ordinary”, “application”…) user credentials and I was done. I was not surprised when I found plenty of complaints on the net about missing RunAs in the shell, so it didn’t come as a surprise when I found that Mark Russinovich delivered an applet that corrects that mistake. Simply download and install ShellRunas and you’re back in business.