简体   繁体   English

归档oracle数据库模式的最佳方法是什么?

[英]What is the best approach to archive oracle database schemas?

i have an application which creates database schema's (Oracle 10g) for the users. 我有一个为用户创建数据库架构(Oracle 10g)的应用程序。 The access to these schema's expires after a certain time. 对这些模式的访问将在一定时间后到期。 These schema's can be as large as 2GB in size. 这些架构的大小可以高达2GB。 The actual operational data for the application is comparatively less. 该应用程序的实际运行数据相对较少。 To keep the database size low, what would be the best approach to archive this database schema's considering that these can be restored when required to be accessed by the user. 为了保持数据库较小,考虑到可以在需要用户访问时可以还原这些数据库架构,最好的方法是归档该数据库架构。

I am thinking if the following approach: 我在想以下方法:

Convert the Schema in .csv files for each table and then compress the files (zip). 为每个表转换.csv文件中的架构,然后压缩文件(zip)。 Using csv can be an advantage considering its easy to convert csv to/from DB tables. 考虑到csv易于将csv与数据库表进行转换,使用csv可能是一个优势。

Please let me know if there is any better approach to do the same. 请让我知道是否有更好的方法可以做到这一点。 The main aim here is to save the operational DB space. 这里的主要目的是节省操作数据库空间。

Use Data Pump Export and Data Pump Import instead of building a custom tool. 使用数据泵导出数据泵导入,而不是构建自定义工具。 Exporting and importing data and metadata is not a trivial task. 导出和导入数据以及元数据并不是一件容易的事。 Data Pump was built for situations like this, it is already including with Oracle, and it has many advanced features. Data Pump是为这种情况而构建的,它已经包含在Oracle中,并且具有许多高级功能。

Here's a very simple example of archiving a schema using data pump. 这是一个使用数据泵归档模式的非常简单的示例。

Create a directory to hold the export. 创建一个目录以保存导出。 This is only required once per database. 每个数据库仅需要一次。

SQL> create directory export_directory as 'C:\test';

Directory created.

Create a test schema and sample data. 创建一个测试模式和示例数据。

SQL> create user test_user identified by test_user;
User created.
SQL> alter user test_user quota unlimited on users;
User altered.
SQL> create table test_user.table1 as select 1 a from dual;
Table created.

Export Data Pump. 导出数据泵。

C:\test>expdp jheller@orcl12 directory=export_directory dumpfile=test_user.dmp schemas=test_user

Export: Release 12.1.0.1.0 - Production on Thu Jun 12 22:33:25 2014

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "JHELLER"."SYS_EXPORT_SCHEMA_01":  jheller/********@orcl12 directory=export_directory dumpfile=test_user.dmp schemas=test_user
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 64 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
. . exported "TEST_USER"."TABLE1"                        5.031 KB       1 rows
Master table "JHELLER"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for JHELLER.SYS_EXPORT_SCHEMA_01 is:
  C:\TEST\TEST_USER.DMP
Job "JHELLER"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Jun 12 22:34:35 2014 elapsed 0 00:00:56

Compress the file. 压缩文件。

There is a data pump option to compress the data but it requires the Advanced Compression option. 有一个数据泵选项可压缩数据,但它需要“高级压缩”选项。 Instead of paying thousands of dollars per core I recommend downloading one of a thousand free software programs that have been compressing data for decades. 我建议您下载已经压缩数十年的数千种免费软件程序中的一种,而不是为每个内核支付数千美元。

C:\test>zip test_user.zip test_user.dmp
  adding: test_user.dmp (172 bytes security) (deflated 90%)

C:\test>dir
 Volume in drive C is OS
 Volume Serial Number is 660C-91D8

 Directory of C:\test

06/12/2014  10:37 PM    <DIR>          .
06/12/2014  10:37 PM    <DIR>          ..
06/12/2014  10:34 PM             1,435 export.log
06/12/2014  10:34 PM           212,992 TEST_USER.DMP
06/12/2014  10:37 PM            21,862 test_user.zip
               3 File(s)        236,289 bytes
               2 Dir(s)  689,950,937,088 bytes free

Drop the user. 删除用户。

SQL> drop user test_user cascade;

User dropped.

SQL> select count(*) from test_user.table1;
select count(*) from test_user.table1
                               *
ERROR at line 1:
ORA-00942: table or view does not exist

Import the user. 导入用户。

C:\test>impdp jheller@orcl12 directory=export_directory dumpfile=test_user.dmp

Import: Release 12.1.0.1.0 - Production on Thu Jun 12 22:41:52 2014

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

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Master table "JHELLER"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "JHELLER"."SYS_IMPORT_FULL_01":  jheller/********@orcl12 directory=export_directory dumpfile=test_user.dmp
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST_USER"."TABLE1"                        5.031 KB       1 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
Job "JHELLER"."SYS_IMPORT_FULL_01" successfully completed at Thu Jun 12 22:42:18 2014 elapsed 0 00:00:19

Check the data. 检查数据。

SQL> select count(*) from test_user.table1;

  COUNT(*)
----------
         1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM