Create RMAN Catalog and Register a Database in 12c

Create tablespace
create tablespace rec_catalog
datafile ‘/data/oradata/CDBRCAT/rec_catalog.dbf’
size 10M autoextend on
extent management local uniform size 1M;

alter session set “_ORACLE_SCRIPT”=true;

Create user
create user rcat identified by randompassword
default tablespace rec_catalog
quota unlimited on rec_catalog;

Grant Privileges 
grant recovery_catalog_owner to rcat;
select privilege from dba_sys_privs where grantee = ‘RECOVERY_CATALOG_OWNER’;

PRIVILEGE
—————————————-
CREATE TABLE
ALTER SESSION
CREATE VIEW
CREATE TYPE
CREATE SYNONYM
CREATE CLUSTER
CREATE TRIGGER
CREATE SESSION
CREATE PROCEDURE
CREATE DATABASE LINK
CREATE SEQUENCE

connect to the Catalog

Create an entry in TNS names CDBRCAT

rman target / catalog rcat@CDBRCAT

Recovery Manager: Release 12.2.0.1.0 – Production on Fri Aug 10 10:19:12 2018

Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.

connected to target database: CDBRCAT (DBID=1512138245)
recovery catalog database Password:
connected to recovery catalog database

Create RMAN Catalog

RMAN> create catalog tablespace rec_catalog;
recovery catalog created

Register the current database
RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

 

Verify if Database is registered in RMAN Catalog

sqlplus rcat@CDBRCAT

SQL*Plus: Release 12.2.0.1.0 Production on Fri Aug 10 10:31:20 2018

Copyright (c) 1982, 2016, Oracle. All rights reserved.

Enter password:
Last Successful login time: Fri Aug 10 2018 10:26:06 -04:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 – 64bit Production

SQL> select * from rc_database;

DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
———- ———- ———- ——– —————– ———
FINAL_CHANGE#
————-
1 2 1512138245 CDBRCAT 6766569 20-JUN-18

Advertisements

Setup SQL Agent alerts for User Error Messages

Setup a simple alert with SQL agent

1

When I test the alert it does not trigger the alert

Capture 2

 

Since error is not being logged, we can verify in the sys.messages

Capture 3

Lets alter the message to log

Capture 4

 

SELECT * FROM sys.messages WHERE
language_id = 1033 AND severity = 16
and message_id = 2812
EXEC sp_altermessage @message_id = 2812, @parameter = ‘WITH_LOG’ ,@parameter_value = ‘True’

Test the alert again, now we can see number of occurrences increases to 1

Capture 5

Failed to initialize sqlcmd library with error number -2147467259 [solved]

 

Setup trace

Send mail again.

Check trace output

SELECT failed because the following SET options have incorrect settings: ‘QUOTED_IDENTIFIER’. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

Change the send dmail command to include QUOTED_IDENTIFIER.

 

 

Log SQL Errors using Extended Events

First create the extended event session to monitor for any errors with severity grater than equal to 11

CREATE EVENT SESSION [ErrorCapture] ON SERVER ADD EVENT sqlserver.error_reported (ACTION(sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.sql_text, sqlserver.username) WHERE ([severity] >= (11))) ADD TARGET package0.event_file (
	SET filename = N'ErrorCapture'
	,max_file_size = (100)
	,max_rollover_files = (5)
	)
	WITH (
MAX_MEMORY = 4096 KB
,EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
,MAX_DISPATCH_LATENCY = 30 SECONDS
,MAX_EVENT_SIZE = 0 KB
,MEMORY_PARTITION_MODE = NONE
,TRACK_CAUSALITY = OFF
,STARTUP_STATE = ON
)
GO

 

How to view them in TSQL

DECLARE @error_log VARCHAR(max) = convert(VARCHAR(max), SERVERPROPERTY('ErrorLogFileName'))
DECLARE @error_log_dir VARCHAR(max) = reverse(substring(reverse(@error_log), charindex('\', reverse(@error_log)), len(@error_log)))

SELECT *
FROM sys.fn_xe_file_target_read_file(@error_log_dir + 'errorcap*.xel', NULL, NULL, NULL)