Everybody knows that you can get the Data Guard configuration in dgmgrl with the command:
show configuration;
but few know that this information is actually available in x$drc:
SQL> desc x$drc Name Null? Type --------------- -------- --------------- ADDR RAW(8) INDX NUMBER INST_ID NUMBER CON_ID NUMBER OBJECT_ID NUMBER ATTRIBUTE VARCHAR2(30) VALUE VARCHAR2(4000) PARENT_ID VARCHAR2(15) STATUS VARCHAR2(30) MESSAGE VARCHAR2(256) ERRNUM NUMBER VALUE_RAW RAW(4095) ERRTIME NUMBER
The table design is not very friendly, because it is a mix of ATTRIBUTE/VALUE pairs (hence many rows per object) and specific columns.
So, in order to get something usable to show the databases and their status, the only solution is to make use of PIVOT().
SELECT piv.*, obj.status FROM ( SELECT object_id, attribute, value FROM x$drc WHERE object_id IN ( SELECT object_id FROM x$drc WHERE attribute = 'DATABASE' ) ) drc PIVOT ( MAX ( value ) FOR attribute IN ( 'DATABASE' DATABASE , 'intended_state' intended_state , 'connect_string' connect_string , 'RAC' RAC , 'enabled' enabled , 'role' role , 'receive_from' receive_from , 'ship_to' ship_to , 'dgb_connect' dgb_connect , -- 'static_connect_identifier' static_connect_identifier , 'FSFOTargetValidity' FSFOTargetValidity ) ) piv JOIN x$drc obj ON ( obj.object_id = piv.object_id AND obj.attribute = 'DATABASE' );
To get it in a friendly format, I recommend using SQLcl and settting
set sqlformat ansiconsole
This is what I get on a simple two databases configuration (primary/standby):
OBJECT_ID DATABASE INTENDED_STATE CONNECT_STRING RAC ENABLED ROLE RECEIVE_FROM SHIP_TO DGB_CONNECT FSFOTARGETVALIDITY STATUS 16842752 ludocdb2_site1 READ-WRITE-XPTON newbox01:1521/ludoCDB2_SITE1_DGMGRL NO YES PRIMARY -N/A- ludocdb2_site2 newbox01:1521/ludoCDB2_SITE1_DGMGRL 2 SUCCESS 33619968 ludocdb2_site2 PHYSICAL-APPLY-ON newbox02:1521/ludoCDB2_SITE2_DGMGRL NO YES PHYSICAL -UNKNOWN- -N/A- newbox02:1521/ludoCDB2_SITE2_DGMGRL 1 SUCCESS
Although it is much easier to get this information from DGMGRL, get it programmatically is more sure/flexible using the SQL interface, as you know what you want to get, no matter how the dgmgrl syntax changes.
Looking forward to have the REST APIs in a future version of Data Guard
—
Ludovico