Shrink msdb database SQL Server

Steps to shrink msdb database in SQL Server 2005:

  1. T-SQL: truncate table msdb.dbo.log_shipping_monitor_history_detail
  2. T-SQL: exec msdb.dbo.sp_purge_jobhistory @oldest_date='2013-02-07T13:55:10'
    (change date above as required)
  3. T-SQL: alter index all on msdb.dbo.sysjobhistory reorganize
  4. Management Studio: system databases > msdb > tasks > shrink > database
    OR, same thing in T-SQL: dbcc shrinkdatabase('msdb')

To see disk usage for a database:

  1. Management Studio: system databases > msdb > Reports > Standard Reports > Disk Usage
Posted in SQL server | Leave a comment

Study notes crib sheet for exams 70-457 70-458 70-459 MCSE SQL Server 2012

Here is the crib sheet/study notes I used for the three exams:
70-457 Transition your MCTS on SQL Server 2008 to MCSA: SQL Server 2012 – Part 1
70-458 Transition your MCTS on SQL Server 2008 to MCSA: SQL Server 2012 – Part 2
70-459 Transition your MCITP on SQL Server 2008 to MCSE: Data Platform

Each of the exams has two components, one mostly straight DBA and the other more developer (T-SQL and SSIS). The passing score remains at 70%, 700 out of possible 1000, but you need to pass both of the two component parts of each exam. The first two exams are straightforward, but 70-459 is a little trickier with case study questions in addition to the normal multiple choice questions.

Microsoft often give special offers, it is worth checking that (http://www.microsoft.com/learning/en/us/offers.aspxbefore booking and paying for any exam – because the offer code has to be entered at the time of booking or you will lose the offer.  Currently (March 2013), Microsoft are offering free resits of any exam, but only if you enter their offer code before booking and paying for the original exam.
Continue reading

Posted in SQL server | Leave a comment

Angry DBA

Some fun from the Angry DBA site – http://web.archive.org/web/20050206023801/http://www.angrydba.com/

Contents:

  • Why are DBA’s angry?
  • Angry DBA stories
  • Is your DBA angry?
  • Angry DBA Gallery
  • How to make your DBA angry
  • DBA Jokes
  • Are you an angry DBA?

The website disappeared a long time ago, but is still available thanks to the Wayback Machine.

H/t APC.

Posted in Uncategorized | Leave a comment

Upgrade rman catalog – no need to upgrade oracle database version

Rman catalog can be upgraded to a higher version than its hosting database oracle version. This is useful if you want to back up new versions of oracle without changing the oracle version on the database used to host the rman catalog.

To do this, run the following commands from the higher version oracle database:

rman
connect target /   #< can be a higher version of oracle
connect catalog username/password@connect_string   #< can be a lower version of oracle
upgrade catalog ;

Tested on v11.2.0.2 - v11.2.0.3 on linux RHEL5 64 bit.

Posted in Rman | Leave a comment

Patch upgrade Oracle RAC 11.2.0.2 to 11.2.0.3 on linux

I used the steps below to apply patchset 11.2.0.3 to an existing 11.2.0.2 2-node RAC cluster on linux RHEL 5.8 64 bit.
Note that GRID_HOME and DB_HOME locations will both be changed as part of this patchset.

0) Download and unzip software from My Oracle Support into e.g. /unzipped
Main patch is 7 large zipfiles, is needed only on first node.
Two small pre-requisite patches need to be downloaded and unzipped on both nodes.

1) Apply pre-requisite patches, repeat on BOTH nodes
Patch 6880880 (opatch)
Patch 12539000

srvctl stop database -d DBNAME
/software/oracle/product/11.2.0/db_1/crs/install/rootcrs.pl -unlock (as root)
/unzipped/OPatch/opatch napply -oh OLD_GRID_HOME -local /unzipped/12539000
/unzipped/OPatch/opatch napply -oh OLD_DB_HOME -local /unzipped/12539000
cp -p OLD_GRID_HOME/crs/install/crsconfig_lib.pm OLD_GRID_HOME/crs/install/crsconfig_lib.pm.backup (as root)
vi OLD_GRID_HOME/crs/install/crsconfig_lib.pm (as root)
Add 'read_file' to the end of this line:
my @exp_func = qw(check_CRSConfig validate_olrconfig validateOCR read_file
OLD_GRID_HOME/rdbms/install/rootadd_rdbms.sh (as root)
OLD_GRID_HOME/crs/install/rootcrs.pl -patch (as root)
srvctl start database -d rmanp
srvctl start database -d rmant

2) Grid install (first node only)

cd /unzipped/grid
./runInstaller (choose upgrade option)

Specify new grid home location when asked, different from old grid home.
When prompted, run script as root on both nodes (node1 first, then node2)

3) Database install (first node only)

cd /unzipped/database
./runInstaller (I choose install, but alternatively choose upgrade to combine with (4) below) 

Specify new database home location when asked, different from old database home.
When prompted, run script as root on both nodes (node1 first, then node2).

4) Database upgrades (one node only) – if not done as part of (3) above via its ‘upgrade’ option.

alter system reset log_archive_dest scope=spfile sid='*' ;
alter system reset log_archive_dest_1 scope=spfile sid='*' ;
srvctl stop database -d DBNAME
srvctl start database -d DBNAME
cd NEW_DB_HOME/bin
./dbua

5) Cleanup

rm -fr /unzipped OLD_GRID_HOME OLD_DB_HOME
srvctl stop ASM -f (BUT do this ONLY if you are using ocfs and NOT using ASM, like I was)

More Information:

Posted in Installs, Linux, RAC | Leave a comment

Fix for ORA-24247 ACL calling Oracle Reports

Found this error on upgrade to 11gR2 trying to call Oracle Reports from within database:

ERROR at line 1:
ORA-20001: Error for submit_report. Report: ab_batch. Error -29273 ORA-29273: HTTP request failed
ORA-06512: at "SYS.UTL_HTTP", line 1722
ORA-24247: network access denied by access control list (ACL)
ORA-06512: at "MYUSER.MYPROC", line 60
ORA-06512: at line 1

Fix was to add this ACL:

BEGIN
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL (
acl => 'myreports.xml',
description => 'Andrew Fraser Feb-2013 for utl_http.request to reports',
principal => 'MYUSER', -- Must be in upper case
is_grant => TRUE,
privilege => 'connect');
END;
/
BEGIN
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL ( -- Creates the first target host
acl => 'myreports.xml',
host => 'myserver.mysite.com');
END;
/

More info in Oracle Support Document 1392315.1 (How to Troubleshoot and Solve the ORA-24247 Error?).

Other issues to note with this:

1) For connections to https/ssl – oracle wallets also needs to be configured.

2) If you want to use utl_http, it is also necessary to include ‘resolve’ in addition to the above connect privilege:

DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(
acl => 'myreports.xml',
principal => 'MYUSER',
is_grant => true,
privilege => 'resolve');

3) For external sites which are being accessed via a proxy, the proxy must also be included:

DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(
acl => 'myreports.xml',
host => 'proxy_server.mysite.com');

4) Tracing is very useful in working out what needs to be added:

alter session set events='24247 trace name errorstack level 3';
alter session set events = '10937 trace name context forever, level 6';
Posted in Uncategorized | Leave a comment

List databases using materialized view log

See which remote databases are using a ‘materialized view log’ on source database with:

SELECT mview_site , COUNT(*)
  FROM dba_registered_mviews
 GROUP BY mview_site
 ORDER BY 1 ;

The snaptime$$ column shows how old the data is in any materialized view log:

SELECT TRUNC(snaptime$$) , COUNT(*)
  FROM owner.mlog$_mytable
 GROUP BY TRUNC(snaptime$$)
 ORDER BY 1 ;

Oracle’s Interactive Quick Reference helped identify the dba_ views for this.

Posted in Materialized views | Leave a comment

RAC 11.2.0.2 Grid install fails on second node until disable virbr0 virtual network

I found I had to disable the virbr0 network interface to get Oracle RAC 11gR2 11.2.0.2 to install correctly (on RHEL 5.8 64 bit 2.6.18-308.el5 with ocfs2).

Problem was that root.sh failed on the second node. The error recorded in ocssd.log, “has a disk HB, but no network HB”, appeared to point to the multicast issue of bug 9974233 / note 12123703.1. However downloading and running masttest.pl showed that the eth1 interface, which is what the private interconnect ought to have been using, was ok for multicasting.

This command showed me that the private interconnect was actually using the ‘virbr0′ interface instead of the ‘eth1′ interface I wanted:

$GRID_HOME/bin/oifcfg getif

Fix was to remove the virbr0 entries in “ipcs -a” altogether with these commands:

virsh net-destroy default
virsh net-undefine default
service libvirtd restart

From http://www.cyberciti.biz/faq/linux-kvm-disable-virbr0-nat-interface/

Posted in Uncategorized | Leave a comment

Timeout SQL materialized view refresh

Problem today where one hourly cron MV refresh hung (waiting on “SQL*Net message from dblink”), causing the other refreshes to queue up waiting on locks, eventually using up all the session so users got “ORA-00018: maximum number of sessions exceeded”

To prevent this happening in the future, it is possible to timeout the MV refresh using a profile.

-- Create profile, 50mins connect time
create profile mv_refresh_limit_time limit connect_time 50 ;
-- Create user with that profile
create user mv_refresh_limit_time identified by ***** profile finance_refresh_limit_time ;
grant create session to mv_refresh_limit_time ;
-- Give the user the power to refresh materialized views
grant alter any materialized view to mv_refresh_limit_time ;

Then cron script runs as that time limited user:

conn mv_refresh_limit_time/*****
exec dbms_mview.refresh ( 'owner.mv_name' )

Note that parameter resource_limit must be set to true for this limit to take effect – and by default it is not set to true. Check/change it with:

sho parameter resource_limit
alter system set resource_limit=TRUE scope=both sid='*';

h/t Kamal Kiishore and OrionNet.

Andrew Fraser, DIT Operational DBA, andrew.fraser@abdn.ac.uk, x4542.

Posted in Uncategorized | Leave a comment

Convert java dates to oracle sql dates (esp. odm_publicobject createdate)

Java dates are recorded in milliseconds after 01-Jan-1970 00:00:00 GMT. To convert these to oracle dates, use sql like:

SELECT TO_DATE('01-JAN-1970 00:00:00','DD-MON-YYYY HH24:MI:SS') + createdate/(1000*60*60*24) createdate ,
       creator
  FROM odm_publicobject
 WHERE TO_DATE('01-JAN-1970 00:00:00','DD-MON-YYYY HH24:MI:SS') + createdate/(1000*60*60*24) > sysdate - 30
 ORDER BY 1 , 2 ;

Note that the above does not correct for any differences between local time and GMT. I didn’t need that level of accuracy, but if you did, you could use the TIMESTAMP datatype.

Posted in Scripts | Leave a comment