<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Refresh &#8211; Blog DBA Dutra</title>
	<atom:link href="https://www.dbadutra.com/tag/refresh/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbadutra.com</link>
	<description></description>
	<lastBuildDate>Wed, 13 Dec 2023 20:22:12 +0000</lastBuildDate>
	<language>pt-BR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
<site xmlns="com-wordpress:feed-additions:1">170494511</site>	<item>
		<title>Refresh database from Data Guard</title>
		<link>https://www.dbadutra.com/2023/12/refresh-database-from-data-guard/</link>
					<comments>https://www.dbadutra.com/2023/12/refresh-database-from-data-guard/#respond</comments>
		
		<dc:creator><![CDATA[André Luiz Dutra Ontalba]]></dc:creator>
		<pubDate>Wed, 13 Dec 2023 20:17:28 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Dataguard]]></category>
		<category><![CDATA[Refresh]]></category>
		<guid isPermaLink="false">https://www.dbadutra.com/?p=6150</guid>

					<description><![CDATA[My client asked me for help. He needs to update the DEV environment every month The current process (using export-import) takes a few days. To reduce the time, an alternative approach was implemented The new procedure should considerably reduce the refresh time considerably to a few hours. 1         Pre-Requirements 2         Preparation Standby preparation Check if [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>My client asked me for help. He needs to update the DEV environment every month</p>



<p>The current process (using export-import) takes a few days.</p>



<p>To reduce the time, an alternative approach was implemented</p>



<ul class="wp-block-list">
<li>Replicate constantly all production changes to a standby database.&nbsp;&nbsp; This is achieved using Data Guard</li>



<li>For the refresh<ul><li>Stop synchronization</li></ul><ul><li>Drop old DEV databases</li></ul><ul><li>Create new DEV databases by cloning from the standby database</li></ul>
<ul class="wp-block-list">
<li>Restart synchronization</li>
</ul>
</li>
</ul>



<p>The new procedure should considerably reduce the refresh time considerably to a few hours.</p>



<h4 class="wp-block-heading"><a>1         Pre-Requirements</a></h4>



<ul class="wp-block-list">
<li>Oracle version and Patch Level on Primary and Secondary should be same.</li>



<li>Db_unique_name on standby and primary database should be different in order to used in DG_CONFIG setting of the LOG_ARCHIVE_CONFIG parameter.</li>
</ul>



<h4 class="wp-block-heading"><a>2         Preparation</a></h4>



<p></p>



<h4 class="wp-block-heading"><a><strong>Standby preparation</strong></a></h4>



<p>Check if standby is in sync with primary</p>



<pre class="wp-block-preformatted">****** To check archivelog apply lag

SELECT al.thrd "Thread", almax "Last Seq Received", lhmax "Last Seq Applied" FROM
(select thread# thrd, MAX(sequence#) almax FROM v$archived_log WHERE resetlogs_change#=(SELECT resetlogs_change#
FROM v$database) GROUP BY thread#) al, (SELECT thread# thrd, MAX(sequence#) lhmax FROM v$log_history
WHERE resetlogs_change#=(SELECT resetlogs_change# FROM v$database) GROUP BY thread#) lh WHERE al.thrd = lh.thrd;

</pre>



<p>Convert standby in snapshot standby</p>



<pre class="wp-block-preformatted">

shutdown immediate
startup mount
alter database convert to snapshot standby;
alter database open;

<a><strong> </strong></a></pre>



<p><a><strong>Create DB links between Standby and DEV</strong></a></p>



<pre class="wp-block-preformatted">---- Standby

alter pluggable database ALL open read only;
CREATE USER c##r_clone identified by Oracle23 CONTAINER=ALL;
GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE, SYSOPER, RESOURCE, CREATE ANY TABLE, UNLIMITED TABLESPACE TO  c##r_clone CONTAINER=ALL;
GRANT DBA to c##r_clone;

CREATE DATABASE LINK refresh_link CONNECT TO c##r_clone identified by Oracle23 using 'DUTSD'; 

----- Dev Database

CREATE DATABASE LINK refresh_link CONNECT TO c##r_clone identified by Oracle23 using 'DUTSST';

alter pluggable database ALL open read only;
CREATE USER c##r_clone identified by Oracle23 CONTAINER=ALL;
GRANT CREATE SESSION, CREATE PLUGGABLE DATABASE, SYSOPER, RESOURCE, CREATE ANY TABLE, UNLIMITED TABLESPACE TO  c##r_clone CONTAINER=ALL;
GRANT DBA to c##r_clone;

</pre>



<p><a><strong>Cleanup old PDB&#8217;s in DUTSD</strong></a></p>



<pre class="wp-block-preformatted">####### DROP OLD PDB - DUTSD
Show pdbs; 

ALTER PLUGGABLE DATABASE &lt;PDBNAME> CLOSE;
DROP PLUGGABLE DATABASE &lt;PDBNAME> INCLUDING DATAFILES;
</pre>



<h4 class="wp-block-heading"><a>3   Clone PDBs</a></h4>



<p>The files of standby were created using OMF convention.&nbsp;&nbsp; For this reason the database files need to be converted from</p>



<p>+DATA01/DUTSD/&lt;GUID&gt;/DATAFILE/&lt;file&gt;.&lt;id&gt;&nbsp; to</p>



<p>+DATA01/DUTSST/DATAFILE/&lt;file&gt;.dbf&#8217;</p>



<p><a><strong>Clone DUTSD</strong></a></p>



<pre class="wp-block-preformatted">CREATE PLUGGABLE DATABASE DUTSD FROM DUTSD@refresh_link storage unlimited tempfile reuse 
file_name_convert=('+DATA01/DUTSD/CCA899613E3D0713E0531114C30A2022/DATAFILE/duts01.474.1147957609','+DATA01/DUTSST/DATAFILE/duts01.dbf',
'+DATA01/DUTSD/CCA899613E3D0713E0531114C30A2022/DATAFILE/duts02.269.1147957617','+DATA01/DUTSST/ /DATAFILE/duts02.dbf') 
keystore identified by "Duts23" parallel 6;
</pre>



<h4 class="wp-block-heading"><a>4   Finalize the refresh</a></h4>



<pre class="wp-block-preformatted">. oraenv
sqlplus / as sysdba
shutdown immediate

startup mount


</pre>



<p><a><strong>Restore datafiles permissions</strong></a></p>



<pre class="wp-block-preformatted">
exec dbms_dnfs.restore_datafile_permissions('&lt;CDBNAME>');

</pre>



<p><a><strong>Convert the snapshot back to physical standby</strong></a></p>



<pre class="wp-block-preformatted">show pdbs
alter database convert to physical standby;
shutdown immediate
startup
</pre>



<p>See you soon in other articles.</p>



<p>Stay tuned by following us on Twitter @aontalba and Linkedin.</p>



<p><strong>Disclaimer: “The postings on this site are my own and do not necessarily represent my current employer positions, strategies, or opinions. The information here was edited to be useful for general purpose, specific data, and identifications was removed to allow reaching a generic audience and to be useful.”</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbadutra.com/2023/12/refresh-database-from-data-guard/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">6150</post-id>	</item>
	</channel>
</rss>
