Posts

JMX log all or specific MBeans and all or specific values

  private static Log Log = LogFactory.getLog(LogMBean.class);   public void LogMBeans(String nameContains, String valueContains) throws IntrospectionException,       InstanceNotFoundException, ReflectionException   {     final List servers = new LinkedList ();     servers.add(ManagementFactory.getPlatformMBeanServer());     servers.addAll(MBeanServerFactory.findMBeanServer(null));     for (final MBeanServer server: servers)     {       Log.error("Server: " + server.getClass().getName());       final Set mbeans = new HashSet ();       mbeans.addAll(server.queryNames(null, null));       for (final ObjectName mbean: mbeans)       {         if (nameContains != null && mbean.toString().contains(nameContains) == false)         {           contin...

Monitoring ActiveMQ with JMX

service:jmx:rmi:///jndi/rmi:// : /jmxrmi Java based Nagios plugin for JMX http://exchange.nagios.org/directory/Plugins/Java-Applications-and-Servers/check_jmx/details java -jar check_jmx.jar       –U $ACTIVEMQ_JMX_URL       -O "org.apache.activemq:BrokerName= ,Type=Broker"        -A         java -jar check_jmx.jar    –U $ACTIVEMQ_JMX_URL    -O org.apache.activemq:BrokerName= ,Type=Queue,Destination= "     -A  

Oracle plsql block executed in plsql

For rerunnable migration this was necessary to conditionally compile/execute plsql that had a static cursor that was referencing a table that might not exist. The static cursor was required for updating where current of. If the table didn't exist the static cursor definition wouldn't compile. DECLARE BEGIN  EXECUTE IMMEDIATE 'DECLARE     BEGIN       execute immediate ''select &7 from dual'';     END;'; END; /

Fix non-unique PK id Oracle

DECLARE   CURSOR sqlCur IS SELECT id FROM (SELECT id, count(1) cnt FROM <someTable> GROUP BY id) WHERE cnt > 1;   recId <someTable>.id%TYPE;   newId <someTable>.id%TYPE;   fixSql VARCHAR2(500);   CURSOR dupeCur (recId <someTable>.id%TYPE) IS SELECT id FROM <someTable> WHERE id=recId FOR UPDATE of id; BEGIN     DBMS_OUTPUT.PUT_LINE('<someTable> checking and fixing dupe ids before creating PK');     --update 1 record from each id with a dupe     --repeat until none remaining     < >     LOOP       OPEN sqlCur;       FETCH sqlCur INTO recId;       EXIT dupe_detect WHEN sqlCur%NOTFOUND;         < >       LOOP         SELECT <someTable>_seq.nextval INTO newId FROM dual;         FOR rec I...

Quickly Generate and Load data in Oracle

The fastest way I've found over the years to generate and load data into Oracle, is to use sqlldr in direct mode reading from a linux pipe with all constraints disabled. Since  everything on linux is a file, any program can generate data and write it to the pipe/file. Disabling all constraints first dramatically increases the speed of loading. Indexes need to be rebuilt after direct loading since they are invalidated. Create a loader.ctl file which directs sqlldr how and where to load the data. The control file below instructs sqlldr to read the comma separated column data (CSV) from the /tmp/loadData.pipe file and write it to the table in direct mode which bypasses logging for speed. It should be noted that the data in the table is not recoverable should the database need to be restored unless you take a backup after the  load. Only the initial load is not logged. All future transaction against the data are logged and recoverable.  OPTIONS (DIRECT=TRUE)   ...

Java programmatic memory analysis

  public static void main(String[] args)   {     MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();     System.out.println(mbean.getHeapMemoryUsage());     System.out.println("Avail " + (mbean.getHeapMemoryUsage().getMax() - mbean.getHeapMemoryUsage().getUsed()) / 1024 + "KB");          List mbeans = ManagementFactory.getMemoryPoolMXBeans();     for (MemoryPoolMXBean bean : mbeans)     {         String name = bean.getName();         MemoryType type = bean.getType();         MemoryUsage usage = bean.getUsage();         MemoryUsage peak = bean.getPeakUsage();         MemoryUsage coll = bean.getCollectionUsage();                  System.out.println(String.format("%s, type=%s, usage=%s, peak=%s, coll=%s", name, type, usage, peak, coll)); ...

JDBC drivers and implicit statement caching

http://www.oracle.com/technetwork/database/enterprise-edition/memory.pdf 11.2 JDBC Developers Guide  HTML 11.2 JDBC Developers Guide - cache configuration and use  PDF The property can either be set as a System property via -D or as a connection property  on the getConnection method. Note that setting freeMemoryOnEnterImplicitCache does not  cause the parameter value buffers to be released, only the row data buffers. oracle.jdbc.freeMemoryOnEnterImplicitCache=true/false The default is Integer.MAX_VALUE. This is the  maximum size for a buffer which will be stored in the internal buffer cache. A single size is used  for both the char[] and byte[] buffers. The size is in chars for the char[] buffers and bytes for the  byte[] buffers. It is the maximum buffer size, not a predefined size. oracle.jdbc.maxCachedBufferSize= Integer.MAX_VALUE oracle.jdbc.useThreadLocalBufferCache=true/false With the 11.2 driver setting maxCachedBuf...