1.首先使用RMAN做一次备份(必需有次备份) rman target / backup database; or backup database root; backup pluggable database pdb; 2.在pdb中创建test用户并授权 sqlplus / as sysdba alter session set container=pdb; create user test identified by r
1.首先使用RMAN做一次备份(必需有次备份)
rman target /
backup database;
or
backup database root;
backup pluggable database pdb;
2.在pdb中创建test用户并授权
sqlplus / as sysdba
alter session set container=pdb;
create user test identified by redhat quota unlimited on users;
grant connect,create table to test;
3.用测试用户创建测试表并查询当前scn
create table t1 (id int);
insert into t1 values(1);
commit;
SQL> select * from t1;
ID
----------
1
conn / as sysdba
SQL> SELECT DBMS_FLASHBACK.get_system_change_number FROM dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1970004
4.再往t1表中插入一条数据
sqlplus test/redhat@pdb
SQL> insert into t1 values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
ID
----------
1
2
5.使用RMAN来恢复
rman target /
RECOVER TABLE 'TEST'.'T1' OF PLUGGABLE DATABASE pdb
UNTIL SCN 1970004
AUXILIARY DESTINATION '/u01/aux'
REMAP TABLE 'TEST'.'T1':'T1_old';
or
RECOVER TABLE 'TEST'.'T1' OF PLUGGABLE DATABASE pdb
UNTIL SCN 1970004
AUXILIARY DESTINATION '/u01/aux'
DATAPUMP DESTINATION '/u01/export'
DUMP FILE 'test_t1_old.dmp'--将以前的数据expdp出来
NOTABLEIMPORT;--不会将之前的数据导入
6.查询恢复过来的表t1_old验证恢复的内容
sqlplus test/redhat@pdb
SQL> select * from t1_old;
ID
----------
1
SQL> select * from t1;
ID
----------
1
2
7.总结
此功能效果和flashback table差不多
alter table t1 enable row movement;
先将t1备份
create table t1_bak as select * from t1;
flashback table t1 to scn 1970004;--基于SCN闪回
flashback table t1 to timestamp to_timestamp('2014-06-07 14:41:19','yyyy-mm-dd hh24:mi:ss'); --基于时间戳闪回
8.下面是日志
[oracle@source admin]$ rman target / Recovery Manager: Release 12.1.0.1.0 - Production on Sat Jun 7 14:42:27 2014 Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved. connected to target database: CDB1 (DBID=823327692) RMAN> RECOVER TABLE 'TEST'.'T1' OF PLUGGABLE DATABASE pdb UNTIL SCN 1970004 AUXILIARY DESTINATION '/u01/aux' REMAP TABLE 'TEST'.'T1':'T1_OLD';2> 3> 4> Starting recover at 07-JUN-14 using target database control file instead of recovery catalog current log archived allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=269 device type=DISK RMAN-05026: WARNING: presuming following set of tablespaces applies to specified Point-in-Time List of tablespaces expected to have UNDO segments Tablespace SYSTEM Tablespace UNDOTBS1 Creating automatic instance, with SID='peCr' initialization parameters used for automatic instance: db_name=CDB1 db_unique_name=peCr_pitr_pdb_CDB1 compatible=12.1.0.0.0 db_block_size=8192 db_files=200 sga_target=1G processes=80 diagnostic_dest=/u01/app/oracle db_create_file_dest=/u01/aux log_archive_dest_1='location=/u01/aux' enable_pluggable_database=true _clone_one_pdb_recovery=true #No auxiliary parameter file used starting up automatic instance CDB1 Oracle instance started Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 281019648 bytes Database Buffers 780140544 bytes Redo Buffers 5480448 bytes Automatic instance created contents of Memory Script: { # set requested point in time set until scn 1970004; # restore the controlfile restore clone controlfile; # mount the controlfile sql clone 'alter database mount clone database'; # archive current online log sql 'alter system archive log current'; } executing Memory Script executing command: SET until clause Starting restore at 07-JUN-14 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=75 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: restoring control file channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CDB1/autobackup/2014_06_07/o1_mf_s_849623963_9s5dwvr3_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/recovery_area/CDB1/autobackup/2014_06_07/o1_mf_s_849623963_9s5dwvr3_.bkp tag=TAG20140607T143923 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 output file name=/u01/aux/CDB1/controlfile/o1_mf_9s5f3180_.ctl Finished restore at 07-JUN-14 sql statement: alter database mount clone database sql statement: alter system archive log current contents of Memory Script: { # set requested point in time set until scn 1970004; # set destinations for recovery set and auxiliary set datafiles set newname for clone datafile 1 to new; set newname for clone datafile 4 to new; set newname for clone datafile 3 to new; set newname for clone datafile 8 to new; set newname for clone datafile 9 to new; set newname for clone tempfile 1 to new; set newname for clone tempfile 3 to new; # switch all tempfiles switch clone tempfile all; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 1, 4, 3, 8, 9; switch clone datafile all; } executing Memory Script executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME renamed tempfile 1 to /u01/aux/CDB1/datafile/o1_mf_temp_%u_.tmp in control file renamed tempfile 3 to /u01/aux/CDB1/datafile/o1_mf_temp_%u_.tmp in control file Starting restore at 07-JUN-14 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/aux/CDB1/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/aux/CDB1/datafile/o1_mf_undotbs1_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/aux/CDB1/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CDB1/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143730_9s5dsblv_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/recovery_area/CDB1/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143730_9s5dsblv_.bkp tag=TAG20140607T143730 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:55 channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/aux/CDB1/datafile/o1_mf_system_%u_.dbf channel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/aux/CDB1/datafile/o1_mf_sysaux_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CDB1/FB373ED0C69817BBE0436405A8C0E168/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143848_9s5dvrc5_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/recovery_area/CDB1/FB373ED0C69817BBE0436405A8C0E168/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143848_9s5dvrc5_.bkp tag=TAG20140607T143848 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36 Finished restore at 07-JUN-14 datafile 1 switched to datafile copy input datafile copy RECID=8 STAMP=849624258 file name=/u01/aux/CDB1/datafile/o1_mf_system_9s5f37pd_.dbf datafile 4 switched to datafile copy input datafile copy RECID=9 STAMP=849624258 file name=/u01/aux/CDB1/datafile/o1_mf_undotbs1_9s5f37py_.dbf datafile 3 switched to datafile copy input datafile copy RECID=10 STAMP=849624258 file name=/u01/aux/CDB1/datafile/o1_mf_sysaux_9s5f37pt_.dbf datafile 8 switched to datafile copy input datafile copy RECID=11 STAMP=849624258 file name=/u01/aux/CDB1/datafile/o1_mf_system_9s5f4zb5_.dbf datafile 9 switched to datafile copy input datafile copy RECID=12 STAMP=849624258 file name=/u01/aux/CDB1/datafile/o1_mf_sysaux_9s5f4z79_.dbf contents of Memory Script: { # set requested point in time set until scn 1970004; # online the datafiles restored or switched sql clone "alter database datafile 1 online"; sql clone "alter database datafile 4 online"; sql clone "alter database datafile 3 online"; sql clone 'PDB' "alter database datafile 8 online"; sql clone 'PDB' "alter database datafile 9 online"; # recover and open database read only recover clone database tablespace "SYSTEM", "UNDOTBS1", "SYSAUX", "PDB":"SYSTEM", "PDB":"SYSAUX"; sql clone 'alter database open read only'; } executing Memory Script executing command: SET until clause sql statement: alter database datafile 1 online sql statement: alter database datafile 4 online sql statement: alter database datafile 3 online sql statement: alter database datafile 8 online sql statement: alter database datafile 9 online Starting recover at 07-JUN-14 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/recovery_area/CDB1/archivelog/2014_06_07/o1_mf_1_27_9s5f2pgz_.arc archived log file name=/u01/app/oracle/recovery_area/CDB1/archivelog/2014_06_07/o1_mf_1_27_9s5f2pgz_.arc thread=1 sequence=27 media recovery complete, elapsed time: 00:00:01 Finished recover at 07-JUN-14 sql statement: alter database open read only contents of Memory Script: { sql clone 'alter pluggable database PDB open read only'; } executing Memory Script sql statement: alter pluggable database PDB open read only contents of Memory Script: { sql clone "create spfile from memory"; shutdown clone immediate; startup clone nomount; sql clone "alter system set control_files = ''/u01/aux/CDB1/controlfile/o1_mf_9s5f3180_.ctl'' comment= ''RMAN set'' scope=spfile"; shutdown clone immediate; startup clone nomount; # mount database sql clone 'alter database mount clone database'; } executing Memory Script sql statement: create spfile from memory database closed database dismounted Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 285213952 bytes Database Buffers 775946240 bytes Redo Buffers 5480448 bytes sql statement: alter system set control_files = ''/u01/aux/CDB1/controlfile/o1_mf_9s5f3180_.ctl'' comment= ''RMAN set'' scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 1068937216 bytes Fixed Size 2296576 bytes Variable Size 285213952 bytes Database Buffers 775946240 bytes Redo Buffers 5480448 bytes sql statement: alter database mount clone database contents of Memory Script: { # set requested point in time set until scn 1970004; # set destinations for recovery set and auxiliary set datafiles set newname for datafile 10 to new; # restore the tablespaces in the recovery set and the auxiliary set restore clone datafile 10; switch clone datafile all; } executing Memory Script executing command: SET until clause executing command: SET NEWNAME Starting restore at 07-JUN-14 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=11 device type=DISK channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/aux/PECR_PITR_PDB_CDB1/datafile/o1_mf_users_%u_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/recovery_area/CDB1/FB373ED0C69817BBE0436405A8C0E168/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143848_9s5dvrc5_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/recovery_area/CDB1/FB373ED0C69817BBE0436405A8C0E168/backupset/2014_06_07/o1_mf_nnndf_TAG20140607T143848_9s5dvrc5_.bkp tag=TAG20140607T143848 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 Finished restore at 07-JUN-14 datafile 10 switched to datafile copy input datafile copy RECID=14 STAMP=849624303 file name=/u01/aux/PECR_PITR_PDB_CDB1/datafile/o1_mf_users_9s5f7gol_.dbf contents of Memory Script: { # set requested point in time set until scn 1970004; # online the datafiles restored or switched sql clone 'PDB' "alter database datafile 10 online"; # recover and open resetlogs recover clone database tablespace "PDB":"USERS", "SYSTEM", "UNDOTBS1", "SYSAUX", "PDB":"SYSTEM", "PDB":"SYSAUX" delete archivelog; alter clone database open resetlogs; } executing Memory Script executing command: SET until clause sql statement: alter database datafile 10 online Starting recover at 07-JUN-14 using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/recovery_area/CDB1/archivelog/2014_06_07/o1_mf_1_27_9s5f2pgz_.arc archived log file name=/u01/app/oracle/recovery_area/CDB1/archivelog/2014_06_07/o1_mf_1_27_9s5f2pgz_.arc thread=1 sequence=27 media recovery complete, elapsed time: 00:00:00 Finished recover at 07-JUN-14 database opened contents of Memory Script: { sql clone 'alter pluggable database PDB open'; } executing Memory Script sql statement: alter pluggable database PDB open contents of Memory Script: { # create directory for datapump import sql 'PDB' "create or replace directory TSPITR_DIROBJ_DPDIR as '' /u01/aux''"; # create directory for datapump export sql clone 'PDB' "create or replace directory TSPITR_DIROBJ_DPDIR as '' /u01/aux''"; } executing Memory Script sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/aux'' sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/aux'' Performing export of tables... EXPDP> Starting "SYS"."TSPITR_EXP_peCr_crua": EXPDP> Estimate in progress using BLOCKS method... EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA EXPDP> Total estimation using BLOCKS method: 64 KB EXPDP> Processing object type TABLE_EXPORT/TABLE/TABLE EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS EXPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER EXPDP> . . exported "TEST"."T1" 5.039 KB 1 rows EXPDP> Master table "SYS"."TSPITR_EXP_peCr_crua" successfully loaded/unloaded EXPDP> ****************************************************************************** EXPDP> Dump file set for SYS.TSPITR_EXP_peCr_crua is: EXPDP> /u01/aux/tspitr_peCr_89262.dmp EXPDP> Job "SYS"."TSPITR_EXP_peCr_crua" successfully completed at Sat Jun 7 14:46:09 2014 elapsed 0 00:00:29 Export completed contents of Memory Script: { # shutdown clone before import shutdown clone abort } executing Memory Script Oracle instance shut down Performing import of tables... IMPDP> Master table "SYS"."TSPITR_IMP_peCr_xgeA" successfully loaded/unloaded IMPDP> Starting "SYS"."TSPITR_IMP_peCr_xgeA": IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE IMPDP> Processing object type TABLE_EXPORT/TABLE/TABLE_DATA IMPDP> . . imported "TEST"."T1_OLD" 5.039 KB 1 rows IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS IMPDP> Processing object type TABLE_EXPORT/TABLE/STATISTICS/MARKER IMPDP> Job "SYS"."TSPITR_IMP_peCr_xgeA" successfully completed at Sat Jun 7 14:46:15 2014 elapsed 0 00:00:02 Import completed Removing automatic instance Automatic instance removed auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_temp_9s5f6jdq_.tmp deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_temp_9s5f66jr_.tmp deleted auxiliary instance file /u01/aux/PECR_PITR_PDB_CDB1/onlinelog/o1_mf_3_9s5f7m7c_.log deleted auxiliary instance file /u01/aux/PECR_PITR_PDB_CDB1/onlinelog/o1_mf_2_9s5f7l9n_.log deleted auxiliary instance file /u01/aux/PECR_PITR_PDB_CDB1/onlinelog/o1_mf_1_9s5f7jps_.log deleted auxiliary instance file /u01/aux/PECR_PITR_PDB_CDB1/datafile/o1_mf_users_9s5f7gol_.dbf deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_sysaux_9s5f4z79_.dbf deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_system_9s5f4zb5_.dbf deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_sysaux_9s5f37pt_.dbf deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_undotbs1_9s5f37py_.dbf deleted auxiliary instance file /u01/aux/CDB1/datafile/o1_mf_system_9s5f37pd_.dbf deleted auxiliary instance file /u01/aux/CDB1/controlfile/o1_mf_9s5f3180_.ctl deleted auxiliary instance file tspitr_peCr_89262.dmp deleted Finished recover at 07-JUN-14

INNODBは、レドログと非論的なものを使用して、データの一貫性と信頼性を確保しています。 1.レドログは、クラッシュの回復とトランザクションの持続性を確保するために、データページの変更を記録します。 2.Undologsは、元のデータ値を記録し、トランザクションロールバックとMVCCをサポートします。

説明コマンドのキーメトリックには、タイプ、キー、行、および追加が含まれます。 1)タイプは、クエリのアクセスタイプを反映しています。値が高いほど、constなどの効率が高くなります。 2)キーは使用されているインデックスを表示し、nullはインデックスがないことを示します。 3)行はスキャンされた行の数を推定し、クエリのパフォーマンスに影響します。 4)追加の情報を最適化する必要があるというFilesortプロンプトを使用するなど、追加情報を提供します。

Temporaryを使用すると、MySQLクエリに一時テーブルを作成する必要があることが示されています。これは、異なる列、またはインデックスされていない列を使用して順番に一般的に見られます。インデックスの発生を回避し、クエリを書き直し、クエリのパフォーマンスを改善できます。具体的には、expliect出力に使用を使用する場合、MySQLがクエリを処理するために一時テーブルを作成する必要があることを意味します。これは通常、次の場合に発生します。1)個別またはグループビーを使用する場合の重複排除またはグループ化。 2)Orderbyに非インデックス列が含まれているときに並べ替えます。 3)複雑なサブクエリを使用するか、操作に参加します。最適化方法には以下が含まれます。1)OrderbyとGroupB

MySQL/INNODBは、4つのトランザクション分離レベルをサポートしています。 1.ReadunCommittedは、知らないデータを読み取ることができます。 2。読み込みは汚い読み取りを回避しますが、繰り返しのない読みが発生する可能性があります。 3. RepeatablerEadはデフォルトレベルであり、汚い読み取りと非回復不可能な読みを避けますが、幻の読み取りが発生する可能性があります。 4. Serializableはすべての並行性の問題を回避しますが、同時性を低下させます。適切な分離レベルを選択するには、データの一貫性とパフォーマンス要件のバランスをとる必要があります。

MySQLは、Webアプリケーションやコンテンツ管理システムに適しており、オープンソース、高性能、使いやすさに人気があります。 1)PostgreSQLと比較して、MySQLは簡単なクエリと高い同時読み取り操作でパフォーマンスが向上します。 2)Oracleと比較して、MySQLは、オープンソースと低コストのため、中小企業の間でより一般的です。 3)Microsoft SQL Serverと比較して、MySQLはクロスプラットフォームアプリケーションにより適しています。 4)MongoDBとは異なり、MySQLは構造化されたデータおよびトランザクション処理により適しています。

MySQLインデックスのカーディナリティは、クエリパフォーマンスに大きな影響を及ぼします。1。高いカーディナリティインデックスは、データ範囲をより効果的に狭め、クエリ効率を向上させることができます。 2。低カーディナリティインデックスは、完全なテーブルスキャンにつながり、クエリのパフォーマンスを削減する可能性があります。 3。ジョイントインデックスでは、クエリを最適化するために、高いカーディナリティシーケンスを前に配置する必要があります。

MySQL学習パスには、基本的な知識、コアの概念、使用例、最適化手法が含まれます。 1)テーブル、行、列、SQLクエリなどの基本概念を理解します。 2)MySQLの定義、作業原則、および利点を学びます。 3)インデックスやストアドプロシージャなどの基本的なCRUD操作と高度な使用法をマスターします。 4)インデックスの合理的な使用や最適化クエリなど、一般的なエラーのデバッグとパフォーマンス最適化の提案に精通しています。これらの手順を通じて、MySQLの使用と最適化を完全に把握できます。

MySQLの実際のアプリケーションには、基本的なデータベース設計と複雑なクエリの最適化が含まれます。 1)基本的な使用法:ユーザー情報の挿入、クエリ、更新、削除など、ユーザーデータの保存と管理に使用されます。 2)高度な使用法:eコマースプラットフォームの注文や在庫管理など、複雑なビジネスロジックを処理します。 3)パフォーマンスの最適化:インデックス、パーティションテーブル、クエリキャッシュを使用して合理的にパフォーマンスを向上させます。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン
