Passed my M102: MongoDB for DBAs Course!

Ive been doing a MongoDB course for the past 7 weeks which includes weekly homework and then a final exam. Happy to say ive passed with 100%!

image

The course is well recommended – https://university.mongodb.com/courses/10gen/M102/2014_May/syllabus

image

error: { "$err" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/query.js:128

When attempting to read data on a secondary, the following error is recieved:

error: { "$err" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/query.js:128

This happens because you are connected to a secondary and slaveOK is set to false. When connecting via  a shell, use the following to enable reads:

rs.slaveOk()

The one caveat with this is that on a system with many secondary’s, there can sometimes be latency between the master and secondary’s which may result in stale data. slaveOk works on the proviso that the user is happy reading data based on eventual consistency.

When connecting via an application, reading from a secondary is achieved via “Read preference”

error: { "$err" : "not master or secondary; cannot currently read from this replSet member", "code" : 13436 }

When attempting to connect to a mongo standalone server without replica set from an application server, the following error is recieved:

error: { "$err" : "not master or secondary; cannot currently read from this replSet member", "code" : 13436 }

On investigation it was found that /etc/mongo.conf had the follwoing parameter set:

replSet        = repqamongo

which means that the mongod process was started as an uninitialised replica.

To resolve, either remove the flag and restart mongod process or run rs.initiate() to turn into a single node replica (a bit pointless though)

Table sizes within a database

SELECT SCHEMA_NAME(tbl.schema_id) as [Schema]
, tbl.Name
, Coalesce((Select pr.name 
        From sys.database_principals pr 
        Where pr.principal_id = tbl.principal_id)
    , SCHEMA_NAME(tbl.schema_id)) as [Owner]
, tbl.max_column_id_used as [Columns]
, CAST(CASE idx.index_id WHEN 1 THEN 1 ELSE 0 END AS bit) AS [HasClusIdx]
, Coalesce( (Select sum (spart.rows) from sys.partitions spart 
    Where spart.object_id = tbl.object_id and spart.index_id < 2), 0) AS [RowCount]

, Coalesce( (Select Cast(v.low/1024.0 as float) 
    * SUM(a.used_pages - CASE WHEN a.type <> 1 THEN a.used_pages WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END) 
        FROM sys.indexes as i
         JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
         JOIN sys.allocation_units as a ON a.container_id = p.partition_id
        Where i.object_id = tbl.object_id  )
    , 0.0) AS [IndexKB]

, Coalesce( (Select Cast(v.low/1024.0 as float)
    * SUM(CASE WHEN a.type <> 1 THEN a.used_pages WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END) 
        FROM sys.indexes as i
         JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id
         JOIN sys.allocation_units as a ON a.container_id = p.partition_id
        Where i.object_id = tbl.object_id)
    , 0.0) AS [DataKB]
, tbl.create_date, tbl.modify_date

 FROM sys.tables AS tbl
  INNER JOIN sys.indexes AS idx ON (idx.object_id = tbl.object_id and idx.index_id < 2)
  INNER JOIN master.dbo.spt_values v ON (v.number=1 and v.type='E')
ORDER BY 6 desc

Is my Windows OS 32-bit or 64-bit?

Cool little query to retrieve OS architecture version

wmic os get osarchitecture

Returns something like this:

H:0_ORA_SETUP\sql>wmic os get osarchitecture
OSArchitecture
64-bit

the wmic os get command has more variables to search on. eg:

H:0_ORA_SETUP\sql>WMIC OS GET osarchitecture, caption /value
Caption=Microsoft Windows 7 Enterprise
OSArchitecture=64-bit

A lot more commands available – http://ss64.com/nt/wmic.html

ORA 600s after applying PSU7 for 11.2.0.3

We were seeing the following two ORA 600s after applying PSU7. Technically the issue wasnt related to PSU 7 but more the switchover involved when patching…

SR 3-8646935731 : ORA 600 [ktbdchk1: bad dscn]
SR 3-8664869401 : ORA 600-[FILE:jsks.c LINE:2388 FUNCTION:jsksStartOCICall() ID:OCIKCallPus]

Caused by Bug 8895202 : ITL HAS HIGHER COMMIT SCN THAN BLOCK SCN

The solution was to set the following dynamic parameter on both the primary and standby database:

ALTER SYSTEM SET "_ktb_debug_flags"=8 SCOPE=BOTH;

This parameter is designed to heal blocks having invalid dependent scn’s on switchover operations.

From the traces provided to oracle, I was told that the affected object for this issue was ID 12152331.

Running the following SQL determines the object:

select owner,object_name,object_type,subobject_name,object_id,data_object_id
  from   dba_objects
  where  object_id in (12152331)
  or     data_object_id in (12152331);

The affected blocks were on index SYS.I_SCHEDULER_JOB_RUN_DETAILS on table SCHEDULER$_JOB_RUN_DETAILS.

As well as the dynamic parameter, I also did the following:

ANALYZE TABLE SCHEDULER$_JOB_RUN_DETAILS VALIDATE STRUCTURE online;

ALTER INDEX SYS.I_SCHEDULER_JOB_RUN_DETAILS REBUILD online;

Follow me on Twitter! @dbamohsin

Ive set up a new twitter handle for all things DBA – follow me @dbamohsin.

All future posts will be tweeted on this handle

Thanks

Follow

Get every new post delivered to your Inbox.

Join 138 other followers