当前位置:   article > 正文

同构异机迁移方案2_目标服务器仅安装数据库软件scp物理文件

同构异机迁移方案2_目标服务器仅安装数据库软件scp物理文件

源端和目标端的数据库版本需要保持一致,补丁版本可以不一致,目标端磁盘空间不能小于源端空间,目标端只需要安装 Oracle 软件即可。

特别说明:本文档案例Oracle的安装路径不同,数据目录一致,采用scp的方式实现同构异机迁移。

迁移背景

ip

os version

os user/password

db version

db user/password

数据量

源库

192.168.40.52

centos7.9 x86_64

root/dhh

11.2.0.4

sys/oracle

87G

目标库

192.168.40.152

centos7.9 x86_64

root/dhh

11.2.0.4

sys/oracle

由于源库服务器剩余的磁盘空间不是很多,采用scp的方式实现同构异机迁移,本文档案例Oracle的安装路径不同,数据目录一致。迁移步骤如下:

迁移前准备

源库

源库数据模拟

该步骤生产环境省略,纯属个人实验环境构建测试数据

  1. --通过数据库主机连接
  2. su - oracle
  3. sqlplus / as sysdba
  4. select sysdate from dual;
  5. --操作系统上创建新的数据文件存放目录
  6. [root@11g-db ~]# mkdir -p /data
  7. [root@11g-db ~]# chown -R oracle:oinstall /data/
  8. --创建表空间
  9. --创建表空间,大小5m,开启自动扩展
  10. create tablespace test datafile '/data/test01.dbf' size 5M autoextend on NEXT 1M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
  11. --创建临时表空间
  12. create temporary tablespace testtemp tempfile '/data/testtemp01.dbf'
  13. size 50m autoextend on next 1m maxsize unlimited extent management local uniform size 4m;
  14. ##创建数据库用户
  15. --创建用户,指定默认表空间和临时表空间
  16. create user test identified by test default tablespace test temporary tablespace testtemp account unlock;
  17. --赋予权限 最后的with admin option表示权限转授,可以把本身获得的权限再授权给其他用户
  18. grant dba,connect,resource to test with admin option;
  19. 注意:密码最长30
  20. --切换用户
  21. conn test/test
  22. ##创建表
  23. create table test (id number primary key not null,name varchar2(100));
  24. insert into test values (1,'hm');
  25. insert into test values (2,'xk');
  26. insert into test values (3,'whm');
  27. commit;
  28. create table t1 (id int not null);
  29. begin
  30. for i in 1..10000 loop
  31. insert into t1 values(dbms_random.value()*10000);
  32. --如果列是主键
  33. --insert into t1 values(i);
  34. end loop;
  35. end;
  36. /

确认源库信息服务器信息和物理文件位置

源库内存cpu磁盘信息
  1. --内存
  2. [oracle@shipin04 admin]$ free -g
  3. total used free shared buff/cache available
  4. Mem: 125 10 7 74 107 38
  5. Swap: 0 0 0
  6. --cpu
  7. [oracle@shipin04 admin]$ lscpu
  8. Architecture: x86_64
  9. CPU op-mode(s): 32-bit, 64-bit
  10. Byte Order: Little Endian
  11. CPU(s): 64
  12. On-line CPU(s) list: 0-63
  13. Thread(s) per core: 2
  14. Core(s) per socket: 32
  15. Socket(s): 1
  16. NUMA node(s): 16
  17. ...
  18. --磁盘
  19. [oracle@shipin04 admin]$ df -Th
  20. Filesystem Type Size Used Avail Use% Mounted on
  21. /dev/vda3 xfs 200G 71G 129G 36% /
  22. devtmpfs devtmpfs 63G 0 63G 0% /dev
  23. tmpfs tmpfs 63G 0 63G 0% /dev/shm
  24. tmpfs tmpfs 63G 1.2G 62G 2% /run
  25. tmpfs tmpfs 63G 0 63G 0% /sys/fs/cgroup
  26. /dev/vda1 xfs 197M 114M 84M 58% /boot
  27. tmpfs tmpfs 13G 0 13G 0% /run/user/0
  28. /dev/mapper/vg_vdb1-lv_vdb1 ext4 493G 413G 55G 89% /data
  29. 由于剩余的磁盘空间不是很多,采用scp的方式实现同构异机迁移
源库oracle软件目录位置
  1. --查$ORACLE_BASE
  2. [oracle@shipin04 ~]$ echo $ORACLE_BASE
  3. /oracle/app
  4. --查$ORACLE_HOME
  5. [oracle@shipin04 ~]$ echo $ORACLE_HOME
  6. /oracle/app/product/11.2.0/db_1
源库物理文件位置
  1. su - oracle
  2. export ORACLE_SID=shipin04
  3. sqlplus / as sysdba
  4. --查看表空间和数据文件位置
  5. SQL> col tablespace_name for a50
  6. SQL> col file_name for a70
  7. SQL> set linesize 9999
  8. SQL> select tablespace_name,file_name from dba_data_files order by 1;
  9. TABLESPACE_NAME FILE_NAME
  10. -------------------------------------------------- --------------------------------------------------------
  11. SYSAUX /oracle/app/oradata/shipin04/sysaux01.dbf
  12. SYSTEM /oracle/app/oradata/shipin04/system01.dbf
  13. SYXT /data/oracledbf/syxt01.dbf
  14. SYXT /data/oracledbf/syxt03.dbf
  15. SYXT /data/oracledbf/syxt02.dbf
  16. TOPSP /data/oracledbf/topsp01.dbf
  17. TOPSP /data/oracledbf/topsp02.dbf
  18. UNDOTBS1 /oracle/app/oradata/shipin04/undotbs01.dbf
  19. USERS /data/oracledbf/users02.dbf
  20. USERS /oracle/app/oradata/shipin04/users01.dbf
  21. 10 rows selected.
  22. --查看控制文件:
  23. SQL> select name from v$controlfile;
  24. NAME
  25. --------------------------------------------------------------------------------
  26. /oracle/app/oradata/shipin04/control01.ctl
  27. /oracle/app/fast_recovery_area/shipin04/control02.ctl
  28. --查看日志文件:
  29. SQL> col member for a60
  30. SQL> select group#,member,status from v$logfile order by 1;
  31. GROUP# MEMBER STATUS
  32. ---------- ------------------------------------------------------------ -------
  33. 1 /oracle/app/oradata/shipin04/redo01.log
  34. 2 /oracle/app/oradata/shipin04/redo02.log
  35. 3 /oracle/app/oradata/shipin04/redo03.log
  36. 4 /oracle/app/oradata/shipin04/redo04.log
  37. 5 /oracle/app/oradata/shipin04/redo05.log
  38. 6 /oracle/app/oradata/shipin04/redo06.log
  39. 6 rows selected.
  40. --参数文件
  41. SQL> show parameter spfile;
  42. NAME TYPE VALUE
  43. ------------------------------------ ----------- ------------------------------
  44. spfile string /oracle/app/product/11.2.0/db_
  45. 1/dbs/spfileshipin04.ora
  46. --密码文件
  47. $ORACLE_HOME/dbs 目录下
  48. [oracle@shipin04 dbs]$ ls -l ora*
  49. -rw-r----- 1 oracle oinstall 1536 Jul 8 2023 orapwshipin04
  50. --监听文件
  51. $ORACLE_HOME/network/admin
  52. [oracle@shipin04 dbs]$ cd $ORACLE_HOME/network/admin
  53. [oracle@shipin04 admin]$ ls -l
  54. total 16
  55. -rw-r--r-- 1 oracle oinstall 361 Apr 26 2023 listener.ora
  56. drwxr-xr-x 2 oracle oinstall 64 Apr 26 2023 samples
  57. -rw-r--r-- 1 oracle oinstall 381 Dec 17 2012 shrept.lst
  58. -rw-r--r-- 1 oracle oinstall 211 Apr 26 2023 sqlnet.ora
  59. -rw-r----- 1 oracle oinstall 327 Apr 26 2023 tnsnames.ora
  60. [oracle@shipin04 ~]$ ls -lh /oracle/app/oradata/shipin04/
  61. total 45G
  62. -rw-r----- 1 oracle oinstall 13M Jan 31 10:11 control01.ctl
  63. -rw-r----- 1 oracle oinstall 501M Jan 31 10:10 redo01.log
  64. -rw-r----- 1 oracle oinstall 501M Jan 31 10:00 redo02.log
  65. -rw-r----- 1 oracle oinstall 501M Jan 31 10:10 redo03.log
  66. -rw-r----- 1 oracle oinstall 501M Jan 31 10:11 redo04.log
  67. -rw-r----- 1 oracle oinstall 501M Jan 31 10:00 redo05.log
  68. -rw-r----- 1 oracle oinstall 501M Jan 31 10:00 redo06.log
  69. -rw-r----- 1 oracle oinstall 2.9G Jan 31 10:10 sysaux01.dbf
  70. -rw-r----- 1 oracle oinstall 791M Jan 31 10:10 system01.dbf
  71. -rw-r----- 1 oracle oinstall 42M Jan 30 22:00 temp01.dbf
  72. -rw-r----- 1 oracle oinstall 6.2G Jan 31 10:10 undotbs01.dbf
  73. -rw-r----- 1 oracle oinstall 32G Jan 31 10:11 users01.dbf
  74. [oracle@shipin04 ~]$ ls -lh /data/oracledbf/
  75. total 45G
  76. -rwxrwxr-x 1 oracle oinstall 4.9G Jan 31 10:05 syxt01.dbf
  77. -rwxrwxr-x 1 oracle oinstall 5.0G Jan 31 10:05 syxt02.dbf
  78. -rwxrwxr-x 1 oracle oinstall 4.7G Jan 31 10:05 syxt03.dbf
  79. -rwxrwxr-x 1 oracle oinstall 79M Jan 31 10:05 topsp01.dbf
  80. -rwxrwxr-x 1 oracle oinstall 141M Jan 31 10:05 topsp02.dbf
  81. -rw-r----- 1 oracle oinstall 30G Jan 31 10:08 users02.dbf
  82. --查看归档模式
  83. su - oracle
  84. export ORACLE_SID=shipin04
  85. sqlplus / as sysdba
  86. SQL> archive log list;
  87. Database log mode Archive Mode
  88. Automatic archival Enabled
  89. Archive destination /data/archivelogs
  90. Oldest online log sequence 18130
  91. Next log sequence to archive 18135
  92. Current log sequence 18135

冷备份是最简单的备份方式,但是也是恢复最快的方式。在工作中,冷备份也是会遇到的,这里简单的测试一下。

源库数据量统计
  1. --查看数据量
  2. select sum(bytes)/1024/1024/1024 as "size(G)" from dba_data_files;
  3. size(G)
  4. ----------
  5. 86.2625732
  6. select tablespace_name,sum(bytes)/1024/1024/1024 GB from dba_data_files group by tablespace_name;
  7. TABLESPACE_NAME GB
  8. ------------------------------ ----------
  9. UNDOTBS1 6.10351563
  10. SYSAUX 2.87109375
  11. USERS 61.8518066
  12. SYXT 14.4514771
  13. SYSTEM .771484375
  14. TOPSP .213195801
  15. 6 rows selected.
  16. select round(sum(bytes) / 1024 / 1024 / 1024, 2) || 'G'
  17. from dba_segments
  18. where owner not in ('MDSYS', 'OUTLN', 'CTXSYS', 'OLAPSYS', 'HR', 'SYSTEM',
  19. 'EXFSYS', 'SCOTT', 'DBSNMP', 'ORDSYS', 'SYSMAN', 'OE', 'PM', 'SH',
  20. 'XDB', 'ORDDATA', 'IX', 'SYS', 'WMSYS') ;
  21. ROUND(SUM(BYTES)/1024/1024/1024,2)||'G'
  22. -----------------------------------------
  23. 67.33G
  24. --查看用户
  25. set lin1000 pagesize 999
  26. select username,default_tablespace,temporary_tablespace from dba_users where username not in ('SYS','SYSTEM','HR','OUTLN','MGMT_VIEW','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','OWBSYS_AUDIT','ORDDATA','CTXSYS','ANONYMOUS','SYSMAN','XDB','ORDPLUGINS','OWBSYS','SI_INFORMTN_SCHEMA','OLAPSYS','SCOTT','ORACLE_OCM','XS$NULL','BI','PM','MDDATA','IX','SH','DIP','OE','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');
  27. USERNAME DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
  28. ------------------------------ ------------------------------ ------------------------------
  29. XZZSK1 USERS TEMP
  30. XZZSK USERS TEMP
  31. WANGBIN USERS TEMP
  32. SYXK USERS TEMP
  33. --每个业务用户下的总对象数量校验
  34. SELECT D.OWNER,COUNT(1)
  35. FROM dba_objects d
  36. WHERE d.OWNER in ('XZZSK1','XZZSK','WANGBIN','SYXK')
  37. AND NOT EXISTS (SELECT 1 FROM DBA_RECYCLEBIN B WHERE B.object_name=D.OBJECT_NAME AND D.OWNER=B.owner)
  38. GROUP BY D.OWNER
  39. ORDER BY D.OWNER ;
  40. OWNER COUNT(1)
  41. ------------------------------ ----------
  42. SYXK 1770
  43. XZZSK 467
  44. --每个业务用户下的各个对象类别的数量校验
  45. SQL> select OWNER,OBJECT_TYPE,status,count(OBJECT_NAME) from dba_objects where owner in ('SYXK','XZZSK') group by OBJECT_TYPE,owner,status order by 1,3,2;
  46. OWNER OBJECT_TYPE STATUS COUNT(OBJECT_NAME)
  47. ------------------------------ ------------------- ------- ------------------
  48. SYXK PROCEDURE INVALID 1
  49. SYXK VIEW INVALID 1
  50. SYXK DATABASE LINK VALID 3
  51. SYXK INDEX VALID 915
  52. SYXK LOB VALID 53
  53. SYXK PROCEDURE VALID 1
  54. SYXK SEQUENCE VALID 12
  55. SYXK TABLE VALID 769
  56. SYXK TRIGGER VALID 2
  57. SYXK VIEW VALID 18
  58. XZZSK DATABASE LINK VALID 5
  59. XZZSK FUNCTION VALID 1
  60. XZZSK INDEX VALID 92
  61. XZZSK LOB VALID 5
  62. XZZSK SEQUENCE VALID 18
  63. XZZSK TABLE VALID 346
  64. 16 rows selected.
  65. --查询回收站lob对象数量(可选),lob数量不一致排查
  66. select owner,type,count(*) from dba_recyclebin group by owner,type order by owner;
  67. OWNER TYPE COUNT(*)
  68. ------------------------------ ------------------------- ----------
  69. SYXK INDEX 1
  70. SYXK LOB 5
  71. SYXK LOB INDEX 5
  72. SYXK TABLE 10
  73. --数据量统计
  74. ----新增count_rows 函数
  75. CREATE OR REPLACE FUNCTION count_rows (
  76. table_name IN varchar2,
  77. owner IN varchar2 := NULL
  78. )
  79. RETURN number AUTHID current_user
  80. AS
  81. num_rows number;
  82. stmt varchar2(2000);
  83. BEGIN
  84. IF owner IS NULL THEN
  85. stmt := 'select count(*) from "' || table_name || '"';
  86. ELSE
  87. stmt := 'select count(*) from "' || owner || '"."' || table_name || '"';
  88. END IF;
  89. EXECUTE IMMEDIATE stmt INTO num_rows;
  90. RETURN num_rows;
  91. END;
  92. /
  93. ---调用count_rows 函数,统计各种表的记录数
  94. select table_name, count_rows(table_name) nrows from user_tables where tablespace_name='ENTSERVICE'
  95. order by nrows desc;

源库生成参数文件

由于源库和目标库的安装目录不一致,所以需生成源库的参数文件传输到目标库进行更改。

  1. su - oracle
  2. export ORACLE_SID=shipin04
  3. sqlplus / as sysdba
  4. --查看数据库实例名
  5. SQL> show parameter name
  6. NAME TYPE VALUE
  7. ------------------------------------ ----------- ------------------------------
  8. cell_offloadgroup_name string
  9. db_file_name_convert string
  10. db_name string shipin04
  11. db_unique_name string shipin04
  12. global_names boolean FALSE
  13. instance_name string shipin04
  14. lock_name_space string
  15. log_file_name_convert string
  16. processor_group_name string
  17. service_names string shipin04
  18. --生成pfile参数文件
  19. SQL> create pfile='/home/oracle/pfile_shipin04_bak_20240131.ora' from spfile;
  20. File created.

源库expdp全库备份(可选)

如果时间和磁盘空间允许,可先对源库进行expdp全库备份。本文档案例由于时间和磁盘空间紧张未做该步骤。

  1. sqlplus / as sysdba
  2. SQL>create directory dump_dir as '/oraDB/tmp_backup'
  3. SQL>grant read,write on directory dump_dir to system;
  4. expdp system/oracle directory=dump_dir dumpfile=backup.dmp full=y;

源库关库

  1. --源库停止监听
  2. su - oracle
  3. [oracle@top130 ~]$ lsnrctl status
  4. [oracle@top130 ~]$ lsnrctl stop
  5. [oracle@top130 ~]$ lsnrctl stop
  6. --源库杀用户连接 不建议 该步骤慎重 该文档未进行该操作
  7. ps -ef|grep LOCAL=NO|awk '{print $2}'|xargs kill -9
  8. --源库关库
  9. su - oracle
  10. export ORACLE_SID=shipin04
  11. sqlplus / as sysdba
  12. SQL> shutdown immediate
  13. --查看进程,确认已关库
  14. ps -ef | grep ora_pmon

目标库

目标库内存cpu磁盘信息

  1. --内存
  2. [oracle@syxk01:/home/oracle]$ free -g
  3. total used free shared buff/cache available
  4. Mem: 125 51 73 0 0 72
  5. Swap: 15 0 15
  6. --cpu
  7. [oracle@syxk01:/home/oracle]$ lscpu
  8. Architecture: x86_64
  9. CPU op-mode(s): 32-bit, 64-bit
  10. Byte Order: Little Endian
  11. CPU(s): 64
  12. On-line CPU(s) list: 0-63
  13. Thread(s) per core: 1
  14. Core(s) per socket: 1
  15. Socket(s): 64
  16. NUMA node(s): 1
  17. Vendor ID: GenuineIntel
  18. ...
  19. --磁盘
  20. [oracle@syxk01:/home/oracle]$ df -Th
  21. Filesystem Type Size Used Avail Use% Mounted on
  22. /dev/vda1 xfs 200G 32G 169G 16% /
  23. devtmpfs devtmpfs 63G 0 63G 0% /dev
  24. tmpfs tmpfs 126G 0 126G 0% /dev/shm
  25. tmpfs tmpfs 63G 17M 63G 1% /run
  26. tmpfs tmpfs 63G 0 63G 0% /sys/fs/cgroup
  27. /dev/mapper/vg1-lv1 xfs 500G 33M 500G 1% /data
  28. tmpfs tmpfs 13G 0 13G 0% /run/user/54321
  29. tmpfs tmpfs 13G 0 13G 0% /run/user/0
  30. 由于源库和目标库内存cpu磁盘配置一样,因此后面参数文件不用更改内存参数,只用改路径就可以了。

安装数据库软件

采用脚本安装,该步骤省略。

  1. --查$ORACLE_BASE
  2. [oracle@syxk01:/home/oracle]$ echo $ORACLE_BASE
  3. /oracle/app/oracle
  4. --查$ORACLE_HOME
  5. [oracle@syxk01:/home/oracle]$ echo $ORACLE_HOME
  6. /oracle/app/oracle/product/11.2.0/db
扩展:静默安装数据库步骤

可参考如下:

创建用户

重建主机的Oracle用户 组 统一规范 uid gid 以保证共享存储挂接或其他需求的权限规范

  1. groupadd -g 504 oinstall
  2. groupadd -g 502 dba
  3. useradd -g oinstall -G dba -u 502 oracle
  4. passwd oracle
安装依赖包

安装好Oracle 需要的rpm包。安装rpm依赖包

  1. rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc- gcc-c++ libaio-devel libaio libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh ksh
  2. 挂载本地yum源
  3. yum install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common glibc-devel gcc- gcc-c++ libaio-devel libaio libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh ksh
修改配置文件 /etc/security/limits.conf
  1. oracle soft nproc 2047
  2. oracle hard nproc 16384
  3. oracle soft nofile 1024
  4. oracle hard nofile 65536
  5. oracle soft stack 10240
修改配置文件/etc/sysctl.conf
  1. fs.file-max = 6815744
  2. fs.aio-max-nr = 1048576
  3. kernel.shmall = 2097152
  4. kernel.shmmax = 2147483648
  5. kernel.shmmni = 4096
  6. kernel.sem = 250 32000 100 128
  7. net.ipv4.ip_local_port_range = 9000 65500
  8. net.core.rmem_default = 4194304
  9. net.core.rmem_max = 4194304
  10. net.core.wmem_default = 262144
  11. net.core.wmem_max = 1048576

重启主机或者输入命令 sysctl -p 生效当前配置

设置oracle 用户环境变量
  1. export ORACLE_BASE=/u01/app/oracle
  2. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  3. export PATH=$PATH:$ORACLE_HOME/bin
  4. export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
  5. export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64:/usr/local/lib64
  6. export ORACLE_SID=orcl #根据具体的填写
  7. #如果设置NLS_LANG,容易产生导入sql或dmp出错,因为其他环境下的不是utf8
  8. export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
  9. ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
  10. ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1; export ORACLE_HOME
  11. ORACLE_SID=orcl; export ORACLE_SID
  12. PATH=/usr/sbin:/usr/bin:/bin:/sbin:$ORACLE_HOME/bin export PATH

创建$ORACLE_BASE目录并赋予oracle目录权限:

mkdir -p /u01/app/oracle && chown -R oracle:oinstall /u01/app
上传数据库安装软件并用oracle 用户解压
静默安装
修改db_install.rsp文件参数
  1. vi /home/oracle/database/response/db_install.rsp
  2. ####
  3. oracle.install.option=INSTALL_DB_SWONLY
  4. ORACLE_HOSTNAME=DB_m2
  5. UNIX_GROUP_NAME=oinstall
  6. INVENTORY_LOCATION=/home/app/oracle/oraInventory
  7. SELECTED_LANGUAGES=en,zh_CN
  8. ORACLE_HOME=/home/app/oracle/product/11.2.0/db_1
  9. ORACLE_BASE=/home/app/oracle
  10. oracle.install.db.InstallEdition=EE
  11. oracle.install.db.DBA_GROUP=dba
  12. oracle.install.db.OPER_GROUP=oinstall
  13. oracle.install.db.config.starterdb.characterSet=AL32UTF8
  14. oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
  15. oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/app/oracle/oradata
  16. oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/app/oracle/recovery_data
  17. DECLINE_SECURITY_UPDATES=true //一定要设为true
  18. ####
安装oracle 软件
./runInstaller -responseFile /home/oracle/database/response/db_install.rsp -ignorePrereq -silent
安装监听
netca /silent /responsefile  /home/oracle/database/response/netca.rsp 
修改dbca配置文件
  1. vi /home/oracle/database/response/dbca.rsp
  2. ###
  3. RESPONSEFILE_VERSION = "11.2.0" //不能更改
  4. OPERATION_TYPE = "createDatabase"
  5. GDBNAME = "orcl11gabc.us.oracle.com" //全局数据库的名字=SID+主机域名
  6. SID = "orcl11gabc" //对应的实例名字
  7. TEMPLATENAME = "General_Purpose.dbc" //建库用的模板文件
  8. DATAFILEDESTINATION = /home/oracle/oradata //数据文件存放目录
  9. RECOVERYAREADESTINATION=/home/oracle/recovery_data //恢复数据存放目录
  10. CHARACTERSET = "AL32UTF8" //字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚。
  11. TOTALMEMORY = "5120" //oracle内存5120MB
  12. ###
安装实例
dbca -silent -responseFile  /home/oracle/database/response/dbca.rsp
卸载oracle 软件
  1. [oracle@db_m2 deinstall]$ pwd
  2. /u01/app/oracle/product/11.2.0/db_1/deinstall
  3. [oracle@db_m2 deinstall]$ ./deinstall
删实例
dbca -silent -deleteDatabase -sourceDB ORCL -sysDBAUserName sys -sysDBAPassword password

传输物理文件

传输参数文件

源库传输参数文件至目标库

将源库/home/oracle/pfile_shipin04_bak_20240131.ora拷贝到目标库的/home/oracle目录。

  1. --源库上操作 传输参数文件
  2. su - oracle
  3. [oracle@shipin04 ~]$ scp -P 422 pfile_shipin04_bak_20240131.ora oracle@172.18.1.130:/home/oracle/

由于源库和目标库内存cpu磁盘配置一样,因此参数文件不用更改内存参数,只用改路径就可以了。

目标库更改参数文件

参数文件中

shipin04.__oracle_base='/oracle/app'#ORACLE_BASE set from environment 为$ORACLE_BASE目录

*.audit_file_dest='/oracle/app/admin/shipin04/adump' 为$ORACLE_BASE目录/admin/shipin04/adump

.control_files中control02.ctl路径为$ORACLE_BASE目录/fast_recovery_area/shipin04/control02.ctl

.db_recovery_file_dest为$ORACLE_BASE目录/fast_recovery_area

.diagnostic_dest为$ORACLE_BASE目录

  1. --目标库操作 备份已传输的参数文件,避免改的有问题重新从源库服务器传输到目标库服务器
  2. [oracle@syxk01:/home/oracle]$ cp pfile_shipin04_bak_20240131.ora pfile_shipin04_bak_20240131.ora_bak02
  3. --更改参数文件中的oracle_base目录为目标库的oracle_base目录
  4. su - oracle
  5. vi pfile_shipin04_bak_20240131.ora
  6. :%s#/oracle/app#/oracle/app/oracle#g
  7. 更改参数文件中的控制文件路径/oracle/app/fast_recovery_area/shipin04/control02.ctl为
  8. 参数文件中的
  9. /oracle/app/oracle/fast_recovery_area/shipin04/control02.ctl
  10. 语法说明:
  11. :%s#源目录#新目录#g

更改后记得确认,避免更改错误。

更改前
  1. 更改pfile_shipin04_bak_20240131.ora参数文件
  2. su - oracle
  3. vi pfile_shipin04_bak_20240131.ora
  4. --更改前
  5. shipin04.__db_cache_size=73819750400
  6. shipin04.__java_pool_size=1879048192
  7. shipin04.__large_pool_size=1073741824
  8. shipin04.__oracle_base='/oracle/app'#ORACLE_BASE set from environment
  9. shipin04.__pga_aggregate_target=21474836480
  10. shipin04.__sga_target=85899345920
  11. shipin04.__shared_io_pool_size=0
  12. shipin04.__shared_pool_size=8053063680
  13. shipin04.__streams_pool_size=536870912
  14. *.audit_file_dest='/oracle/app/admin/shipin04/adump'
  15. *.audit_trail='db'
  16. *.compatible='11.2.0.4.0'
  17. *.control_files='/oracle/app/oradata/shipin04/control01.ctl','/oracle/app/fast_recovery_area/shipin04/control02.ctl'
  18. *.db_block_size=8192
  19. *.db_domain=''
  20. *.db_name='shipin04'
  21. *.db_recovery_file_dest='/oracle/app/fast_recovery_area'
  22. *.db_recovery_file_dest_size=107374182400
  23. *.diagnostic_dest='/oracle/app'
  24. *.dispatchers='(PROTOCOL=TCP) (SERVICE=shipin04XDB)'
  25. *.filesystemio_options='SETALL'
  26. *.log_archive_dest_1='location=/data/archivelogs'
  27. *.open_cursors=300
  28. *.pga_aggregate_target=21474836480
  29. *.processes=2000
  30. *.remote_login_passwordfile='EXCLUSIVE'
  31. *.sga_max_size=85899345920
  32. *.sga_target=85899345920
  33. *.undo_tablespace='UNDOTBS1'
更改后
  1. shipin04.__db_cache_size=73819750400
  2. shipin04.__java_pool_size=1879048192
  3. shipin04.__large_pool_size=1073741824
  4. shipin04.__oracle_base='/oracle/app/oracle'#ORACLE_BASE set from environment
  5. shipin04.__pga_aggregate_target=21474836480
  6. shipin04.__sga_target=85899345920
  7. shipin04.__shared_io_pool_size=0
  8. shipin04.__shared_pool_size=8053063680
  9. shipin04.__streams_pool_size=536870912
  10. *.audit_file_dest='/oracle/app/oracle/admin/shipin04/adump'
  11. *.audit_trail='db'
  12. *.compatible='11.2.0.4.0'
  13. *.control_files='/oracle/app/oradata/shipin04/control01.ctl','/oracle/app/oracle/fast_recovery_area/shipin04/control02.ctl'
  14. *.db_block_size=8192
  15. *.db_domain=''
  16. *.db_name='shipin04'
  17. *.db_recovery_file_dest='/oracle/app/oracle/fast_recovery_area'
  18. *.db_recovery_file_dest_size=107374182400
  19. *.diagnostic_dest='/oracle/app/oracle'
  20. *.dispatchers='(PROTOCOL=TCP) (SERVICE=shipin04XDB)'
  21. *.filesystemio_options='SETALL'
  22. *.log_archive_dest_1='location=/data/archivelogs'
  23. *.open_cursors=300
  24. *.pga_aggregate_target=21474836480
  25. *.processes=2000
  26. *.remote_login_passwordfile='EXCLUSIVE'
  27. *.sga_max_size=85899345920
  28. *.sga_target=85899345920
  29. *.undo_tablespace='UNDOTBS1'

目标库创建参数文件中不存在的目录

目标库所在服务器上创建参数文件中涉及的不存在的目录,从上到下先查目录是否存在若不存在务必创建避免后面步骤报错。

  1. --$ORACLE_BASE目录
  2. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle
  3. drwxrwxr-x 8 oracle oinstall 110 Jan 31 12:01 /oracle/app/oracle
  4. --审计目录
  5. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle/admin/shipin04/adump
  6. ls: cannot access /oracle/app/oracle/admin/shipin04/adump: No such file or directory
  7. [oracle@syxk01:/home/oracle]$ mkdir -p /oracle/app/oracle/admin/shipin04/adump
  8. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle/admin/shipin04/adump
  9. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:02 /oracle/app/oracle/admin/shipin04/adump
  10. --数据目录
  11. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oradata/shipin04/
  12. ls: cannot access /oracle/app/oradata/shipin04/: No such file or directory
  13. [oracle@syxk01:/home/oracle]$ mkdir -p /oracle/app/oradata/shipin04/
  14. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oradata/shipin04/
  15. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:03 /oracle/app/oradata/shipin04/
  16. --控制文件目录
  17. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle/fast_recovery_area/shipin04
  18. ls: cannot access /oracle/app/oracle/fast_recovery_area/shipin04: No such file or directory
  19. [oracle@syxk01:/home/oracle]$ mkdir -p /oracle/app/oracle/fast_recovery_area/shipin04
  20. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle/fast_recovery_area/shipin04
  21. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:03 /oracle/app/oracle/fast_recovery_area/shipin04
  22. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle/fast_recovery_area
  23. drwxr-x--- 3 oracle oinstall 22 Jan 31 16:03 /oracle/app/oracle/fast_recovery_area
  24. --诊断目录
  25. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oracle
  26. drwxrwxr-x 8 oracle oinstall 110 Jan 31 12:01 /oracle/app/oracle
  27. --归档目录
  28. [oracle@syxk01:/home/oracle]$ ls -ld /data/archivelogs
  29. ls: cannot access /data/archivelogs: No such file or directory
  30. su - root
  31. [root@syxk01:/root]$ mkdir -p /data/archivelogs
  32. [root@syxk01:/root]$ chown -R oracle:oinstall /data/archivelogs/
  33. [root@syxk01:/root]$ ls -ld /data/archivelogs/
  34. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:04 /data/archivelogs/

目标库start nomount启库

  1. su - oracle
  2. [oracle@syxk01:/home/oracle]$ export ORACLE_SID=shipin04
  3. [oracle@syxk01:/home/oracle]$ sqlplus / as sysdba
  4. SQL*Plus: Release 11.2.0.4.0 Production on Wed Jan 31 16:08:16 2024
  5. Copyright (c) 1982, 2013, Oracle. All rights reserved.
  6. Connected to an idle instance.
  7. idle 31-JAN-24> startup nomount pfile='/home/oracle/pfile_shipin04_bak_20240131.ora';
  8. ORACLE instance started.
  9. Total System Global Area 8.5516E+10 bytes
  10. Fixed Size 2262656 bytes
  11. Variable Size 1.1543E+10 bytes
  12. Database Buffers 7.3820E+10 bytes
  13. Redo Buffers 151117824 bytes
  14. idle 31-JAN-24>

目标库生成spfile参数文件(勿忘记)

该步骤不可省略,因为启库默认查找$ORACLE_HOME/dbs下的spfilesid.ora文件,如果不存在

  1. SQL> create spfile from pfile='/home/oracle/pfile_shipin04_bak_20240131.ora';
  2. SQL> shutdown immediate;
  3. SQL> startup nomount; --启动到nomount状态

传输控制文件

源库传输控制文件至目标库

源库控制文件位置:

/oracle/app/oradata/shipin04/control01.ctl

/oracle/app/fast_recovery_area/shipin04/control02.ctl

目标库控制文件位置:

/oracle/app/oradata/shipin04/control01.ctl

/oracle/app/oracle/fast_recovery_area/shipin04/control02.ctl

  1. --源库操作 control01.ctl传输
  2. su - oracle
  3. cd /oracle/app/oradata/shipin04/
  4. [oracle@shipin04 ~]$ scp -P 422 control01.ctl oracle@172.18.1.130:/oracle/app/oradata/shipin04/
  5. --源库操作 control02.ctl传输
  6. cd /oracle/app/fast_recovery_area/shipin04
  7. [oracle@shipin04 ~]$ scp -P 422 control02.ctl oracle@172.18.1.130:/oracle/app/oracle/fast_recovery_area/shipin04/

目标库启库至mount状态

  1. --目标库操作 启库到mount状态
  2. SQL> alter database mount; --启动到mount状态

传输数据文件

源库数据文件位置:

/oracle/app/oradata/shipin04

/data/oracledbf

目标库数据文件位置:

本文档步骤采用目标库保持和源库数据文件位置一样,不存在的目录需提前创建。

目标库目录检查

目标库操作 检查数据文件所有目录是否存在,若不存在,创建不存在的数据目录。

  1. --目标库操作 创建不存在的数据目录
  2. [oracle@syxk01:/home/oracle]$ ls -ld /oracle/app/oradata/shipin04/
  3. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:03 /oracle/app/oradata/shipin04/
  4. [oracle@syxk01:/home/oracle]$ ls -ld /data/oracledbf
  5. ls: cannot access /data/oracledbf: No such file or directory
  6. [root@syxk01:/root]$ mkdir -p /data/oracledbf
  7. [root@syxk01:/root]$ chown -R oracle:oinstall /data/oracledbf/
  8. [root@syxk01:/root]$ ls -ld /data/oracledbf/
  9. drwxr-xr-x 2 oracle oinstall 6 Jan 31 16:29 /data/oracledbf/

源库传输数据文件至目标库

  1. --源库操作 传输数据文件
  2. cd /oracle/app/oradata/shipin04/
  3. [oracle@shipin04 shipin04]$ ls -l
  4. total 46884852
  5. -rw-r----- 1 oracle oinstall 13287424 Jan 31 18:05 control01.ctl
  6. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:05 redo01.log
  7. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo02.log
  8. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo03.log
  9. -rw-r----- 1 oracle oinstall 524288512 Jan 31 17:50 redo04.log
  10. -rw-r----- 1 oracle oinstall 524288512 Jan 31 17:50 redo05.log
  11. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo06.log
  12. -rw-r----- 1 oracle oinstall 3082821632 Jan 31 18:05 sysaux01.dbf
  13. -rw-r----- 1 oracle oinstall 828383232 Jan 31 18:05 system01.dbf
  14. -rw-r----- 1 oracle oinstall 42999808 Jan 30 22:00 temp01.dbf
  15. -rw-r----- 1 oracle oinstall 6553608192 Jan 31 18:05 undotbs01.dbf
  16. -rw-r----- 1 oracle oinstall 34357911552 Jan 31 18:05 users01.dbf
  17. [oracle@shipin04 ~]$ scp -P 422 *.dbf oracle@172.18.1.130:/oracle/app/oradata/shipin04/
  18. [oracle@shipin04 shipin04]$ cd /data/oracledbf/
  19. [oracle@shipin04 oracledbf]$ ls -l
  20. total 46680776
  21. -rwxrwxr-x 1 oracle oinstall 5241118720 Jan 31 18:05 syxt01.dbf
  22. -rwxrwxr-x 1 oracle oinstall 5295316992 Jan 31 18:05 syxt02.dbf
  23. -rwxrwxr-x 1 oracle oinstall 4980744192 Jan 31 18:05 syxt03.dbf
  24. -rwxrwxr-x 1 oracle oinstall 82124800 Jan 31 18:05 topsp01.dbf
  25. -rwxrwxr-x 1 oracle oinstall 146808832 Jan 31 18:05 topsp02.dbf
  26. -rw-r----- 1 oracle oinstall 32054976512 Jan 31 18:05 users02.dbf
  27. [oracle@shipin04 oracledbf]$ scp -P 422 *.dbf oracle@172.18.1.130:/data/oracledbf/

传输日志文件

源库日志文件位置:/oracle/app/oradata/shipin04/

目标库日志文件位置:/oracle/app/oradata/shipin04/

源库传输日志文件至目标库

  1. --源库操作 传输数据文件
  2. [oracle@shipin04 shipin04]$ ls -l
  3. total 46884852
  4. -rw-r----- 1 oracle oinstall 13287424 Jan 31 18:05 control01.ctl
  5. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:05 redo01.log
  6. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo02.log
  7. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo03.log
  8. -rw-r----- 1 oracle oinstall 524288512 Jan 31 17:50 redo04.log
  9. -rw-r----- 1 oracle oinstall 524288512 Jan 31 17:50 redo05.log
  10. -rw-r----- 1 oracle oinstall 524288512 Jan 31 18:00 redo06.log
  11. -rw-r----- 1 oracle oinstall 3082821632 Jan 31 18:05 sysaux01.dbf
  12. -rw-r----- 1 oracle oinstall 828383232 Jan 31 18:05 system01.dbf
  13. -rw-r----- 1 oracle oinstall 42999808 Jan 30 22:00 temp01.dbf
  14. -rw-r----- 1 oracle oinstall 6553608192 Jan 31 18:05 undotbs01.dbf
  15. -rw-r----- 1 oracle oinstall 34357911552 Jan 31 18:05 users01.dbf
  16. [oracle@shipin04 ~]$ scp -P 422 *.log oracle@172.18.1.130:/oracle/app/oradata/shipin04/

目标库启库至open

  1. --目标库操作 启库到open状态
  2. SQL> alter database open; --启动到mount状态

传输密码文件

源库传输密码文件至目标库

源库密码文件位置:$ORACLE_HOME/dbs 即/oracle/app/product/11.2.0/db_1/dbs

目标库密码文件位置:$ORACLE_HOME/dbs即/oracle/app/oracle/product/11.2.0/db/dbs

  1. --源库操作 传输密码文件
  2. [oracle@shipin04 dbs]$ ls -l
  3. total 12996
  4. -rw-rw---- 1 oracle oinstall 1544 Nov 13 15:55 hc_shipin04.dat
  5. -rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
  6. -rw-r----- 1 oracle oinstall 24 Apr 26 2023 lkSHIPIN04
  7. -rw-r----- 1 oracle oinstall 1536 Jul 8 2023 orapwshipin04
  8. -rw-r----- 1 oracle oinstall 13287424 Jan 31 00:42 snapcf_shipin04.f
  9. -rw-r----- 1 oracle oinstall 3584 Dec 15 22:00 spfileshipin04.ora
  10. [oracle@shipin04 dbs]$ pwd
  11. /oracle/app/product/11.2.0/db_1/dbs
  12. [oracle@shipin04 ~]$ scp -P 422 orapwshipin04 oracle@172.18.1.130:/oracle/app/oracle/product/11.2.0/db/dbs/

传输监听文件(可选)

如果监听文件没有特殊设置可省略该步骤。

本文档案例监听文件没有特殊设置,省略该步骤

目标库停止监听

  1. --目标库操作 停止监听服务
  2. su - oracle
  3. lsnrctl stop
  4. lsnrctl status
  5. --目标库操作 监听文件备份
  6. cd /oracle/app/oracle/product/11.2.0/db/network/admin
  7. cp listener.ora listener.ora_old_bak_20240131

源库传输监听文件至目标库

源库监听文件位置:$ORACLE_HOME/dbs 即/oracle/app/product/11.2.0/db_1/network/admin

目标库监听文件位置:$ORACLE_HOME/dbs即/oracle/app/oracle/product/11.2.0/db/network/admin

  1. --源库操作 传输监听文件
  2. cd /oracle/app/product/11.2.0/db_1/network/admin
  3. [oracle@shipin04 admin]$ ls -l
  4. total 16
  5. -rw-r--r-- 1 oracle oinstall 361 Apr 26 2023 listener.ora
  6. drwxr-xr-x 2 oracle oinstall 64 Apr 26 2023 samples
  7. -rw-r--r-- 1 oracle oinstall 381 Dec 17 2012 shrept.lst
  8. -rw-r--r-- 1 oracle oinstall 211 Apr 26 2023 sqlnet.ora
  9. -rw-r----- 1 oracle oinstall 327 Apr 26 2023 tnsnames.ora
  10. [oracle@shipin04 admin]$ pwd
  11. /oracle/app/product/11.2.0/db_1/network/admin
  12. [oracle@shipin04 ~]$ scp -P 422 listener.ora oracle@172.18.1.130:/oracle/app/oracle/product/11.2.0/db/network/admin/

目标库启动监听

  1. --目标库操作 启动监听服务
  2. su - oracle
  3. lsnrctl start
  4. lsnrctl status

修改数据库监听配置

  1. alter system set local_listener='(ADDRESS=(PROTOCOL=tcp)(HOST=192.141.0.14)(PORT=1521))';
  2. alter system register;

修改新库主机名

  1. #hostname shipin04
  2. #vi /etc/sysconfig/network
  3. #vi /etc/hosts

目标库数据量统计

  1. 目标库数据量统计
  2. --查看数据量
  3. select sum(bytes)/1024/1024/1024 as "size(G)" from dba_data_files;
  4. size(G)
  5. ----------
  6. 86.2625732
  7. select tablespace_name,sum(bytes)/1024/1024/1024 GB from dba_data_files group by tablespace_name;
  8. TABLESPACE_NAME GB
  9. ------------------------------ ----------
  10. UNDOTBS1 6.10351563
  11. SYSAUX 2.87109375
  12. USERS 61.8518066
  13. SYXT 14.4514771
  14. SYSTEM .771484375
  15. TOPSP .213195801
  16. 6 rows selected.
  17. select round(sum(bytes) / 1024 / 1024 / 1024, 2) || 'G'
  18. from dba_segments
  19. where owner not in ('MDSYS', 'OUTLN', 'CTXSYS', 'OLAPSYS', 'HR', 'SYSTEM',
  20. 'EXFSYS', 'SCOTT', 'DBSNMP', 'ORDSYS', 'SYSMAN', 'OE', 'PM', 'SH',
  21. 'XDB', 'ORDDATA', 'IX', 'SYS', 'WMSYS') ;
  22. ROUND(SUM(BYTES)/1024/1024/1024,2)||'G'
  23. -----------------------------------------
  24. 67.33G
  25. --查看用户
  26. set lin1000 pagesize 999
  27. select username,default_tablespace,temporary_tablespace from dba_users where username not in ('SYS','SYSTEM','HR','OUTLN','MGMT_VIEW','FLOWS_FILES','MDSYS','ORDSYS','EXFSYS','DBSNMP','WMSYS','APPQOSSYS','APEX_030200','OWBSYS_AUDIT','ORDDATA','CTXSYS','ANONYMOUS','SYSMAN','XDB','ORDPLUGINS','OWBSYS','SI_INFORMTN_SCHEMA','OLAPSYS','SCOTT','ORACLE_OCM','XS$NULL','BI','PM','MDDATA','IX','SH','DIP','OE','APEX_PUBLIC_USER','SPATIAL_CSW_ADMIN_USR','SPATIAL_WFS_ADMIN_USR');
  28. USERNAME DEFAULT_TABLESPACE TEMPORARY_TABLESPACE
  29. ------------------------------ ------------------------------ ------------------------------
  30. XZZSK1 USERS TEMP
  31. XZZSK USERS TEMP
  32. WANGBIN USERS TEMP
  33. SYXK USERS TEMP
  34. --每个业务用户下的总对象数量校验
  35. SELECT D.OWNER,COUNT(1)
  36. FROM dba_objects d
  37. WHERE d.OWNER in ('XZZSK1','XZZSK','WANGBIN','SYXK')
  38. AND NOT EXISTS (SELECT 1 FROM DBA_RECYCLEBIN B WHERE B.object_name=D.OBJECT_NAME AND D.OWNER=B.owner)
  39. GROUP BY D.OWNER
  40. ORDER BY D.OWNER ;
  41. OWNER COUNT(1)
  42. ------------------------------ ----------
  43. SYXK 1770
  44. XZZSK 467
  45. --每个业务用户下的各个对象类别的数量校验
  46. SQL> select OWNER,OBJECT_TYPE,status,count(OBJECT_NAME) from dba_objects where owner in ('SYXK','XZZSK') group by OBJECT_TYPE,owner,status order by 1,3,2;
  47. OWNER OBJECT_TYPE STATUS COUNT(OBJECT_NAME)
  48. ------------------------------ ------------------- ------- ------------------
  49. SYXK PROCEDURE INVALID 1
  50. SYXK VIEW INVALID 1
  51. SYXK DATABASE LINK VALID 3
  52. SYXK INDEX VALID 915
  53. SYXK LOB VALID 53
  54. SYXK PROCEDURE VALID 1
  55. SYXK SEQUENCE VALID 12
  56. SYXK TABLE VALID 769
  57. SYXK TRIGGER VALID 2
  58. SYXK VIEW VALID 18
  59. XZZSK DATABASE LINK VALID 5
  60. XZZSK FUNCTION VALID 1
  61. XZZSK INDEX VALID 92
  62. XZZSK LOB VALID 5
  63. XZZSK SEQUENCE VALID 18
  64. XZZSK TABLE VALID 346
  65. 16 rows selected.
  66. --查询回收站lob对象数量(可选),lob数量不一致排查
  67. select owner,type,count(*) from dba_recyclebin group by owner,type order by owner;
  68. OWNER TYPE COUNT(*)
  69. ------------------------------ ------------------------- ----------
  70. SYXK INDEX 1
  71. SYXK LOB 5
  72. SYXK LOB INDEX 5
  73. SYXK TABLE 10
  74. --数据量统计
  75. ----新增count_rows 函数
  76. CREATE OR REPLACE FUNCTION count_rows (
  77. table_name IN varchar2,
  78. owner IN varchar2 := NULL
  79. )
  80. RETURN number AUTHID current_user
  81. AS
  82. num_rows number;
  83. stmt varchar2(2000);
  84. BEGIN
  85. IF owner IS NULL THEN
  86. stmt := 'select count(*) from "' || table_name || '"';
  87. ELSE
  88. stmt := 'select count(*) from "' || owner || '"."' || table_name || '"';
  89. END IF;
  90. EXECUTE IMMEDIATE stmt INTO num_rows;
  91. RETURN num_rows;
  92. END;
  93. /
  94. ---调用count_rows 函数,统计各种表的记录数
  95. select table_name, count_rows(table_name) nrows from user_tables where tablespace_name='ENTSERVICE'
  96. order by nrows desc;


Oracle 冷备份以及恢复——异机备份恢复 - 腾讯云开发者社区-腾讯云

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/64842
推荐阅读
相关标签
  

闽ICP备14008679号