Saturday, August 15, 2015

Learning Chef and Ruby version pain ... rbenv issue 96



I was studiously working through the following chef-solo (knife) training document:




When I hit the following weird looking 'syntax error':


root@knife1:/vagrant# chef-solo -c solo.rb -j web.json
[2015-08-15T13:15:50+00:00] INFO: *** Chef 10.14.2 ***
[2015-08-15T13:15:50+00:00] INFO: Setting the run_list to ["recipe[apt]", "recipe[phpapp]"] from JSON
[2015-08-15T13:15:50+00:00] INFO: Run List is [recipe[apt], recipe[phpapp]]
[2015-08-15T13:15:50+00:00] INFO: Run List expands to [apt, phpapp]
[2015-08-15T13:15:50+00:00] INFO: Starting Chef Run for knife1
[2015-08-15T13:15:50+00:00] INFO: Running start handlers
[2015-08-15T13:15:50+00:00] INFO: Start handlers complete.


================================================================================
Recipe Compile Error in /vagrant/chef-repo/cookbooks/apt/providers/repository.rb
================================================================================


SyntaxError
-----------
compile error
/vagrant/chef-repo/cookbooks/apt/providers/repository.rb:45: syntax error, unexpected ':', expecting ')'
 so = Mixlib::ShellOut.new(cmd, env: { 'LANG' => 'en_US' })
                                    ^
/vagrant/chef-repo/cookbooks/apt/providers/repository.rb:45: syntax error, unexpected ')', expecting kEND


Cookbook Trace:
---------------
 /vagrant/chef-repo/cookbooks/apt/providers/repository.rb:203:in `class_from_file'


Relevant File Content:
----------------------
/vagrant/chef-repo/cookbooks/apt/providers/repository.rb:


 1:  #
 2:  # Cookbook Name:: apt
 3:  # Provider:: repository
 4:  #
 5:  # Copyright 2010-2011, Chef Software, Inc.
 6:  #
 7:  # Licensed under the Apache License, Version 2.0 (the "License");
 8:  # you may not use this file except in compliance with the License.
 9:  # You may obtain a copy of the License at


[2015-08-15T13:15:50+00:00] ERROR: Running exception handlers
[2015-08-15T13:15:50+00:00] ERROR: Exception handlers complete
[2015-08-15T13:15:50+00:00] FATAL: Stacktrace dumped to /vagrant/chef-solo/chef-stacktrace.out
[2015-08-15T13:15:50+00:00] FATAL: SyntaxError: compile error
/vagrant/chef-repo/cookbooks/apt/providers/repository.rb:45: syntax error, unexpected ':', expecting ')'
 so = Mixlib::ShellOut.new(cmd, env: { 'LANG' => 'en_US' })
                                    ^
/vagrant/chef-repo/cookbooks/apt/providers/repository.rb:45: syntax error, unexpected ')', expecting kEND


After double-checking all my scripts and commands (as I hadn't changed the repository.rb file), I started googling for this error and eventually stumbled across


todd commented on Apr 5, 2014
Narrowed this down - it looks like the recipe is using incompatible syntax with Ruby 1.8 (which I'm assuming is the Ruby version @CADBOT and @nazarhussain are using). Since Ruby 1.8 is not supported by this project, this isn't technically an issue, but I'd be more than happy to put some work in to make this compatible with 1.8.


nazarhussain commented on Apr 7, 2014
todd yes you are right I am using Ruby 1.8. Since its pre-built with Chef-Solo, so you must think to resolve this issue and make this recipe functional for old version of ruby.




Checking my ruby version, yes it was 1.8.x:


root@knife1:/vagrant# ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]


As this was a development/training effort and the build process was scripted via vagrant/provision.sh,  the easiest thing to was to upgrade the base image from Ubuntu 12.x (base ruby version is 1.8) to Ubuntu 14.x (base ruby version is 1.9).


For further details of the Vagrantfile, provision.sh and other setup files please see my github repo:






Sunday, May 10, 2015

Automatic Data Optimization (ADO) DBMS_ILM example - part one


I have working through some Oracle 12c ILM examples, I didn't find that many blog articles covering this feature but was happy to follow : http://gavinsoorma.com/2013/09/oracle-12c-new-feature-heat-map-and-automatic-data-optimization/


First of all as SYS enable heat mapping:

SQL> alter system set heat_map=on scope=both;


System altered.


SQL> exec dbms_ilm_admin.set_heat_map_start(start_date => sysdate - 30);


PL/SQL procedure successfully completed.


SQL> select OBJECT_NAME,SEGMENT_WRITE_TIME , SEGMENT_READ_TIME, FULL_SCAN FROM dba_heat_map_segment;


no rows selected

The following also didn't trigger any new records in dba_heat_map_segment:


SQL> select count(*) from scott.emp;


 COUNT(*)
----------
14


SQL> select OBJECT_NAME,SEGMENT_WRITE_TIME , SEGMENT_READ_TIME, FULL_SCAN FROM dba_heat_map_segment;


no rows selected


However after adding a policy:

SQL> ALTER TABLE scott.myobjects ILM ADD POLICY ROW STORE COMPRESS ADVANCED SEGMENT AFTER 30 DAYS OF NO MODIFICATION;


Table altered.

and re-runing the the select count(*) from  scott.myobjects:


SQL> col OBJECT_NAME form a30
SQL> select object_name, track_time, segment_write, FULL_SCAN, lookup_scan  from DBA_HEAT_MAP_SEG_HISTOGRAM where object_name='MYOBJECTS' and owner = 'SCOTT';


OBJECT_NAME       TRACK_TIME  SEG FUL LOO
------------------------------ ------------------ --- --- ---
MYOBJECTS       10-may-15 09:35:28 NO  YES NO



I also decide  to reduce my policy from 30 days to 1 day:


SQL> alter table scott.myobjects ILM DELETE POLICY P1;


Table altered.


SQL> select policy_name, action_type, scope, compression_level, condition_type, condition_days from  dba_ilmdatamovementpolicies  order by policy_name;


no rows selected


SQL> ALTER TABLE scott.myobjects ILM ADD POLICY ROW STORE COMPRESS ADVANCED SEGMENT AFTER 2 DAYS OF NO MODIFICATION;


Table altered.


SQL> select policy_name, action_type, scope, compression_level, condition_type, condition_days from  dba_ilmdatamovementpolicies  order by policy_name;


POLICY_NAME
--------------------------------------------------------------------------------
ACTION_TYPE SCOPE   COMPRESSION_LEVEL   CONDITION_TYPE
----------- ------- ------------------------------ ----------------------
CONDITION_DAYS
--------------
P41
COMPRESSION SEGMENT ADVANCED   LAST MODIFICATION TIME
    2


Next manually kick off  dbms_ilm.execute_ilm:


declare
 v_executionid number;
begin
 dbms_ilm.execute_ILM (ILM_SCOPE => dbms_ilm.SCOPE_SCHEMA, execution_mode => dbms_ilm.ilm_execution_offline, task_id => v_executionid);
end;
/

SQL>  


PL/SQL procedure successfully completed


this ran with task_id=82:

SQL> select task_id, start_time as start_time from user_ilmtasks;


  TASK_ID START_TIME
---------- ---------------------------------------------------------------------------
82 10-MAY-15 09.54.13.708088 PM


but didn't do anything


set line 150
col POLICY_NAME form a15
col OBJECT_NAME form a30
col SELECTED_FOR_EXECUTION form a10
col JOB_NAME form a10
select task_id, policy_name, object_name, selected_for_execution, job_name from user_ilmevaluationdetails;


SQL>


  TASK_ID POLICY_NAME   OBJECT_NAME  SELECTED_FOR_EXECUTION JOB_NAME
---------- --------------- ------------------------------ ------------------------------ ----------
82 P41   MYOBJECTS  PRECONDITION NOT SATISFIED

Let's give it 24 hours...

Thursday, April 30, 2015

The very handy DICT view


I want to check my FRA usage, but forgot the precise view name:

SQL> select * from v$flash_recovery_area;
select * from v$flash_recovery_area
             *
ERROR at line 1:
ORA-00942: table or view does not exist

So using the DICT view:

SQL> select table_name from dict where table_name like '%FLASH%';


TABLE_NAME
---------------------------------------------------------------------------------------------------------------
DBA_FLASHBACK_ARCHIVE
DBA_FLASHBACK_ARCHIVE_TABLES
DBA_FLASHBACK_ARCHIVE_TS
DBA_FLASHBACK_TXN_REPORT
DBA_FLASHBACK_TXN_STATE
USER_FLASHBACK_ARCHIVE
USER_FLASHBACK_ARCHIVE_TABLES
USER_FLASHBACK_TXN_REPORT
USER_FLASHBACK_TXN_STATE
V$FLASHBACK_DATABASE_LOG
V$FLASHBACK_DATABASE_LOGFILE
V$FLASHBACK_DATABASE_STAT
V$FLASHBACK_TXN_GRAPH
V$FLASHBACK_TXN_MODS
V$FLASHFILESTAT
V$FLASH_RECOVERY_AREA_USAGE
GV$FLASHBACK_DATABASE_LOG
GV$FLASHBACK_DATABASE_LOGFILE
GV$FLASHBACK_DATABASE_STAT
GV$FLASHFILESTAT

20 rows selected.

I can see the correct name is v$flash_recovery_area_usage:

SQL> select * from v$flash_recovery_area_usage;

FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES CON_ID
----------------------- ------------------ ------------------------- --------------- ----------
CONTROL FILE 0   0   0      0
REDO LOG      2.19   0   3      0
ARCHIVED LOG .2  .2   1      0
BACKUP PIECE     61.25       21.32   6      0
IMAGE COPY 0   0   0      0
FLASHBACK LOG 0   0   0      0
FOREIGN ARCHIVED LOG 0   0   0      0
AUXILIARY DATAFILE COPY 0   0   0      0

8 rows selected.


NB Which curiously in 12c has a 'Container ID', although this does seem to be set?