Locations of visitors to this page

Monday, January 26, 2009

recover open-deleted files with lsof - 用lsof恢复删除文件

recover open-deleted database files of oracle with lsof
用lsof恢复误删除的数据库文件


删除测试数据库所有数据文件
cd /data/oracle/app/oracle/oradata
rm -rf test
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cd
[oracle@DEV-RPT-2 ~]$ cd /data/oracle/app/oracle/oradata
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ rm -rf test
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ ls -ld test
ls: test: No such file or directory
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$

用lsof查询oracle进程打开的文件
ps -ef|grep ora_lgwr_test
lsof -p 19335
[oracle@DEV-RPT-2 ~]$ ps -ef|grep ora_lgwr_test
oracle 19335 1 1 15:19 ? 00:00:00 ora_lgwr_test
oracle 19393 18391 0 15:20 pts/4 00:00:00 grep ora_lgwr_test
[oracle@DEV-RPT-2 ~]$ lsof -p 19335
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
oracle 19335 oracle cwd DIR 8,5 4096 343573 /data/oracle/app/oracle/product/10.2/dbs
oracle 19335 oracle rtd DIR 8,2 4096 2 /
oracle 19335 oracle txt REG 8,5 104920619 4971303 /data/oracle/app/oracle/product/10.2/bin/oracle
oracle 19335 oracle DEL REG 0,6 1409027 /SYSVc24a2604
oracle 19335 oracle mem REG 8,2 4176 1808011 /stub/lib64/libcwait.so
oracle 19335 oracle mem REG 8,5 177809 343723 /data/oracle/app/oracle/product/10.2/lib/libskgxp10.so
oracle 19335 oracle mem REG 8,5 1772385 343663 /data/oracle/app/oracle/product/10.2/lib/libhasgen10.so
oracle 19335 oracle mem REG 8,5 8545 343667 /data/oracle/app/oracle/product/10.2/lib/libskgxn2.so
oracle 19335 oracle mem REG 8,5 681761 343785 /data/oracle/app/oracle/product/10.2/lib/libocr10.so
oracle 19335 oracle mem REG 8,5 691049 343681 /data/oracle/app/oracle/product/10.2/lib/libocrb10.so
oracle 19335 oracle mem REG 8,5 516097 343671 /data/oracle/app/oracle/product/10.2/lib/libocrutl10.so
oracle 19335 oracle mem REG 8,5 11385162 343768 /data/oracle/app/oracle/product/10.2/lib/libjox10.so
oracle 19335 oracle mem REG 8,5 64041 343619 /data/oracle/app/oracle/product/10.2/lib/libclsra10.so
oracle 19335 oracle mem REG 8,5 123345 343740 /data/oracle/app/oracle/product/10.2/lib/libdbcfg10.so
oracle 19335 oracle mem REG 8,5 3796601 343782 /data/oracle/app/oracle/product/10.2/lib/libnnz10.so
oracle 19335 oracle mem REG 8,2 4000 619696 /usr/lib64/libaio.so.1.0.1
oracle 19335 oracle mem REG 8,2 15143 32596 /lib64/libdl-2.3.4.so
oracle 19335 oracle mem REG 8,2 610169 32626 /lib64/tls/libm-2.3.4.so
oracle 19335 oracle mem REG 8,2 103139 32628 /lib64/tls/libpthread-2.3.4.so
oracle 19335 oracle mem REG 8,2 104519 32600 /lib64/libnsl-2.3.4.so
oracle 19335 oracle mem REG 8,2 1488106 32624 /lib64/tls/libc-2.3.4.so
oracle 19335 oracle mem REG 8,2 19112 1018420 /usr/lib64/libnuma.so.1
oracle 19335 oracle mem REG 8,5 1544 343589 /data/oracle/app/oracle/product/10.2/dbs/hc_test.dat
oracle 19335 oracle mem CHR 1,5 2127 /dev/zero
oracle 19335 oracle mem REG 8,2 56902 32606 /lib64/libnss_files-2.3.4.so
oracle 19335 oracle mem REG 8,2 105080 32807 /lib64/ld-2.3.4.so
oracle 19335 oracle 0r CHR 1,3 2126 /dev/null
oracle 19335 oracle 1r CHR 1,3 2126 /dev/null
oracle 19335 oracle 2w REG 8,5 925 801283 /data/oracle/app/oracle/admin/test/bdump/test_lgwr_19335.trc
oracle 19335 oracle 3r CHR 1,3 2126 /dev/null
oracle 19335 oracle 4r CHR 1,3 2126 /dev/null
oracle 19335 oracle 5w REG 8,5 658 801276 /data/oracle/app/oracle/admin/test/udump/test_ora_19324.trc
oracle 19335 oracle 6w REG 8,5 643706 801272 /data/oracle/app/oracle/admin/test/bdump/alert_test.log
oracle 19335 oracle 7u REG 8,5 0 343693 /data/oracle/app/oracle/product/10.2/dbs/lkinsttest (deleted)
oracle 19335 oracle 8w REG 8,5 643706 801272 /data/oracle/app/oracle/admin/test/bdump/alert_test.log
oracle 19335 oracle 9u REG 8,5 1544 343589 /data/oracle/app/oracle/product/10.2/dbs/hc_test.dat
oracle 19335 oracle 10r CHR 1,5 2127 /dev/zero
oracle 19335 oracle 11r CHR 1,5 2127 /dev/zero
oracle 19335 oracle 12r REG 8,5 849408 4971267 /data/oracle/app/oracle/product/10.2/rdbms/mesg/oraus.msb
oracle 19335 oracle 13u REG 8,5 1544 343589 /data/oracle/app/oracle/product/10.2/dbs/hc_test.dat
oracle 19335 oracle 14uR REG 8,5 24 343583 /data/oracle/app/oracle/product/10.2/dbs/lkTEST
oracle 19335 oracle 15u REG 8,5 9093120 1210419 /data/oracle/app/oracle/oradata/test/control01.ctl (deleted)
oracle 19335 oracle 16u REG 8,5 9093120 1210050 /data/oracle/app/oracle/oradata/test/control02.ctl (deleted)
oracle 19335 oracle 17u REG 8,5 9093120 1210051 /data/oracle/app/oracle/oradata/test/control03.ctl (deleted)
oracle 19335 oracle 18u REG 8,5 104858112 1210052 /data/oracle/app/oracle/oradata/test/redo01.rdo (deleted)
oracle 19335 oracle 19u REG 8,5 104858112 1210053 /data/oracle/app/oracle/oradata/test/redo01b.rdo (deleted)
oracle 19335 oracle 20u REG 8,5 104858112 1210054 /data/oracle/app/oracle/oradata/test/redo02.rdo (deleted)
oracle 19335 oracle 21u REG 8,5 104858112 1210055 /data/oracle/app/oracle/oradata/test/redo02b.rdo (deleted)
oracle 19335 oracle 22u REG 8,5 104858112 1210056 /data/oracle/app/oracle/oradata/test/redo03.rdo (deleted)
oracle 19335 oracle 23u REG 8,5 104858112 1210057 /data/oracle/app/oracle/oradata/test/redo03b.rdo (deleted)
oracle 19335 oracle 24u REG 8,5 314580992 1210059 /data/oracle/app/oracle/oradata/test/system01.dbf (deleted)
oracle 19335 oracle 25u REG 8,5 209723392 1210063 /data/oracle/app/oracle/oradata/test/undotbs01.dbf (deleted)
oracle 19335 oracle 26u REG 8,5 146808832 1210058 /data/oracle/app/oracle/oradata/test/sysaux01.dbf (deleted)
oracle 19335 oracle 27u REG 8,5 5251072 1210064 /data/oracle/app/oracle/oradata/test/users01.dbf (deleted)
oracle 19335 oracle 28u REG 8,5 10493952 1210062 /data/oracle/app/oracle/oradata/test/ts_test01.dbf (deleted)
oracle 19335 oracle 29u REG 8,5 20979712 1210060 /data/oracle/app/oracle/oradata/test/temp01.dbf (deleted)
oracle 19335 oracle 30u REG 8,5 10493952 1210061 /data/oracle/app/oracle/oradata/test/ts_temp01.dbf (deleted)
oracle 19335 oracle 31r REG 8,5 849408 4971267 /data/oracle/app/oracle/product/10.2/rdbms/mesg/oraus.msb
[oracle@DEV-RPT-2 ~]$
控制文件(.ctl),数据文件(.dbf),重做日志文件(.rdo)显示为已被删除(deleted)
打开文件顺序是控制文件, 重做日志文件, 系统表空间文件, 撤销表空间文件, 系统辅助表空间文件, 其它表空间文件, 临时表空间文件


用进程伪文件系统(/proc)恢复被删除的文件
mkdir -p /data/oracle/app/oracle/oradata/test.recv
cat /proc/19335/fd/15 >/data/oracle/app/oracle/oradata/test.recv/control01.ctl
cat /proc/19335/fd/16 >/data/oracle/app/oracle/oradata/test.recv/control02.ctl
cat /proc/19335/fd/17 >/data/oracle/app/oracle/oradata/test.recv/control03.ctl
cat /proc/19335/fd/18 >/data/oracle/app/oracle/oradata/test.recv/redo01.rdo
cat /proc/19335/fd/19 >/data/oracle/app/oracle/oradata/test.recv/redo01b.rdo
cat /proc/19335/fd/20 >/data/oracle/app/oracle/oradata/test.recv/redo02.rdo
cat /proc/19335/fd/21 >/data/oracle/app/oracle/oradata/test.recv/redo02b.rdo
cat /proc/19335/fd/22 >/data/oracle/app/oracle/oradata/test.recv/redo03.rdo
cat /proc/19335/fd/23 >/data/oracle/app/oracle/oradata/test.recv/redo03b.rdo
cat /proc/19335/fd/24 >/data/oracle/app/oracle/oradata/test.recv/system01.dbf
cat /proc/19335/fd/25 >/data/oracle/app/oracle/oradata/test.recv/undotbs01.dbf
cat /proc/19335/fd/26 >/data/oracle/app/oracle/oradata/test.recv/sysaux01.dbf
cat /proc/19335/fd/27 >/data/oracle/app/oracle/oradata/test.recv/users01.dbf
cat /proc/19335/fd/28 >/data/oracle/app/oracle/oradata/test.recv/ts_test01.dbf
cat /proc/19335/fd/29 >/data/oracle/app/oracle/oradata/test.recv/temp01.dbf
cat /proc/19335/fd/30 >/data/oracle/app/oracle/oradata/test.recv/ts_temp01.dbf
ls -l /data/oracle/app/oracle/oradata/test.recv/
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ mkdir -p /data/oracle/app/oracle/oradata/test.recv
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/15 >/data/oracle/app/oracle/oradata/test.recv/control01.ctl
cat /proc/17990/fd/16 >/data/oracle/app/oracle/oradata/test.recv/control02.ctl
cat /proc/17990/fd/17 >/data/oracle/app/oracle/oradata/test.recv/control03.ctl
cat /proc/17990/fd/18 >/data/oracle/app/oracle/oradata/test.recv/redo01.rdo
cat /proc/17990/fd/19 >/data/oracle/app/oracle/oradata/test.recv/redo01b.rdo
cat /proc/17990/fd/20 >/data/oracle/app/oracle/oradata/test.recv/redo02.rdo
cat /proc/17990/fd/21 >/data/oracle/app/oracle/oradata/test.recv/redo02b.rdo
cat /proc/17990/fd/22 >/data/oracle/app/oracle/oradata/test.recv/redo03.rdo
cat /proc/17990/fd/23 >/data/oracle/app/oracle/oradata/test.recv/redo03b.rdo
cat /proc/17990/fd/24 >/data/oracle/app/oracle/oradata/test.recv/system01.dbf
cat /proc/17990/fd/25 >/data/oracle/app/oracle/oradata/test.recv/undotbs01.dbf
cat /proc/17990/fd/26 >/data/oracle/app/oracle/oradata/test.recv/sysaux01.dbf
cat /proc/17990/fd/27 >/data/oracle/app/oracle/oradata/test.recv/users01.dbf
cat /proc/17990/fd/28 >/data/oracle/app/oracle/oradata/test.recv/ts_test01.dbf
cat /proc/17990/fd/29 >/data/oracle/app/oracle/oradata/test.recv/temp01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/16 >/data/oracle/app/oracle/oradata/test.recv/control02.ctl
cat /proc/17990/fd/30 >/data/oracle/app/oracle/oradata/test.recv/ts_temp01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/17 >/data/oracle/app/oracle/oradata/test.recv/control03.ctl
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/18 >/data/oracle/app/oracle/oradata/test.recv/redo01.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/19 >/data/oracle/app/oracle/oradata/test.recv/redo01b.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/20 >/data/oracle/app/oracle/oradata/test.recv/redo02.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/21 >/data/oracle/app/oracle/oradata/test.recv/redo02b.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/22 >/data/oracle/app/oracle/oradata/test.recv/redo03.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/23 >/data/oracle/app/oracle/oradata/test.recv/redo03b.rdo
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/24 >/data/oracle/app/oracle/oradata/test.recv/system01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/25 >/data/oracle/app/oracle/oradata/test.recv/undotbs01.dbf
cat: /proc/17990/fd/25: No such file or directory
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/26 >/data/oracle/app/oracle/oradata/test.recv/sysaux01.dbf
cat: /proc/17990/fd/26: No such file or directory
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/27 >/data/oracle/app/oracle/oradata/test.recv/users01.dbf
cat: /proc/17990/fd/27: No such file or directory
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/28 >/data/oracle/app/oracle/oradata/test.recv/ts_test01.dbf
cat: /proc/17990/fd/28: No such file or directory
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/29 >/data/oracle/app/oracle/oradata/test.recv/temp01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cat /proc/17990/fd/30 >/data/oracle/app/oracle/oradata/test.recv/ts_temp01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ ls -l /data/oracle/app/oracle/oradata/test.recv/
total 1343952
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control01.ctl
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control02.ctl
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control03.ctl
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo01b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo01.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo02b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo02.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo03b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo03.rdo
-rw-r--r-- 1 oracle oinstall 146808832 Jan 25 15:23 sysaux01.dbf
-rw-r--r-- 1 oracle oinstall 314580992 Jan 25 15:23 system01.dbf
-rw-r--r-- 1 oracle oinstall 20979712 Jan 25 15:23 temp01.dbf
-rw-r--r-- 1 oracle oinstall 10493952 Jan 25 15:23 ts_temp01.dbf
-rw-r--r-- 1 oracle oinstall 10493952 Jan 25 15:23 ts_test01.dbf
-rw-r--r-- 1 oracle oinstall 209723392 Jan 25 15:23 undotbs01.dbf
-rw-r--r-- 1 oracle oinstall 5251072 Jan 25 15:23 users01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$

关闭数据库
conn / as sysdba
shutdown abort
SQL> conn / as sysdba
Connected.
SQL> shutdown abort
ORACLE instance shut down.
SQL>

恢复文件到原来的目录
cd /data/oracle/app/oracle/oradata
rsync -av test.recv/ test/
ls -l test/
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ cd /data/oracle/app/oracle/oradata
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ rsync -av test.recv/ test/
building file list ... done
created directory test
./
control01.ctl
control02.ctl
control03.ctl
redo01.rdo
redo01b.rdo
redo02.rdo
redo02b.rdo
redo03.rdo
redo03b.rdo
sysaux01.dbf
system01.dbf
temp01.dbf
ts_temp01.dbf
ts_test01.dbf
undotbs01.dbf
users01.dbf

sent 1374928843 bytes received 340 bytes 211527566.62 bytes/sec
total size is 1374759936 speedup is 1.00
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$ ls -l test/
total 1343952
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control01.ctl
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control02.ctl
-rw-r--r-- 1 oracle oinstall 9093120 Jan 25 15:22 control03.ctl
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo01b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo01.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo02b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo02.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo03b.rdo
-rw-r--r-- 1 oracle oinstall 104858112 Jan 25 15:23 redo03.rdo
-rw-r--r-- 1 oracle oinstall 146808832 Jan 25 15:23 sysaux01.dbf
-rw-r--r-- 1 oracle oinstall 314580992 Jan 25 15:23 system01.dbf
-rw-r--r-- 1 oracle oinstall 20979712 Jan 25 15:23 temp01.dbf
-rw-r--r-- 1 oracle oinstall 10493952 Jan 25 15:23 ts_temp01.dbf
-rw-r--r-- 1 oracle oinstall 10493952 Jan 25 15:23 ts_test01.dbf
-rw-r--r-- 1 oracle oinstall 209723392 Jan 25 15:23 undotbs01.dbf
-rw-r--r-- 1 oracle oinstall 5251072 Jan 25 15:23 users01.dbf
[oracle@DEV-RPT-2 /data/oracle/app/oracle/oradata]$

启数据库
conn / as sysdba
startup
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory
SQL>
SQL> !mkdir /data/oracle/app/oracle/oradata/test/flash_recovery_area

SQL> !mkdir /data/oracle/app/oracle/oradata/test/archive

SQL> !mkdir /data/oracle/app/oracle/oradata/test/utlfile

SQL> startup
ORACLE instance started.

Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 188744952 bytes
Database Buffers 117440512 bytes
Redo Buffers 6303744 bytes
Database mounted.
Database opened.
SQL>


一些问题:
1.
如果文件存放在netapp上, 被删除后文件名将变成.nfs0000000加一串数字, 比如
[oracle@DEV24-DB-1 /u01/dev24_db_1/DEV24-DB-1/oracle/app/oracle/oradata/s10]$ ls -la
total 14243836
drwxr-x--- 2 oracle oinstall 4096 Jan 24 22:55 .
drwxr-xr-x 4 oracle oinstall 4096 Jan 24 22:55 ..
-rw-r----- 1 oracle oinstall 10633216 Jan 25 00:55 .nfs0000000000022a2200000001
-rw-r----- 1 oracle oinstall 10633216 Jan 25 00:55 .nfs0000000000022a2300000002
-rw-r----- 1 oracle oinstall 10633216 Jan 25 00:55 .nfs0000000000022a2400000003
-rw-r----- 1 oracle oinstall 419438592 Jan 24 23:59 .nfs0000000000022a2500000004
-rw-r----- 1 oracle oinstall 52436992 Jan 24 23:59 .nfs0000000000022a2600000005
-rw-r----- 1 oracle oinstall 52436992 Jan 24 23:59 .nfs0000000000022a2700000006
-rw-r----- 1 oracle oinstall 199237632 Jan 25 00:44 .nfs0000000000022a2800000007
-rw-r----- 1 oracle oinstall 314580992 Jan 25 00:54 .nfs0000000000022a2900000008
-rw-r----- 1 oracle oinstall 109060096 Jan 24 06:00 .nfs0000000000022a2a00000009
-rw-r----- 1 oracle oinstall 5489303552 Jan 25 00:55 .nfs0000000000022a2b0000000a
-rw-r----- 1 oracle oinstall 5251072 Jan 24 23:59 .nfs0000000000022a2c0000000b
-rw-r----- 1 oracle oinstall 20979712 Jan 24 23:59 .nfs0000000000022a2d0000000c
-rw-r----- 1 oracle oinstall 20979712 Jan 24 23:59 .nfs0000000000022a2e0000000d
-rw-r----- 1 oracle oinstall 104858112 Jan 24 23:54 .nfs0000000000022a320000000e
-rw-r----- 1 oracle oinstall 104858112 Jan 25 00:55 .nfs0000000000022a330000000f
-rw-r----- 1 oracle oinstall 104858112 Jan 24 23:24 .nfs00000000000554d600000010
-rw-r----- 1 oracle oinstall 5358231552 Jan 25 00:54 .nfs00000000000554d800000011
-rw-r----- 1 oracle oinstall 1908416512 Jan 25 00:53 .nfs00000000000554d900000012
-rw-r----- 1 oracle oinstall 209723392 Jan 24 23:59 .nfs00000000000554dd00000013
-rw-r----- 1 oracle oinstall 52436992 Jan 24 23:59 .nfs00000000000554de00000014
可以按文件大小, 文件描述符序号, 查看数据字典,数据文件内容等, 得出文件名

2.
打开数据库报错ora-1251, 说明文件名不对, 需要修正
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/home/oracle/app/oracle/oradata/s10/xiewen_data01.dbf'
ORA-01251: Unknown File Header Version read for file number 6


SQL>

oerr ora 1251
01251, 00000, "Unknown File Header Version read for file number %s"
// *Cause: Read of the file header returned a record but its version cannot
// be identified. Either the header has been corrupted, or the file
// is not a valid database file.
// *Action: Have the operating system make the correct file available to
// the database, or recover the file.

3.
打开数据库报错 ora-600 kcratr1_lastbwr
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [kcratr1_lastbwr], [], [], [], [],
[], [], []


SQL>

参考 ORA-00600:[Kcratr1_lastbwr] During Database Startup after a Crash
手工恢复即可
SQL> recover database;
Media recovery complete.
SQL> alter database open;

Database altered.

SQL>




-fin-

Sunday, January 25, 2009

ORA-600 kdsgrp1

ORA-600 kdsgrp1

修复数据库后, 告警日志报错
Errors in file /home/oracle/app/oracle/admin/s10/udump/s10_ora_23209.trc:
ORA-00600: internal error code, arguments: [kdsgrp1], [], [], [], [], [], [], []


跟踪文件显示:
*** SESSION ID:(1620.1) 2009-01-25 02:21:07.036
row 0281ec7f.4a continuation at
file# 10 block# 126079 slot 75 not found
**************************************************
KDSTABN_GET: 0 ..... ntab: 1
curSlot: 75 ..... nrows: 74
**************************************************
*** 2009-01-25 02:21:07.043
ksedmp: internal or fatal error
ORA-00600: internal error code, arguments: [kdsgrp1], [], [], [], [], [], [], []
Current SQL statement for this session:
SELECT ID, LOCAL_UID, BYTES_ID, CHECKSUM, MIME_TYPE, PHYSICAL_CONTENT_ID, ASSET_TYPE, SOURCE_URL FROM ASSET WHERE LOCAL_UID =
(SELECT LOCAL_UID FROM DP_FEED_IMAGE WHERE FEED_IMAGE_ID=:1 AND SOURCE_URL IS NOT NULL)
----- Call Stack Trace -----
calling call entry argument values in hex
location type point (? means dubious value)
-------------------- -------- -------------------- ----------------------------
ksedst()+31 call ksedst1() 000000000 ? 000000001 ?
7FFF96BEC710 ? 7FFF96BEC770 ?
7FFF96BEC6B0 ? 000000000 ?
ksedmp()+610 call ksedst() 000000000 ? 000000001 ?
7FFF96BEC710 ? 7FFF96BEC770 ?
7FFF96BEC6B0 ? 000000000 ?
ksfdmp()+21 call ksedmp() 000000003 ? 000000001 ?
7FFF96BEC710 ? 7FFF96BEC770 ?
7FFF96BEC6B0 ? 000000000 ?
kgerinv()+161 call ksfdmp() 000000003 ? 000000001 ?
7FFF96BEC710 ? 7FFF96BEC770 ?
7FFF96BEC6B0 ? 000000000 ?
kgeasnmierr()+163 call kgerinv() 006217D40 ? 01B5B28B0 ?
7FFF96BEC770 ? 7FFF96BEC6B0 ?
000000000 ? 000000000 ?
kdsgrp()+764 call kgeasnmierr() 006217D40 ? 01B5B28B0 ?
7FFF96BEC770 ? 7FFF96BEC6B0 ?
000000000 ? 000000001 ?
kdsfbr()+228 call kdsgrp() 000000000 ? 000000000 ?
2B2815CA49B0 ? 7FFF96BEC6B0 ?
000000000 ? 000000001 ?
qertbFetchByRowID() call kdsfbr() 2B2815CA49B0 ? 00000004B ?
+895 000000000 ? 000000001 ?
000000000 ? 0000000FD ?
subsr1()+515 call qertbFetchByRowID() 066C88320 ? 000000000 ?
000000000 ? 000000001 ?
000000000 ? 0000000FD ?
evaopn2()+4067 call subsr1() 066C88010 ? 000000000 ?
000000000 ? 000000001 ?
000000000 ? 0000000FD ?
qerixTunnelGetKey() call evaopn2() 066C87F20 ? 2B2815CA4BB8 ?
+1030 000000000 ? 000000001 ?
2B2815CBF9C0 ? 0000000FD ?
qerixStart()+1293 call qerixTunnelGetKey() 066C87F20 ? 2B2815CA4BB8 ?
000000000 ? 000000001 ?
2B2815CBF9C0 ? 066C87F20 ?
qertbStart()+956 call qerixStart() 066C87AA0 ? 2B2815CA4BB8 ?
2B2815CAF000 ? 000000001 ?
2B2815CBF9C0 ? 066C87F20 ?
selexe()+667 call qertbStart() 066C878A8 ? 000000001 ?
2B2815CAF000 ? 2B2815CAF468 ?
000000000 ? 066C87F20 ?
opiexe()+4671 call selexe() 066C8BE28 ? 7FFF96BEEBA8 ?
7FFF96BEEBA8 ? 066C8BE28 ?
000000000 ? 066C87F20 ?
kpoal8()+2273 call opiexe() 000000049 ? 000000003 ?
7FFF96BEF070 ? 00000000E ?
000000000 ? 066C87F20 ?
opiodr()+984 call kpoal8() 00000005E ? 000000017 ?
7FFF96BF1F50 ? 00000000E ?
000000001 ? 066C87F20 ?
ttcpip()+1012 call opiodr() 00000005E ? 000000017 ?
7FFF96BF1F50 ? 00000000E ?
005444950 ? 066C87F20 ?
opitsk()+1322 call ttcpip() 00621FA10 ? 7FFF96BEFF38 ?
7FFF96BF1F50 ? 000000000 ?
7FFF96BF1A48 ? 7FFF96BF20B8 ?
opiino()+1026 call opitsk() 000000003 ? 000000000 ?
7FFF96BF1F50 ? 000000001 ?
000000000 ? 48E082200000001 ?
opiodr()+984 call opiino() 00000003C ? 000000004 ?
7FFF96BF3118 ? 000000000 ?
000000000 ? 48E082200000001 ?
opidrv()+547 call opiodr() 00000003C ? 000000004 ?
7FFF96BF3118 ? 000000000 ?
005444400 ? 48E082200000001 ?
sou2o()+114 call opidrv() 00000003C ? 000000004 ?
7FFF96BF3118 ? 000000000 ?
005444400 ? 48E082200000001 ?
opimai_real()+163 call sou2o() 7FFF96BF30F0 ? 00000003C ?
000000004 ? 7FFF96BF3118 ?
005444400 ? 48E082200000001 ?
main()+116 call opimai_real() 000000002 ? 7FFF96BF3180 ?
000000004 ? 7FFF96BF3118 ?
005444400 ? 48E082200000001 ?
__libc_start_main() call main() 000000002 ? 7FFF96BF3180 ?
+244 000000004 ? 7FFF96BF3118 ?
005444400 ? 48E082200000001 ?
_start()+41 call __libc_start_main() 0006E8898 ? 000000002 ?
7FFF96BF32D8 ? 000000000 ?
005444400 ? 000000002 ?

--------------------- Binary Stack Dump ---------------------
...


可能是因为表和索引数据不一致造成的

检验表结构
set time on timing on
analyze table s3test.asset validate structure cascade;
analyze table s3test.dp_feed_image validate structure cascade;
12:22:38 SQL> set time on timing on
12:22:44 SQL> analyze table s3test.asset validate structure cascade;

Table analyzed.

Elapsed: 00:16:52.28
12:39:37 SQL>
13:00:57 SQL> analyze table s3test.dp_feed_image validate structure cascade;
analyze table s3test.dp_feed_image validate structure cascade
*
ERROR at line 1:
ORA-01499: table/index cross reference failure - see trace file


Elapsed: 00:05:44.41
13:09:11 SQL>


跟踪文件显示
Table/Index row count mismatch
table 1022161 : index 1022167, 0
Index root = tsn: 11 rdba: 0x02c0dd0c


查询是哪个索引坏了
col segment_name for a30
select owner, segment_name, segment_type
from dba_segments
where header_file = dbms_utility.data_block_address_file(to_number('02c0dd0c','xxxxxxxxx'))
and header_block = dbms_utility.data_block_address_block(to_number('02c0dd0c','xxxxxxxxx'));
SQL> col segment_name for a30
SQL> select owner, segment_name, segment_type
from dba_segments
where header_file = dbms_utility.data_block_address_file(to_number('02c0dd0c','xxxxxxxxx'))
and header_block = dbms_utility.data_block_address_block(to_number('02c0dd0c','xxxxxxxxx'));
2 3 4
OWNER SEGMENT_NAME SEGMENT_TYPE
------------------------------ ------------------------------ ------------------
S3TEST DP_FC_LOCAL_UID INDEX

SQL>


重建索引
set time on timing on
alter index s3test.dp_fc_local_uid rebuild online;
SQL> set time on timing on
13:35:45 SQL> alter index s3test.dp_fc_local_uid rebuild online;

Index altered.

Elapsed: 00:00:18.17
13:36:07 SQL>


问题解决
analyze table s3test.dp_feed_image validate structure cascade;
13:36:23 SQL> analyze table s3test.dp_feed_image validate structure cascade;

Table analyzed.

Elapsed: 00:06:50.82
13:43:15 SQL>


外部链接:
ORA-600 [kdsgrp1]
ORA-1499. Table/Index row count mismatch




-fin-

Friday, January 23, 2009

ORA-600 Kkqsprepforeventprocessing

告警日志报错
Errors in file /home/oracle/app/oracle/admin/s10/bdump/s10_j000_23220.trc:
ORA-00600: internal error code, arguments: [kkqsPrepForEventProcessing:1], [], [], [], [], [], [], []
ORA-06512: at "SYS.DBMS_STATS", line 13591
ORA-06512: at "SYS.DBMS_STATS", line 13937
ORA-06512: at "SYS.DBMS_STATS", line 14015
ORA-06512: at "SYS.DBMS_STATS", line 13974
ORA-06512: at "S3AUTO1.GATHERSTATISTICS", line 4
ORA-06512: at line 1



跟踪文件显示
ksedmp: internal or fatal error
ORA-00600: internal error code, arguments: [kkqsPrepForEventProcessing:1], [], [], [], [], [], [], []
Current SQL statement for this session:
select substrb(dump(val,16,0,32),1,120) ep, cnt from (select /*+ no_parallel(t) no_parallel_index(t) dbms_stats cursor_sharing_exact use_weak_name_resl dynamic_sampling(0) no_monitoring */"IS_FULFILLED" val,count(*) cnt from "S3AUTO1"."DOWNLOAD_RIGHTS" t where "IS_FULFILLED" is not null group by "IS_FULFILLED") order by val
----- PL/SQL Call Stack -----
object line object
handle number name
0x68cc9fd8 11286 package body SYS.DBMS_STATS
0x68cc9fd8 11841 package body SYS.DBMS_STATS
0x68cc9fd8 12475 package body SYS.DBMS_STATS
0x68cc9fd8 12892 package body SYS.DBMS_STATS
0x68cc9fd8 13345 package body SYS.DBMS_STATS
0x68cc9fd8 13546 package body SYS.DBMS_STATS
0x68cc9fd8 13937 package body SYS.DBMS_STATS
0x68cc9fd8 14015 package body SYS.DBMS_STATS
0x68cc9fd8 13974 package body SYS.DBMS_STATS
0x68dd0318 4 procedure S3AUTO1.GATHERSTATISTICS
0x68e36f28 1 anonymous block
----- Call Stack Trace -----
calling call entry argument values in hex
location type point (? means dubious value)
-------------------- -------- -------------------- ----------------------------
ksedst()+31 call ksedst1() 000000000 ? 000000001 ?
7FFFE94DA1D0 ? 7FFFE94DA230 ?
7FFFE94DA170 ? 000000000 ?
ksedmp()+610 call ksedst() 000000000 ? 000000001 ?
7FFFE94DA1D0 ? 7FFFE94DA230 ?
7FFFE94DA170 ? 000000000 ?
ksfdmp()+21 call ksedmp() 000000003 ? 000000001 ?
7FFFE94DA1D0 ? 7FFFE94DA230 ?
7FFFE94DA170 ? 000000000 ?
kgerinv()+161 call ksfdmp() 000000003 ? 000000001 ?
7FFFE94DA1D0 ? 7FFFE94DA230 ?
7FFFE94DA170 ? 000000000 ?
kgeasnmierr()+163 call kgerinv() 006217D40 ? 00D054780 ?
7FFFE94DA230 ? 7FFFE94DA170 ?
000000000 ? 000000000 ?
kkqsPrepForEventPro call kgeasnmierr() 006217D40 ? 00D054780 ?
cessing()+500 7FFFE94DA230 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsProcessNextEven call kkqsPrepForEventPro 2AF1C39495B0 ? 00D054780 ?
tLevel()+128 cessing() 7FFFE94DA230 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsNDimEventTrans( call kkqsProcessNextEven 2AF1C39493A8 ? 00D054780 ?
)+53 tLevel() 7FFFE94DA230 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsEVTransition()+ call kkqsNDimEventTrans( 2AF1C39493A8 ? 2AF1C3949B70 ?
276 ) 7FFFE94DA230 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsDoStopTransitio call kkqsEVTransition() 2AF1C39493A8 ? 2AF1C3949B70 ?
n()+190 2AF1C3949B70 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsEventWalk()+327 call kkqsDoStopTransitio 2AF1C39493A8 ? 2AF1C39492E0 ?
n() 2AF1C3949B70 ? 7FFFE94DA170 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
kkqsEventWalk()+558 call kkqsEventWalk() 2AF1C39493A8 ? 2AF1C39492E0 ?
2AF1C3949148 ? 000000000 ?
7FFFE94DB000 ? 7FFFE94DB010 ?
...


这是一个BUG, 还没有linux版本补丁, 解决办法是:
alter system set "_mmv_query_rewrite_enabled"=FALSE;


外部链接:
Ora-00600: Internal Error Code, Arguments: [Kkqsprepforeventprocessing:1], [],
Bug 6001239 - OERI[kkqsPrepForEventProcessing:1] during query rewrite
XF11.1GSTAT - TRC - KKQSPREPFOREVENTPROCESSING



-fin-

Thursday, January 22, 2009

sudo examples

配置sudo限制用户ssh自动登录服务器的例子

1.ssh认证密钥放在s3op用户下
私钥加密
其它服务器root用户下配好认证公钥 authorized_keys
启动ssh-agent代理
过程略


2.配置sudo限制登录服务器
s3op1用户可以登录qa-app-1,dev-app-?
oracle用户可以登录任何机器

运行visudo命令编辑sudo配置,保存退出
visudo
[root@MGT tmp]# visudo
[root@MGT tmp]# cat /etc/sudoers
Defaults logfile = /var/log/sudo.log
User_Alias ORACLE = oracle
User_Alias S3OP1 = s3op1
Runas_Alias S3OP = s3op
Cmnd_Alias SSH_QA_APP_1 = /usr/bin/ssh qa-app-1 *
Cmnd_Alias SSH_DEV_APP = /usr/bin/ssh dev-app-? *
Cmnd_Alias SSH_APP = SSH_QA_APP_1,SSH_DEV_APP
Cmnd_Alias SSH = /usr/bin/ssh
root ALL=(ALL) ALL
S3OP1 ALL = (S3OP) NOPASSWD: SSH_APP
ORACLE ALL = (S3OP) NOPASSWD: SSH
[root@MGT tmp]#
解释略


3.
s3op1用户设置SSH_AUTH_SOCK环境变量
[s3op1@MGT ~]$ SSH_AUTH_SOCK=/tmp/ssh-KGbqxg6150/agent.6150; export SSH_AUTH_SOCK;
[s3op1@MGT ~]$

运行sudo 以root登录qa-app-1
sudo -u s3op /usr/bin/ssh qa-app-1 -x -l root "hostname;whoami"
[s3op1@MGT ~]$ sudo -u s3op /usr/bin/ssh qa-app-1 -x -l root "hostname;whoami"
QA-app-1
root
[s3op1@MGT ~]$
[oracle@MGT ~]$

也能登录dev-app-?等服务器
sudo -u s3op ssh dev-app-1 -x -l root "hostname;whoami"
sudo -u s3op ssh dev-app-2 -x -l root "hostname;whoami"
[s3op1@MGT ~]$ sudo -u s3op ssh dev-app-1 -x -l root "hostname;whoami"
DEV-app-1
root
[s3op1@MGT ~]$ sudo -u s3op ssh dev-app-2 -x -l root "hostname;whoami"
DEV-app-2
root
[s3op1@MGT ~]$

不允许登录qa-app-2
sudo -u s3op ssh qa-app-2 -x
[s3op1@MGT ~]$ sudo -u s3op ssh qa-app-2 -x
Password:
这里输入当前用户s3op1的密码, 然后显示
Sorry, user s3op1 is not allowed to execute '/usr/bin/ssh qa-app-2 -x' as s3op on MGT.s3lab.mot.com.
[s3op1@MGT ~]$

ssh命令是按通配符匹配的,格式必须像"/usr/bin/ssh qa-app-2 *"这样, 所以最后至少要有个参数, 如果没有也不能登录
sudo -u s3op ssh dev-app-1
[s3op1@MGT ~]$ sudo -u s3op ssh dev-app-1
Sorry, user s3op1 is not allowed to execute '/usr/bin/ssh dev-app-1' as s3op on MGT.s3lab.mot.com.
[s3op1@MGT ~]$

随便加个参数, 改成
sudo -u s3op ssh dev-app-1 --
[s3op1@MGT ~]$ sudo -u s3op ssh dev-app-1 --
Password:
Last login: Thu Jan 22 08:46:55 2009 from mgt.s3lab.mot.com
Could not chdir to home directory /data/s3op: No such file or directory
-bash-3.00$
能登了
dev-app-1上的用户s3op没有自动认证, 需要输入密码

用sudo能实现限制用户登录, 但是不好用


4.oracle用户运行sudo
被允许运行ssh命令, 后面参数不限, 所以可以登录任何机器

sudo -u s3op ssh root@dev-app-1 "date"
[oracle@MGT ~]$ sudo -u s3op ssh root@dev-app-1 "date"
Thu Jan 22 08:52:11 GMT 2009
[oracle@MGT ~]$

sudo -u s3op ssh root@dev-blur-db-1 "date"
[oracle@MGT ~]$ sudo -u s3op ssh root@dev-blur-db-1 "date"
Thu Jan 22 08:52:33 GMT 2009
[oracle@MGT ~]$


5.
首次运行sudo, 会显示提示信息(lecture)
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these two things:

#1) Respect the privacy of others.
#2) Think before you type.


We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

可以在配置文件中修改这个属性



-fin-

Wednesday, January 14, 2009

how to recover SecureCRT saved session password - 恢复SecureCRT保存的密码

如何恢复SecureCRT保存的密码

很老很土却很有效的办法,现公之于众,好危险哟。幸好我根本不用盗版软件啊


登录密码保存在CRT的session配置文件中,不过是加密保存的,看不懂
也不知道它的加密算法,没法解密. 所以如果能让CRT自己显示出来就好了

首先修改要登录的主机的IP地址,改成另外一台机器, 这台的登录密码要跟原来机器的不一样
然后连接,这时因为登录密码错误,会弹出一个窗口,显示了用户名和密码,密码是用一串星号表示的
随便下一个星号密码查看软件,查看一下就行了
我找了两个,应该都能用
侠客密码查看器
Asterisk Logger





-fin-

Saturday, January 10, 2009

1z0-043 lesson 5 Database Recovery

做错好多

是否显示我的答案
是否显示书上的答案和我的注释


1.
3、One of the tablespaces is read-only in your database. The loss of all control files forced you to re-create the control file. Which operation do you need to perform after re-creating the control file and opening the database?
A. drop and re-create the read-only tablespaces
B. rename the read-only data files to their correct file names
C. change the tablespace status from read/write to read-only
D. re-create the read-only tablespace because it is automatically removed
B
B
教材5-35


2.
8、You are using Oracle Database 10g. Which statement regarding an incomplete recovery is true?
A. You do not need to restore all the data files.
B. You do not need to open the database with the RESETLOGS operation.
C. You do not need to perform a full backup after the RESETLOGS operation.
D. You do not need to recover all the data files to the same system change number (SCN).
D 猜的
C

C:pdf教材8-33
D:教材5-20, 可是只读表空间的scn不就不一样了吗


3.
11、Your database is open and running in ARCHIVELOGmode. You take RMAN full backups every Sunday night. On Monday morning, while querying the user1.employeestable, you receive the following error message:
01578: ORACLE data block corrupted (file # 5, block # 51)
ORA-01110: data file 5:'/u01/app/oracle/oradata/orcl/example01.dbf'
You need to rectify the corruption while ensuring the following:
The data file should remain online.
The mean time to recover (MTTR) should be minimal.
You are not using a backup control file and all the archived logs are accessible.
Which option would you choose?
A. flash back the corrupted blocks
B. use the DBMS_REPAIR package
C. use the RMAN TSPITR command
D. use the RMAN BLOCKRECOVER command
E. use the RESTORE DATABASE and RECOVER DATABASE commands
F. investigate the time at which the corruption occurred and perform a point-in-time recovery
D 猜的
D
这是第7课的内容呀


4.
17. The current time is 12:00 noon. You want to recover the USERS tablespace from a failure that occurred at 11:50 a.m. You discover that the only member of an unarchived redo log group containing information from 11:40 a.m. onwards is corrupt. With reference to this scenario, if you are not using Recovery Manager (RMAN), which recovery method would you use?
A. time-based recovery
B. log sequence recovery
C. cancel-based recovery
D. change-based recovery
A
C

A.不能确定具体时间
B.RMAN才能用这种方式 教材5-13
C.教材5-12


5.
18. You lost the PRODSTD tablespace, which was read/write. The tablespace was read-only when the last backup was performed. How would you recover the tablespace?
A. restore the tablespace from the backup; there is no need to apply the redo information
B. restore the full database to recover the data up to the point when you performed the backup
C. restore the tablespace from the backup and then perform a recovery using the backup control file
D. restore the tablespace from the backup and then recover the tablespace; all the redo information from the point when the tablespace was made read/write is applied
C
D
教材5-33


6.
21. Your database operates in ARCHIVELOG mode. User-managed consistent backups are performed every Sunday night. On Tuesday, client A drops a table at 8:00 a.m. as follows:
SQL> DROP TABLE cust_ord PURGE;
Table dropped.
Client B executes a query at 9:00 a.m. on the same table as follows:
SQL> SELECT * FROM cust_ord;
SELECT * FROM cust_ord
*ERROR at line 1:ORA-00942: table or view does not exist
Client B needs the dropped table and reports the problem to you. With reference to this scenario, which action should you take?
A. retrieve the table by using the flashback feature
B. restore all the data files from last Sunday's backup and then perform a time-based recovery
C. restore all the data files from last Sunday's backup and then perform a log sequence recovery
D. restore all the data files from last Sunday's backup and then perform a cancel-based recovery
E. restore from last Sunday's backup only data files that belong to the tablespace in which the table was stored and then perform a complete recovery
B
B
教材5-16,5-21


7.
22. You performed an incomplete recovery on your Oracle Database 10g database using the following command:
SQL> RECOVER DATABASE
2 UNTIL TIME '2004-08-05:12:10:03'
3 USING BACKUP CONTROLFILE;
In which situation would the above recovery be required?
A. A user table was lost at the specified time.
B. A redo log file was lost at the specified time.
C. The backup control file is on a faster disk than the current one.
D. The current control file has a different path compared with the intended time of recovery.
E. The current control file does not match the physical structure of the database at the intended time of recovery.
E
E
教材5-11没讲


8.
33. Your database operates in ARCHIVELOG mode. The redo log files are not multiplexed and one of the online redo logs is missing. The missing redo log sequence, 230, is not archived and it contained information from 10:35 a.m. onwards. The current time is 11:00 a.m. Because of a disk crash, you executed the following command to perform an incomplete recovery:
RMAN> RUN {
2> SET UNTIL SEQUENCE 230 THREAD 1;
3> ALTER DATABASE MOUNT;
4> RESTORE DATABASE;
5> RECOVER DATABASE;
6> ALTER DATABASE OPEN RESETLOGS;
7> };
With reference to this scenario, which statement is true?
A. RMAN recovers up to log sequence 230, but not including 230.
B. RMAN returns an error because the log sequence number mentioned in the command should be 229.
C. RMAN returns an error because the log sequence number mentioned in the command may never be missing.
D. RMAN recovers up to and including log sequence 229 but then returns an error because log sequence 230 is missing.
A
A
教材5-23


9.
34. In your database, all the tablespaces are locally managed. You started Recovery Manager (RMAN) using recovery catalog and restored the control file by using the following command:
RMAN> RESTORE CONTROLFILE;
Which two operations do you need to perform after restoring the control file from backup? (Choose two.)
A. shut down and restart the instance
B. add new tempfiles to the temporary tablespaces after recovery
C. perform a media recovery and open the database with the RESETLOGS option
D. perform a media recovery and bring the database to NOARCHIVELOG mode
AB
BC
教材5-30


10.
36. Exhibit. One of the important tables in the USERS tablespace was dropped and purged from the recycle bin at 9:00 a.m. You noticed this at 11:00 a.m. and you want to perform an incomplete recovery to recover the table. Which statement is true?
1z0-043-lessson5-10.png
A. You must recover all data files to the required system change number (SCN).
B. You must recover all data files, except those that are offline, to the required SCN.
C. You must recover all data files belonging to the USERS tablespace to the required SCN.
D. You cannot recover all data files because segment space management is performed manually for the undo tablespace.
C 不知道跟UNDO有什么关系
B

C.表空间的时间点的恢复(TSPITR: TableSpace Point-In-Time Recovery)呢?
D.好像跟UNDO没关系


11.
52. The loss of which two types of files may require a recovery with the RESETLOGS option?(Choose two.)
A. control files
B. password file
C. archived log files
D. system-critical data files for which all the redo entries are present
E. non-system-critical data files for which all the redo entries are present
A,C
AC
教材5-30,5-20,5-11


12.
57. You executed the following command in Recovery Manager (RMAN):
RMAN> RESTORE CONTROLFILE;
Which operation must you perform before this command is executed?
A. back up the control file to trace
B. bring database to the MOUNT state
C. open a connection to the RMAN recovery catalog, which contains the RMAN metadata for the target database
D. set the database ID (DBID), but only if the DB_NAME parameter associated with the target database is unique in the recovery catalog
B
C
教材5-30

D.如果没有catalog才用设置DBID


13.
77. Case 1:
1. Shut down the database and perform a backup.
2. Restore all the data files.
3. Mount the database.
4. Recover the database.
5. Without applying all the redo log files, open the database using the RESETLOGS option.
6. Back up the database.
Case 2:
1. Shut down the database and perform a backup.
2. Restore only the data files of the tablespace where user error damaged the data.
3. Mount the database.
4. Recover the database.
5. Open the database with the RESETLOGS option.
6. Back up the database.
Case 3:
1. Shut down the database.
2. Restore the data files.
3. Open the database.
4. Perform recovery to the current point in time.
Which case has the correct steps for an incomplete recovery?
A. Only case 1
B. Only case 2
C. Only case 3
D. Case 1 and 2
E. Case 2 and 3
F. Case 1 and 3
G. All cases, case 1, case 2, case 3
A
A
教材5-9


14.
99. You lost a data file that belongs to an index tablespace in your database, which operates in ARCHIVELOG mode. Loss of the data file resulted in increased response time on your queries. Which two options would you use to solve this problem? (Choose two)
A. Restore the lost data file from the backup, and then flash back the database.
B. Restore the data file pertaining to index tablespace, and then recover the tablespace.
C. Restore all the data files, and then perform an incomplete recovery to get the tablespace back.
D. Restore all the data files, and then perform an incomplete recovery using the backup control file.
E. Drop and re-create the index tablespace, and then re-create all of the indexes in that tablespace.
BE
BE
完全恢复或重建

C不完全恢复会丢失其它数据


15.
100. You database operates in ARCHIVELOG mode and user-managed consistent backups are performed every Sunday night. On Tuesday, at 9:00 a.m. the current log sequence number was 369. Also, on Tuesday you lost the data file belonging to the SYSTEM tablespace and an achivelog file (sequence number 356) that contained redo entries between 8:00 a.m. and 8.30 a.m. With reference to this scenario, what would you do to recover the database?
A. Restore all the data files from last Sunday's backup, and then perform a time-based recovery.
B. Restore all the data files from last Sunday's backup, and then perform a cancel-based recovery.
C. Restore all the data files from last Sunday's backup, and then perform a change-based recovery.
D. Restore only data files that belong to the SYSTEM tablespace from last Sunday's backup, and then perform a complete recovery.
B
B

或者UNTIL SEQUENCE


16.
104. You are using Oracle Database 10g. The log LOG_ARCHIVE_FORMAT parameter is set to 'LOG%t_%_s_%r.dbf'. Why is %r used in the file name format?
A. To uniquely identify the archived log files with the restore operation.
B. To uniquely identify the archived log files with the redo log group number.
C. To uniquely identify the archived log files for each incarnation of the database.
D. To uniquely identify the archived log files with the number of recovery operations performed
C
C
教材5-28


17.
110. Your database is functioning in NOARCHIVELOG mode. Your database contains 15 tablespaces. You want to use Recovery Manager (RMAN) to perform backups. Which two backups would you be able to perform when the database is being accessed by users? (Choose two)
A. Backup of offline tablespaces.
B. Backup of read-only tablespaces.
C. Backup of system-critical tablespaces.
D. Backup of online, locally managed tablespaces.
E. Backup of read/write dictionary-managed tablespaces.
A,B
AB
教材3-10, 不是这课的


18.
115. You used the following command in Recovery Manager (RMAN) as part of the recovery process:
RESTORE CONTROLFILE FROM AUTOBACKUP;
How does RMAN find the control file autobackup? (Choose all the apply)
A. By using the trace file.
B. By using the alert log file.
C. By using the database ID.
D. By using the server parameter file.
E. By using the V$CONTROLFILE view.
F. By using the autobackup format configuration setting.
C,F 做过
CF
第2课解释过


19.
123. For an incomplete recovery, which four backup types can be used by Recovery Manager (RMAN) to restore data files? (Choose four)
A. RMAN image copies.
B. RMAN database backups.
C. RMAN tablespace backups.
D. User-managed backups placed in the flash recovery area.
E. User-managed backups that have been cataloged with RMAN.
F. User-managed data file backups for which the full path name is specified.
A,B,C,E
ABCE
不清楚,跟是不是incomplete的没关系吧?


20.
124. You are using Oracle Database 10g. You performed an incomplete recovery of your database and opened the database with the RESETLOGS option. What is the effect of opening the database with the RESETLOGS option? (Choose two)
A. This operation resets the SCN for the database.
B. This operation creates a new incarnation of the database.
C. This operation moves all the redo log files to a different location.
D. This operation deletes the old redo log files and creates new redo log files.
E. This operation updates all current datafiles and online redo logs and all subsequent archived redo logs with a new RESETLOGS SCN and time stamp.
B,E
BE

A. datebase scn不变?
B教材5-28
E教材5-20


21.
126. Your database is functioning in ARCHIVELOG mode. In which two situations would you perform a cancel-based recovery? (Choose two)
A. You find that one of the redo log members in each redo log group is lost.
B. You find that a data file that belongs to the USERS tablespace is damaged.
C. You find that a data file that belongs to the SYSTEM tablespace is damaged.
D. You find that the current redo log group is damaged and is not available for recovery.
E. You realized while performing a recovery that an archived redo log file needed for recovery is lost.
D,E
DE
教材5-12


22.
135. Exhibit, One the evening of April 22, you are working on a database created using Oracle Database 10g. This database operates in the ARCHIVELOG mode. You discover that you need crucial data that was dropped from the database at 8:00 a.m. No full backup has been taken after April 15.What would you do?
1z0-043-lessson5-22.png
A. recover the database until April 10
B. recover the database until April 15
C. recover the database until 22 7:59 a.m.
D. recovery is not possible; manually re-create the object
C 10g好像行?
C
pdf教材8-33
教材5-28:"If you are using Oracle Database 10g, this step is now optional."


23.
153. Your database operates in ARCHIVELOG mode and all the tablespaces are online. Due to a user error, you decided to perform an incomplete recovery. Which two tasks would you be required to perform in the recovery process? (Choose two.)
A. open the database with the RESTRICTED option
B. open the database with the RESETLOGS option
C. recover to the required SCN only that data file in which the error occurred
D. recover all the data files to the same system change number (SCN)
B,D
BD
教材5-20


24.
156. You lost the PRODSTD tablespace, which was read-only. The tablespace was read-only when the last backup was taken. How would you recover the tablespace?
A. restore the tablespace from the backup, and then perform an incomplete recovery
B. restore the tablespace from the backup, and then apply all the redo information
C. restore all the data files in the database, and then perform an incomplete recovery
D. restore the tablespace from the backup
D
D
教材5-33


25.
157. The loss of the control file forced you to re-create the control file. After re-creating it and opening the database, you find that some of the data files are named as MISSINGnnnnn, where nnnnn is a five-digit number starting with 0. What could be the possible reason?
A. These are the data files that are corrupted.
B. There is no SYSAUX tablespace in your database
C. There is a read-only tablespace in your database.
D. These are the data files that cannot be recovered.
C
C
教材5-35


26.
158. Every Sunday, consistent backups are performed on your database. Because of a user error, you performed an incomplete recovery on Tuesday and opened the database with the RESETLOGS option. A user error occurs again on Thursday, which necessitates an incomplete recovery. Sunday's backup is the most recent backup available.What would you do in this scenario?
A. recovery cannot be performed because a backup was not performed after the last incomplete recovery
B. restore all the files from Sunday's backup, and then recover up to the point in time when the RESETLOGS operation was performed on Tuesday
C. restore all the files from Sunday's backup, and open the database to reset the database to the point in time when the backup was performed on Sunday
D. restore all the files from Sunday's backup, and then perform an incomplete recovery up to the point in time when the user error occurred on Thursday
D 同第22题
D
同第22题


27.
165. You have only two redo log groups and these groups get overwritten several times in a day. Your database operates in NOARCHIVELOG mode and user-managed consistent backups are performed every Sunday night. On Thursday morning, you find that an important table has been dropped and purged. With reference to this scenario, up to what point in time can the data be recovered?
A. until Thursday morning
B. until that point in time when the database is opened
C. until that point in time when the recovery is performed
D. until last Sunday's backup
E. until that point in time when the table is dropped and purged
F. until Wednesday evening
D
D
只能恢复到上次备份


28.
167.In your database, all the tablespaces are locally managed. You started Recovery Manager (RMAN) using recovery catalog. The following commands are used in the process of recovering the database by using the backup control file:
1.RESTORE CONTROLFILE;
2.RESTORE DATABASE;
3.ALTER DATABASE MOUNT;
4.SQL ALTER TABLESPACE temp ADD TEMPFILE
5.ALTER DATABASE OPEN RESETLOGS;
6.RECOVER DATABASE;
7.STARTUP NOMOUNT;
In what sequence would you use this process to perform the recovery?
A. 2, 7, 3, 5, 1, 6, 4
B. 2, 1, 7, 6, 3, 5, 4
C. 7, 1, 3, 2, 6, 5, 4
D. 7, 2, 3, 1, 4, 6, 5
C
C
教材5-30,5-35


29.
175. You have a read-only tablespace on read-only media. You want to perform a media recovery on the existing data files, but using a backup control file. The backup control file indicates that the status of the read-only tablespace was read/write when the control file was backed up. What should you consider?
A. take data files from the read-only tablespace offline before performing a recovery
B. recovery using backup control file is not possible, so restore all the files from the last full database backup, and then open the database
C. drop the read-only tablespace and re-create the tablespace after recovery
D. perform a recovery; status of the tablespace in control file will be changed automatically
D


30.
180. You are working on Oracle Database 10g, which is in ARCHIVELOG mode. All the archived log files are intact. In which scenario would performing a recovery require the opening of the database with the RESETLOGS option?
A. loss of one of the tablespaces
B. loss of a system data file
C. loss of one of the control files
D. loss of a tempfile
E. loss of the only member of an unarchived redo log group
F. loss of a member from each redo log group
B
E
失误,不应该做错的呀


31.
183. You are connected to Recovery Manager (RMAN) without a recovery catalog. There is no copy of the control file available. You want to restore the control file from an autobackup. To retrieve the autobackup, you need the database ID (DBID). In which two sources would you find the DBID? (Choose two.)
A. the alert log file
B. the server parameter file
C. the formatted name of a control file autobackup
D. an RMAN session log file
E. the trace file
CD 做过
CD
做过

pdf教材8-6


=====

32.
11. You are faced with a media failure for a tablespace that is currently read-only. The only backup of the read-only tablespace was made one week ago when the tablespace was read-write. What do you have to do to recover this tablespace? (Choose all that apply.)
A. You only need to restore the datafile for this tablespace because the tablespace is read-only.
B. You only need to restore and recover the datafile for this tablespace because the tablespace you have restored is read-write.
C. You only need to restore and recover the datafile for this tablespace because the tablespace has a different SCN in the header.
D. You only need to recover the datafile for this tablespace because the tablespace is read-only.
BC ?
11. B, C. You need to restore and recover the tablespace of the read-only tablespace because the tablespace was read-write when the backup was taken. If the tablespace was backed up read-write, the datafile has changed or has a different SCN in the datafile header. This will require recovery. See Chapter 3 for more information.

教材5-33的案例3
不清楚是怎么恢复的,得做个试验


33.
12. User-managed recovery requires which major difference from using RMAN?
A. User-managed recovery uses the UNTIL SCN clause.
B. User-managed recovery uses the UNTIL SEQUENCE clause.
C. User-managed recovery uses the UNTIL TIME clause.
D. User-managed recovery requires the DBA to directly manage the recovery.
D
12. D. User-managed recovery requires the DBA to directly manage the recovery process. The DBA must determine which database files to restore and from what backup, as well as which archive logs to apply. See Chapter 4 for more information.

A.用户管理的是UNTIL CHANGE, RMAN管理的用的才是UNTIL SCN


34.
13. Why does control file recovery require special steps when using RMAN without the recovery catalog? (Choose all that apply.)
A. Special steps are required when recovering control files because they are not part of the physical database.
B. Special steps are required when recovering control files because they contain RMAN metadata information.
C. Special steps are required when recovering a database when the RMAN repository is not available for that database.
D. Special steps are required when recovering control files because they cannot be easily rebuilt.
B,C
13. B, C. Control files contain the RMAN repository when not using the recovery catalog that contains metadata about the backups that are used to perform the recovery. This information is not available when recovering a control file. See Chapter 4 for more information.

问的不好


35.
14. Logical corruption has been introduced into the database. You need to recover the database to the point-in-time prior to the introduction of the corruption. The logical corruption was introduced at 6:30 P.M. on September 6, 2004.
A. run
{
set until time '06-SEP-2004 6:25:00';
restore database;
recover database;
}
B. run
{
set until time '06-SEP-2004 18:25:00';
recover database;
}
C. run
{
set until time '06-SEP-2004 18:25:00';
restore database;
}
D. run
{
set until time '06-SEP-2004 18:25:00';
restore database;
recover database;
}
D
14. D. The correct RMAN commands would be as follows:
run
{
set until time '06-SEP-2004 18:25:00';
restore database;
recover database;
}
The closest time to 6:30 P.M. would be 18:25. You need to use both the RESTORE DATABASE and RECOVER DATABASE commands. See Chapter 4 for more information.

教材5-21


36.
15. You have a backup from two days ago. It is discovered that corruption was introduced today at 6:30 P.M. You perform an incomplete recovery of the database to 6:25 P.M. before the corruption. One day later you have a media failure, and you need to recover but you only have the same backup that was used to perform an incomplete recovery prior to the corruption. What will happen to the recovery attempt for the media failure?
A. The media recovery will fail because you have performed a RESETLOGS to recover from the corruption and you have not taken another backup after the RESETLOGS operation.
B. The media recovery will be successful because you can perform a RESETLOGS to recover from an incomplete recovery to a new point-in-time greater than the RESETLOGS operation.
C. The media recovery will fail because you always must take a backup following an incomplete recovery with RESETLOGS to open the database.
D. The media recovery will only be successful if you recover the database back to the original time of 6:25 P.M. before the corruption.
B ?
15. B. You can now recover through an incomplete recovery, which uses RESETLOGS to open the database. In previous Oracle versions, you had to take a backup immediately following an incomplete recovery, because the redo log sequences got reset, making the backup unusable. See Chapter 4 for more information.

10g新特性


==

37.
10. What should be updated and readily accessible in case of a non-critical loss of a tablespace?
A. Temporary segments
B. SELECT statements using sorting
C. Current index scripts
D. Create table scripts
C 什么意思?
10. C. The index scripts must be current and stored locally so they can be accessed quickly and easily during an index tablespace rebuild.

修改建索引的脚本,重建索引表空间和索引


38.
11. Which type of tablespace contains static data?
A. Read-only tablespace
B. Index tablespace
C. Read-write tablespace
D. Temporary tablespace
A
11. A. The read-only tablespace contains only static or non-changing data.

教材5-33


39.
12. What is the result of starting an Oracle database with a missing read-only tablespace? (Choose two.)
A. The database opens normally.
B. The database only mounts.
C. An ORA-01157 cannot identify datafile halts the database from opening error occurs.
D. The database functions normally, and the read-only tablespace is static.
A ?
12. B, C. The database will stop at the mount stage. This is due to the ORA-01157 error.

这个也可以试试


40.
19. The main reason that you need to restore and use the RECOVER command on a tablespace that was backed up read-write and converted to read-only is due to what? (Choose all that apply.)
A. The checkpointing process has changed the control file.
B. There have been changes to the tablespace.
C. The tablespace file header has been changed.
D. Read-only tablespaces require the RECOVER command.
A,B,C
19. A, B, C. The scenario of read-write to read-only tablespace requires the use of the RECOVER command, which will apply necessary redo changes to make the tablespace consistent with the control file. The checkpointing operation of Oracle will change the control file, and the header of the read-only tablespace will be modified, which equates to changes in the tablespace.

同前面那几道题
另外,怎么又是恢复一个表空间? 又是TSPITR?


===

41.
1. What is another name for RMAN-based database recovery?
A. User-managed recovery
B. Server-managed recovery
C. Traditional recovery
D. Database recovery
B ?
1. B. Server-managed recovery is another name for RMAN recovery because the server session performs the recovery process as it interacts with the target database.

pdf教材8-4


42.
2. What command is responsible for automating the backup of control files?
A. ALTER DATABASE CONTROLFILE AUTOBACKUP ON
B. ALTER SYSTEM CONTROLFILE AUTOBACKUP ON
C. CONFIGURE CONTROLFILE AUTOBACKUP ON
D. ENABLE CONTROLFILE AUTOBACKUP
C
2. C. The control file autobackup is enabled by setting parameters within RMAN by using CONFIGURE CONTROLFILE AUTOBACKUP ON.

第2课讲过


43.
3. What is the process to recover a control file?
A. Start up database, restore control file, start up mount the database, recover the database, and open the database.
B. Start up mount, restore control file, start up the database, recover the database, and open the database.
C. Start up nomount, restore control file, start up mount the database, recover the database, and open the database.
D. Start up force, restore control file, start up the database, recover the database, and open the database.
C
3. C. The database needs to be started in NOMOUNT mode because there is not a control file available to MOUNT the database. Next, the control file can be restored. Once a restored control file is available, the database can be started in MOUNT mode so that standard database recovery can continue. When recovery is complete, the database can OPEN for normal use.

教材5-30


44.
4. When recovering a control file without the recovery catalog, what special step must be performed to identify the target database? (Choose all that apply.)
A. You must CONNECT TARGET / to the target database within RMAN.
B. You must STARTUP MOUNT the database because the control file is missing.
C. You must SET DBID to the target database so that the target database can be identified without the control file available.
D. You must CONNECT TARGET database name to the target database within RMAN.
A? C
4. A, C. The target database is not identifiable by database name without the control file. So you must first use the CONNECT TARGET / command to connect. The target database needs to be identified by the database identifier (DBID) number with the command SET DBID database identifier. This database identifier number denotes the target database. When you are recovering the control file, the target database identification is not available because it is stored in the control file.

教材5-30,


45.
5. After you restore the control file, what must you do before you execute the RECOVER command to apply archive logs?
A. The database must be restored with the RESTORE command.
B. The database must be reconnected with the CONNECT TARGET database name command.
C. The database must be started in MOUNT mode.
D. The database must open for use with ALTER DATABASE OPEN command.
C
5. C. The database must be mounted before the RECOVER command can be executed. You first must restore control so you can MOUNT the database.

当然了


46.
6. Which of the following methods should you use for creating a control file? (Choose all that apply.)
A. Dump the control file information to a trace file.
B. Use the ALTER DATABASE BACKUP CONTROLFILE TO TRACE command.
C. Use the CREATE CONTROLFILE command.
D. None of the above.
A,B
6. A, B. The ALTER DATABASE BACKUP CONTROL FILE TO TRACE command creates a user trace file, which stores an ASCII representation of the binary control file.

教材5-31
AB说的是一回事


47.
7. What are the two cases defined in the backup control file? (Choose two.)
A. ALTER DATABASE OPEN
B. ALTER DATABASE OPEN RESETLOGS
C. ALTER DATABASE OPEN NORESETLOGS
D. ALTER DATABASE OPEN NORESET
BC
7. B, C. The two cases in the backup control file are opening the database with RESETLOGS or NORESETLOGS.

RESETLOG,NORESETLOGS两种


48.
8. Which files need to be available and in the matching location of the ASCII control file in order to rebuild the control file? (Choose all that apply.)
A. Server file, PFILE or SPFILE
B. Datafiles
C. Control files
D. Redo logs
A,B, D?
8. A, B. The server file, SPFILE or PFILE must be available to start the database with the right parameters, and the datafiles must be in the location matching the control file. The redo logs and control file will be rebuilt.

重做日志文件会被重建


49.
9. Which of the following descriptions best describes incomplete recovery? (Choose all that apply.)
A. Recovery that stops before the failure
B. Recovery that stops at the point of failure
C. Recovery that is missing transactions
D. Recovery that is not missing transactions
ABD?
9. A, C. Incomplete recovery is a recovery that stops before the failure and a recovery that is missing transactions. Incomplete recovery is not complete or missing some data that was previously stored in the database prior to the failure.

教材5-7
B应该是之前
D应该是丢失一些事务


50.
10. What are the required steps to perform a RMAN-based incomplete recovery with the SET UNTIL TIME clause?
A. Start up the database in MOUNT mode, verify or set the NLS_DATE_FORMAT environment variable, designate time with the SET UNTIL TIME time stamp, restore the necessary files with the RESTORE DATABASE command, recover the database with the RECOVER DATABASE command, and then open the database with the ALTER DATABASE OPEN command.
B. Start up the database in NOMOUNT mode, verify or set the NLS_DATE_FORMAT environment variable, designate the SET UNTIL TIME time stamp, restore the necessary files with the RESTORE DATABASE command, recover the database with the RECOVER DATABASE command, and then open the database with the ALTER DATABASE OPEN RESETLOGS command.
C. Start up the database in MOUNT mode, designate the SET UNTIL TIME time stamp, restore the necessary files with the RESTORE DATABASE command, recover the database with the RECOVER DATABASE command, and then open the database with ALTER DATABASE OPEN NORESETLOGS command.
D. Start up the database in MOUNT mode, verify or set the NLS_DATE_FORMAT environment variable, designate the SET UNTIL TIME time stamp, restore the necessary files with the RESTORE DATABASE command, recover the database with the RECOVER DATABASE command, and then open the database with ALTER DATABASE OPEN RESETLOGS command.
D
10. D. The proper process of performing a RMAN based incomplete recovery utilizing a time stamp to determine the point-in-time to complete the recovery process is as follows: Start up the database in MOUNT mode, verify or set the NLS_DATE_FORMAT environment variable if not present, designate the SET UNTIL TIME time stamp, restore the necessary files with the RESTORE DATABASE command, recover the database with the RECOVER DATABASE command, and then open the database with ALTER DATABASE OPEN RESETLOGS command.

教材5-21,5-22


51.
11. Which command is not a valid RMAN incomplete recovery run block?
A. run
  {
   set until change 7563633;
   restore database;
   recover database;
  }
B. run
  {
   set until time '06-SEP-2004 11:25:00';
   restore database;
   recover database;
  }
C. run
  {
   set until SCN 7563633;
   restore database;
   recover database;
  }
D. run
  {
   set until sequence 3 thread 1;
   restore database;
   recover database;
  }
C
11. A. The SET UNTIL CHANGE command is not used with RMAN. This command is used during a user-managed incomplete recovery.

教材5-13


52.
12. Which of the following would be a reason for using incomplete recovery? (Choose all that apply.)
A. Stopping the recovery at a certain redo log sequence before a database corruption point
B. Stopping the recovery at a certain time when database corruption occurred
C. Stopping the recovery before a bad transaction is executed
D. Stopping the recovery only after applying all transactions
ABC
12. A, B, C. Incomplete recovery is designed to be able to stop at a desired point, before introducing undesired transactions to the database.

教材5-10
D完全恢复


53.
13. Which incomplete recovery capability is available to RMAN or user-managed methods?
A. SET UNTIL TIME
B. UNTIL TIME
C. UNTIL SCN
D. UNTIL SEQUENCE
B 不知道, 和33题不一样呀
13. B. The UNTIL TIME clause is available in both user-managed and RMAN-based incomplete recovery methods.

同第33题


54.
14. When performing incomplete recovery, which command allows you to stop the recovery process at a random point?
A. UNTIL SEQUENCE, when performing a user-managed recovery
B. UNTIL SCN, when performing a RMAN-based recovery
C. UNTIL CANCEL, when performing a RMAN-based recovery
D. UNTIL CANCEL, when performing a user-managed recovery
C 不知道,什么叫random point?
14. D. The UNTIL CANCEL command is available only in user-managed recovery. This command allows you to stop the recovery process at a random point during redo log switches.

恢复到哪个日志不也是确定的吗


55.
15. Which command is required when performing an incomplete recovery?
A. ALTER DATABASE OPEN RESETLOGS
B. ALTER DATABASE OPEN NORESETLOGS
C. UNTIL CANCEL
D. ALTER DATABASE OPEN
A
15. A. The ALTER DATABASE OPEN RESETLOGS command is required with every incomplete recovery. This is because the redo log sequence always needs to be reset.

教材5-10


56.
16. When using EM to perform a whole database incomplete recovery, what sequence of events must occur? (Choose the best answer.)
A. The database must be shut down and started in NOMOUNT mode.
B. The database must be started in MOUNT mode.
C. The database must be shut down and started in MOUNT mode.
D. The database must be shut down and restarted.
C EM?
16. C. When using EM, the database must be shut down and started in MOUNT mode so that a whole database backup can be performed when you are recovering the same database EM is connected to.

为什么是EM? 用RMAN也要关库,STARTUP MOUNT吧?
pdf教材8-30说可以全库不完全恢复, 还可以表空间,数据文件,归档日志,表的不完全恢复? 教材5-20说必须恢复到一样的SCN. 很矛盾呀


57.
17. Which credentials are needed to perform a recovery with EM? (Choose all that apply.)
A. Database account with SYSDBA privilege
B. Administrator account in Windows
C. Oracle account in Unix
D. Any Windows account
A,B,C
17. A, B, C. You need two credentials when running a recovery with EM: the correct operating system account and the correct database account. The correct operating system account is an account similar to the Oracle account in Unix or the administrator account in Windows. The database account is any account that has SYSDBA privilege.

pdf教材8-27,8-30


58.
18. The RESETLOGS clause is required with which of the following types of incomplete recovery?
A. Using the UNTIL CANCEL command and applying almost all the archived redo logs before cancelling recovery
B. Using the UNTIL TIME command and stopping before the current time
C. Using the SET UNTIL SEQUENCE command and stopping before the last redo log sequence
D. All of the above
D
18. D. The RESETLOGS clause is required with all incomplete recovery options. The RESETLOGS clause is required because you are opening the database to a point prior to the existing redo log entries. So the redo logs must be reset when the database is opened.

是不完全恢复就要RESETLOGS


59.
19. What is required to perform a UNTIL SEQUENCE recovery in RMAN?
A. Identifying the sequence number with V$LOGHISTORY
B. Identifying the sequence number with V$LOG_HISTORY
C. Identifying the SCN number with V$LOG_HISTORY
D. Identifying the SCN number with V$LOGHISTORY
B
19. B. You need to know the redo log sequence number and thread to perform an UNTIL SEQUENCE recovery in RMAN. This can be obtained by querying the V$LOG_HISTORY dynamic view.

教材5-18


60.
20. What is required to recover your database through a RESETLOGS recovery from a backup created prior to the RESETLOGS recovery?
A. NORESETLOGS
B. RESETLOGS
C. UNTIL SEQUENCE
D. Nothing, this feature is automatic.
D
20. D. The new feature to recover your database through a prior RESETLOGS recovery is native with Oracle 10g. Oracle will recover the database through the RESETLOGS prior to recovery if necessary.

10g新特性



疑问:
1.除了10g新特性TSPITR, 可以部分库不完全恢复吗?比如不完全恢复一个表空间(第56题, EM有这些选项)
2.怎么恢复只读表空间? 从读写的变成只读的,怎么恢复?教材5-33的3个案例





-fin-

Friday, January 9, 2009

setup vnc server for linux - 配置VNC Server服务

setup vnc server for linux - 配置VNC Server服务




vnc是远程共享桌面用的
介绍如何在CentOS/Redhat上配置 VNC Server, 使用vnc viewer, SSH安全访问等


1. 安装vnc server

rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" |grep -i vnc
[root@Perf-pxy-2 ~]# rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" |grep -i vnc
vnc-server-4.1.2-9.el5.x86_64
vnc-4.1.2-9.el5.x86_64
[root@Perf-pxy-2 ~]#
已经安装了vnc服务和客户程序



2. 启动vncserver

登录一个用户, 启动vnc服务
[root@Perf-pxy-2 ~]# su - mysql
[mysql@Perf-pxy-2 ~]$ vncserver

You will require a password to access your desktops.

Password:
Password must be at least 6 characters - try again
Password:
Verify:
xauth: creating new authority file /var/lib/mysql/.Xauthority

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Creating default startup script /var/lib/mysql/.vnc/xstartup
Starting applications specified in /var/lib/mysql/.vnc/xstartup
Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$ ls -la .vnc
total 24
drwxr-xr-x 2 mysql mysql 4096 Jan 6 07:54 .
drwxr-xr-x 3 mysql mysql 4096 Jan 6 07:54 ..
-rw------- 1 mysql mysql 8 Jan 6 07:54 passwd
-rw-r--r-- 1 mysql mysql 556 Jan 6 07:54 Perf-pxy-2.s3lab.mot.com:1.log
-rw-r--r-- 1 mysql mysql 6 Jan 6 07:54 Perf-pxy-2.s3lab.mot.com:1.pid
-rwxr-xr-x 1 mysql mysql 334 Jan 6 07:54 xstartup
[mysql@Perf-pxy-2 ~]$
第一次运行前因为还没有创建密码文件, 所以提示输入密码, 在访问VNC服务时要用到这个密码
用户$HOME家目录下创建了.vnc目录和.vnc/xstartup脚本, passwd密码文件等
然后启动了 vnc服务
信息显示出新的桌面名称是'Perf-pxy-2.s3lab.mot.com:1 (mysql)', 位于 Perf-pxy-2.s3lab.mot.com:1
New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

用vncpasswd命令创建或修改密码
vncpasswd <<'EOF'
123123
123123
EOF
[mysql@Perf-pxy-2 ~]$ vncpasswd <<'EOF'
> 123123
> 123123
> EOF
Password:Verify:[mysql@Perf-pxy-2 ~]$


3. vncserver的监听端口

默认的, vnc 服务监听3个TCP端口
RFB(Remote FrameBuffer)协议 默认端口 : 5900+显示器号
HTTP协议默认端口 : 5800+显示器号
X协议 默认端口 : 6000+显示器号
vncserver使用的显示器编号默认从1开始, 依次使用, 也可以参数指定端口号

启一个vncserver, 默认占用了5801,5901,6001端口
vncserver
/usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:1.pid")
[mysql@Perf-pxy-2 ~]$ vncserver

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup
Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$ /usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:1.pid")
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Xvnc 23896 mysql cwd DIR 8,2 4096 2050291 /var/lib/mysql
Xvnc 23896 mysql rtd DIR 8,2 4096 2 /
Xvnc 23896 mysql txt REG 8,2 1681088 1153094 /usr/bin/Xvnc
Xvnc 23896 mysql mem REG 8,2 134400 1664137 /lib64/ld-2.5.so
Xvnc 23896 mysql mem REG 8,2 1699880 1664138 /lib64/libc-2.5.so
Xvnc 23896 mysql mem REG 8,2 615136 1664143 /lib64/libm-2.5.so
Xvnc 23896 mysql mem REG 8,2 23360 1664144 /lib64/libdl-2.5.so
Xvnc 23896 mysql mem REG 8,2 30496 1150346 /usr/lib64/libfontenc.so.1.0.0
Xvnc 23896 mysql mem REG 8,2 85608 1164877 /usr/lib64/libz.so.1.2.3
Xvnc 23896 mysql mem REG 8,2 501832 1146413 /usr/lib64/libXfont.so.1.4.1
Xvnc 23896 mysql mem REG 8,2 12040 1164881 /usr/lib64/libXau.so.6.0.0
Xvnc 23896 mysql mem REG 8,2 22032 1164882 /usr/lib64/libXdmcp.so.6.0.0
Xvnc 23896 mysql mem REG 8,2 1099816 1164883 /usr/lib64/libX11.so.6.2.0
Xvnc 23896 mysql mem REG 8,2 543824 1164878 /usr/lib64/libfreetype.so.6.3.10
Xvnc 23896 mysql mem REG 8,2 58400 1660009 /lib64/libgcc_s-4.1.2-20080102.so.1
Xvnc 23896 mysql mem REG 8,2 976312 1145904 /usr/lib64/libstdc++.so.6.0.8
Xvnc 23896 mysql DEL REG 0,8 3014672 /SYSV00000000
Xvnc 23896 mysql DEL REG 0,8 3047441 /SYSV00000000
Xvnc 23896 mysql DEL REG 0,8 3080210 /SYSV00000000
Xvnc 23896 mysql 0u IPv6 90730 TCP *:6001 (LISTEN)
Xvnc 23896 mysql 1u IPv4 90731 TCP *:6001 (LISTEN)
Xvnc 23896 mysql 2w REG 8,2 556 2051197 /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log
Xvnc 23896 mysql 3u unix 0xffff81003dde2c80 90732 /tmp/.X11-unix/X1
Xvnc 23896 mysql 4u IPv4 90736 TCP *:5901 (LISTEN)
Xvnc 23896 mysql 5u IPv4 90737 TCP *:5801 (LISTEN)
Xvnc 23896 mysql 6u unix 0xffff81001b21b380 90742 /tmp/.X11-unix/X1
Xvnc 23896 mysql 7u unix 0xffff810002d83680 90744 /tmp/.X11-unix/X1
Xvnc 23896 mysql 8u unix 0xffff81000dc80c80 90746 /tmp/.X11-unix/X1
[mysql@Perf-pxy-2 ~]$

再启一个vncserver, 默认占用了5802,5902,6002端口
[root@Perf-pxy-2 ~]# vncserver

New 'Perf-pxy-2.s3lab.mot.com:2 (root)' desktop is Perf-pxy-2.s3lab.mot.com:2

Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/Perf-pxy-2.s3lab.mot.com:2.log

[root@Perf-pxy-2 ~]# /usr/sbin/lsof -p $(cat ".vnc/Perf-pxy-2.s3lab.mot.com:2.pid")
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
...
Xvnc 23947 root 0u IPv6 90882 TCP *:6002 (LISTEN)
Xvnc 23947 root 1u IPv4 90883 TCP *:6002 (LISTEN)
Xvnc 23947 root 2w REG 8,2 556 2932502 /root/.vnc/Perf-pxy-2.s3lab.mot.com:2.log
Xvnc 23947 root 3u unix 0xffff81000a863c80 90884 /tmp/.X11-unix/X2
Xvnc 23947 root 4u IPv4 90888 TCP *:5902 (LISTEN)
Xvnc 23947 root 5u IPv4 90889 TCP *:5802 (LISTEN)
Xvnc 23947 root 6u unix 0xffff81001b21b080 90895 /tmp/.X11-unix/X2
Xvnc 23947 root 7u unix 0xffff81000dc80680 90897 /tmp/.X11-unix/X2
Xvnc 23947 root 8u unix 0xffff81003dde2980 90899 /tmp/.X11-unix/X2
[root@Perf-pxy-2 ~]#


4. 访问VNC服务

连接vnc服务器的1号显示器(桌面/display)
vncviewer perf-pxy-2:1
[s3op1@DEV-Blur-DB-1 ~]$ vncviewer perf-pxy-2:1

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 23:13:57
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Tue Jan 6 08:04:58 2009
CConn: connected to host perf-pxy-2 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

Tue Jan 6 08:05:57 2009
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding

Tue Jan 6 08:05:58 2009
CConn: Throughput 15714 kbit/s - changing to hextile encoding
CConn: Throughput 15714 kbit/s - changing to full colour
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using hextile encoding
写端口号也行, 比如 vncviewer perf-pxy-2::5901 &

提示输入密码
vnc-vncviewer-auth.png

登入远程桌面
vnc-desktop-twm.png
桌面默认使用twm窗口管理器
登入的用户就是启vncserver的那个用户

免输入密码登录
运行vncpasswd 生成密码文件, 文件名任意
mkdir -p ~/.vnc && (echo "123123";echo "123123")|vncpasswd ~/.vnc/passwd--perf-pxy-2--1; echo
[root@CentOS-1 ~]# mkdir -p ~/.vnc && (echo "123123";echo "123123")|vncpasswd ~/.vnc/passwd--perf-pxy-2--1; echo
Password:Verify:
[root@CentOS-1 ~]#
参数-passwd指定密码文件
vncviewer -passwd ~/.vnc/passwd--perf-pxy-2--1 perf-pxy-2:1 &
[root@CentOS-1 ~]# vncviewer -passwd ~/.vnc/passwd--perf-pxy-2--1 perf-pxy-2:1 &
[1] 15607
[root@CentOS-1 ~]#
VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Thu Jan 8 05:35:35 2009
CConn: connected to host perf-pxy-2 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding

Thu Jan 8 05:35:36 2009
CConn: Throughput 15000 kbit/s - changing to hextile encoding
CConn: Throughput 15000 kbit/s - changing to full colour
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using hextile encoding



5. 更改桌面
改成其它窗口管理器

退出vncviewer
vnc-desktop-exit.png
vnc的好处在于, 桌面是在服务器端运行的, 下次再进入能够继续上次的工作, 只要不关闭/重启vnc服务
还有网络带宽要求比SSH的X11 Forwarding低

停止vnc服务
vncserver -kill :1
[mysql@Perf-pxy-2 ~]$ ps -ef|grep vnc
mysql 18021 1 0 07:54 pts/0 00:00:00 Xvnc :1 -desktop Perf-pxy-2.s3lab.mot.com:1 (mysql) -httpd /usr/share/vnc/classes -auth /var/lib/mysql/.Xauthority -geometry 1024x768 -depth 16 -rfbwait 30000 -rfbauth /var/lib/mysql/.vnc/passwd -rfbport 5901 -pn
mysql 18025 1 0 07:54 pts/0 00:00:00 vncconfig -iconic
mysql 18156 17935 0 08:21 pts/0 00:00:00 grep vnc
[mysql@Perf-pxy-2 ~]$ vncserver -kill :1
Killing Xvnc process ID 18021
[mysql@Perf-pxy-2 ~]$ ps -ef|grep vnc
mysql 18165 17935 0 08:21 pts/0 00:00:00 grep vnc
[mysql@Perf-pxy-2 ~]$

编辑.vnc/xstartup启动脚本, 去掉其中两行注释
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
vncserver服务启动时运行/etc/X11/xinit/xinitrc, 启动缺省的桌面
sed -i '/unset SESSION_MANAGER\|exec \/etc\/X11\/xinit\/xinitrc/{s/ˆ#*//g;s/ˆ //g}' .vnc/xstartup
cat .vnc/xstartup
[mysql@Perf-pxy-2 ~]$ sed -i '/unset SESSION_MANAGER\|exec \/etc\/X11\/xinit\/xinitrc/{s/ˆ#*//g;s/ˆ //g}' .vnc/xstartup
[mysql@Perf-pxy-2 ~]$ cat .vnc/xstartup
#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
[mysql@Perf-pxy-2 ~]$

重启vncserver
[mysql@Perf-pxy-2 ~]$ vncserver

New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup
Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

[mysql@Perf-pxy-2 ~]$
第二次运行vncserver不用输入密码

客户端访问
vncviewer perf-pxy-2:1
[s3op1@DEV-Blur-DB-1 ~]$ vncviewer perf-pxy-2:1

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 23:13:57
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Tue Jan 6 08:33:24 2009
CConn: connected to host perf-pxy-2 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

Tue Jan 6 08:33:28 2009
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
CConn: Throughput 20256 kbit/s - changing to hextile encoding
CConn: Throughput 20256 kbit/s - changing to full colour
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using hextile encoding
进入了好看的GNOME桌面
vnc-desktop-gnome.png


6. 浏览器访问vnc server

JAVA方式默认访问端口是5800加显示器号
firefox http://perf-pxy-2:5801 &
vnc-viewer-for-java-missing-plugin.png
要安装java插件, 该插件在32位的jre中

安装jre
[root@CentOS-1 ~]# sh /u01/software/oracle/java/jre-6u11-linux-i586-rpm.bin
Sun Microsystems, Inc. Binary Code License Agreement

...

Do you agree to the above license terms? [yes or no]
yes
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jre-6u11-linux-i586.rpm
Preparing... ########################################### [100%]
1:jre warning: /etc/.java/.systemPrefs/.system.lock created as /etc/.java/.systemPrefs/.system.lock.rpmnew
warning: /etc/.java/.systemPrefs/.systemRootModFile created as /etc/.java/.systemPrefs/.systemRootModFile.rpmnew
########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...

Done.
[root@CentOS-1 ~]#

注册插件
mkdir -p /usr/lib/firefox-3.0b5/plugins
ln -s /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox-3.0b5/plugins/
[root@CentOS-1 ~]# mkdir -p /usr/lib/firefox-3.0b5/plugins
[1]+ Done firefox
[root@CentOS-1 ~]# ln -s /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox-3.0b5/plugins/
[root@CentOS-1 ~]# ls -l /usr/lib/firefox-3.0b5/plugins/
total 0
lrwxrwxrwx 1 root root 58 Jan 7 05:42 libjavaplugin_oji.so -> /usr/java/jre1.6.0_11/plugin/i386/ns7/libjavaplugin_oji.so
firefox about:plugins &
vnc-viewer-for-java-fx-plugins.png

firefox http://perf-pxy-2:5801 &
vnc-viewer-for-java-connection.png

输入密码
vnc-viewer-for-java-auth.png

显示桌面
vnc-viewer-for-java-desktop.png


7. 系统服务方式自动运行

编辑 /etc/sysconfig/vncservers 配置文件
cat >/etc/sysconfig/vncservers <<'EOF'
VNCSERVERS="1:mysql 5:root"
VNCSERVERARGS[1]="-geometry 1152x864 -nohttpd -nolisten tcp -AlwaysShared -SecurityTypes None"
VNCSERVERARGS[5]="-geometry 1152x864 -nohttpd -nolisten tcp -localhost"
EOF
[root@Perf-pxy-2 ~]# cat >/etc/sysconfig/vncservers <<'EOF'
> VNCSERVERS="1:mysql 5:root"
> VNCSERVERARGS[1]="-geometry 1152x864 -nohttpd -nolisten tcp -AlwaysShared -SecurityTypes None"
> VNCSERVERARGS[5]="-geometry 1152x864 -nohttpd -nolisten tcp -localhost"
> EOF
[root@Perf-pxy-2 ~]#
VNCSERVERS="1:mysql 5:root"
表示启3个vnc服务, 显示器(display)1,5, 分别对应用户 mysql,root
VNCSERVERARGS是为每个vnc显示器配置的参数
-geometry 桌面大小,缺省是1024x768
-nohttpd 不监听HTTP端口
-nolisten tcp 不监听X端口
-localhost 只允许从本机访问
-AlwaysShared 默认的, 同时只能有一个vncviewer连接(跟客户端配置也有关), 一旦第2个连上去, 第1个就被断开了. 此参数允许同时连多个vncviewer
-SecurityTypes None登录不需要密码认证 VncAuth默认值,要密码认证

创建vncserver认证密码
runuser -l mysql -c "(echo '123123';echo '123123')|vncpasswd;echo"
runuser -l root -c "(echo '123123';echo '123123')|vncpasswd;echo"
[root@Perf-pxy-2 ~]# runuser -l mysql -c "(echo '123123';echo '123123')|vncpasswd;echo"
Password:Verify:
[root@Perf-pxy-2 ~]# runuser -l root -c "(echo '123123';echo '123123')|vncpasswd;echo"
Password:Verify:
[root@Perf-pxy-2 ~]#

加入自动启动
chkconfig --level 345 vncserver on
ls -l /etc/rc*.d/*vncserver
[root@Perf-pxy-2 ~]# chkconfig --level 345 vncserver on
[root@Perf-pxy-2 ~]# ls -l /etc/rc*.d/*vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc0.d/K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc1.d/K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc2.d/K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc3.d/S91vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc4.d/S91vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc5.d/S91vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 19 Jan 8 03:34 /etc/rc6.d/K35vncserver -> ../init.d/vncserver
[root@Perf-pxy-2 ~]#

启动服务
service vncserver start
[root@Perf-pxy-2 ~]# service vncserver start
Starting VNC server: 1:mysql
New 'Perf-pxy-2.s3lab.mot.com:1 (mysql)' desktop is Perf-pxy-2.s3lab.mot.com:1

Starting applications specified in /var/lib/mysql/.vnc/xstartup
Log file is /var/lib/mysql/.vnc/Perf-pxy-2.s3lab.mot.com:1.log

5:root
New 'Perf-pxy-2.s3lab.mot.com:5 (root)' desktop is Perf-pxy-2.s3lab.mot.com:5

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/Perf-pxy-2.s3lab.mot.com:5.log

[ OK ]
[root@Perf-pxy-2 ~]#

停止服务
service vncserver stop
[root@Perf-pxy-2 ~]# service vncserver stop
Shutting down VNC server: 1:mysql 5:root [ OK ]
[root@Perf-pxy-2 ~]#


8. 通过SSH隧道安全访问vnc

有时出于安全考虑加密网络传输内容或网络不能直接访问, 可使用<a ref="http://mrxiesdatabase.blogspot.com/2008/08/ssh-tunnel.html">SSH隧道</a>
运行
ssh -L localhost:9905:localhost:5905 -f mysql@perf-pxy-2 "sleep 10" && vncviewer localhost::9905
此命令将perf-pxy-2上的localhost:5905端口转发到本机的localhost:9905端口
输入mysql@perf-pxy-2密码
[root@CentOS-1 ~]# ssh -L localhost:9905:localhost:5905 -f mysql@perf-pxy-2 "sleep 10" && vncviewer localhost::9905
mysql@perf-pxy-2's password:

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Thu Jan 8 05:51:39 2009
CConn: connected to host localhost port 9905
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

Thu Jan 8 05:51:44 2009
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
[root@CentOS-1 ~]#
然后输入vncserver密码登入桌面
当关闭vncviewer后,ssh端口转发进程自动退出

或用 -via 参数
将mysql@perf-pxy-2上的localhost::5905转发到本地某个端口
vncviewer -via mysql@perf-pxy-2 localhost::5905
[root@CentOS-1 ~]# vncviewer -via mysql@perf-pxy-2 localhost::5905

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
mysql@perf-pxy-2's password:

Thu Jan 8 06:50:50 2009
CConn: connected to host localhost port 5599
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

Thu Jan 8 06:50:53 2009
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
[root@CentOS-1 ~]#
写成显示器号也可以, vncviewer -via mysql@perf-pxy-2 localhost:5
ps 查到后台自动调用了ssh命令(设置VNC_VIA_CMD等环境变量可以改变自动调用的命令和参数), 建立了SSH隧道, 转发到本地5599端口
[root@CentOS-1 ~]# ps -ef|grep "[s]sh "
root 15830 15829 0 06:45 pts/0 00:00:00 /usr/bin/ssh -f -L 5599:localhost:5905 mysql@perf-pxy-2 sleep 20
[root@CentOS-1 ~]#


9. 访问服务器本身的桌面

检查是否安装了X的vnc模块
ls -l /usr/lib64/xorg/modules/extensions/libvnc.so
[root@Perf-pxy-2 ~]# ls -l /usr/lib64/xorg/modules/extensions/libvnc.so
-rwxr-xr-x 1 root root 415112 Mar 15 2007 /usr/lib64/xorg/modules/extensions/libvnc.so
[root@Perf-pxy-2 ~]#

编辑X的配置文件
Module段增加加载vnc模块
Screen段增加安全方式等
Section "Module"
Load "vnc"
EndSection
Section "Screen"
Option "SecurityTypes" "VncAuth"
Option "UserPasswdVerifier" "VncAuth"
Option "PasswordFile" "/root/.vnc/passwd"
EndSection
cat /etc/X11/xorg.conf
[root@Perf-pxy-2 ~]# cat /etc/X11/xorg.conf
# Xorg configuration created by pyxf86config

Section "ServerLayout"
Identifier "Default Layout"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection

Section "Device"
Identifier "Videocard0"
Driver "radeon"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Videocard0"
DefaultDepth 16
SubSection "Display"
Viewport 0 0
Depth 16
EndSubSection
Option "SecurityTypes" "VncAuth"
Option "UserPasswdVerifier" "VncAuth"
Option "PasswordFile" "/root/.vnc/passwd"
EndSection

Section "Module"
Load "vnc"
EndSection

[root@Perf-pxy-2 ~]#

已经有密码文件了, 所以不用再生成了
[root@Perf-pxy-2 ~]# ls -l /root/.vnc/passwd
-rw------- 1 root root 8 Jan 8 03:36 /root/.vnc/passwd
[root@Perf-pxy-2 ~]#

重启GNOME桌面
gdm-restart
[root@Perf-pxy-2 ~]# gdm-restart
[root@Perf-pxy-2 ~]# ps -ef|grep gdm
root 6075 1 0 Jan02 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon
root 30411 6075 0 08:59 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon
root 30413 1 0 08:59 ? 00:00:00 /usr/libexec/gdm-rh-security-token-helper
root 30415 30411 4 08:59 tty7 00:00:00 /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7
gdm 30437 30411 3 08:59 ? 00:00:00 /usr/libexec/gdmgreeter
root 30439 23750 0 08:59 pts/0 00:00:00 grep gdm
[root@Perf-pxy-2 ~]# lsof -p 30415
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
...
Xorg 30415 root 7u IPv4 105949 TCP *:5900 (LISTEN)
...
[root@Perf-pxy-2 ~]#
X服务器进程(/usr/bin/Xorg)监听5900这个端口

vncviewer登录
vncviewer perf-pxy-2:0
[root@CentOS-1 ~]# vncviewer perf-pxy-2:0

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Thu Jan 8 09:00:13 2009
CConn: connected to host perf-pxy-2 port 5900
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8

Thu Jan 8 09:00:17 2009
TXImage: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 6 (8bpp) rgb222
CConn: Using ZRLE encoding
[root@CentOS-1 ~]#
vnc-desktop-native.png

确实是远程服务器上的桌面, 是同步的
vnc-desktop-native-shared.png

另一种方式, 运行
x0vncserver -rfbport 5910 -PasswordFile '/root/.vnc/passwd'
[root@Perf-pxy-2 ~]# x0vncserver -rfbport 5910 -PasswordFile '/root/.vnc/passwd'

Thu Jan 8 09:25:41 2009
main: XTest extension present - version 2.2
main: Listening on port 5910

Thu Jan 8 09:26:23 2009
Connections: accepted: 192.168.13.160::48939
SConnection: Client needs protocol version 3.8
SConnection: Client requests security type VncAuth(2)

Thu Jan 8 09:26:28 2009
VNCSConnST: Server default pixel format depth 24 (32bpp) little-endian rgb888
VNCSConnST: Client pixel format depth 6 (8bpp) rgb222

Thu Jan 8 09:26:29 2009
VNCSConnST: Client pixel format depth 24 (32bpp) little-endian rgb888

Thu Jan 8 09:26:30 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:32 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:34 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:36 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:39 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:41 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:43 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:45 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:47 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:50 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:52 2009
Timer: time has moved forwards!

Thu Jan 8 09:26:54 2009
Connections: closed: 192.168.13.160::48939 (write: Broken pipe (32))
SMsgWriter: framebuffer updates 12
SMsgWriter: hextile rects 145, bytes 19473667
SMsgWriter: ZRLE rects 1, bytes 12999
SMsgWriter: raw bytes equivalent 42738404, compression ratio 2.193213
~Image called - usingShm 0

效率相当低下,而且显示有严重问题
vnc-desktop-x0vncserver.png


10. vncconfig
修改vnc服务器一些配置什么的

以同样用户运行vncconfig, 列出所有参数
vncconfig -display :1 -list
[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -list
localhost
desktop
rfbport
rfbwait
httpPort
httpd
rfbauth
QueryConnectTimeout
AlwaysSetDeferUpdateTimer
DeferUpdate
Log
QueryConnect
SendCutText
AcceptCutText
AcceptPointerEvents
AcceptKeyEvents
DisconnectClients
NeverShared
AlwaysShared
Protocol3.3
CompareFB
ClientWaitTimeMillis
IdleTimeout
Password
PasswordFile
ReverseSecurityTypes
SecurityTypes
BlacklistTimeout
BlacklistThreshold
RemapKeys
ZlibLevel
MaxCutText
[mysql@Perf-pxy-2 ~]$


vncconfig也是个助手程序(helper application),只有运行了它,客户机和服务器之间才可以使用剪贴板复制粘贴数据


11. 反向连接

客户机监听端口, 等待服务器连接
vncviewer -listen
[root@CentOS-1 ~]# vncviewer -listen

VNC Viewer Free Edition 4.1.2 for X - built Mar 14 2007 22:51:02
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Fri Jan 9 11:21:28 2009
main: Listening on port 5500



服务器去连接客户机
vncconfig -display :1 -connect centos-1
[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -connect centos-1
[mysql@Perf-pxy-2 ~]$

客户机弹出远程桌面
vnc-reverse-connection.png

用完后断开连接
[mysql@Perf-pxy-2 ~]$ vncconfig -display :1 -disconnect
[mysql@Perf-pxy-2 ~]$


12. vnc中终端的环境变量
vnc中的terminal终端窗口(所有子进程)继承的是vnc服务器进程(父进程)的环境变量, 当修改了.bash_profile后, 再开启一个新的终端窗口并不能使环境变量生效
解决方法是将环境变量写入.bashrc,即可


13. 重新登录桌面
如果不小心登出(logout)了vnc的桌面, 那只有重启vnc服务.
Recovery from a logout这里有个办法,但是如果连这个终端也退出了, 一样没办法了





外部连接:

Auto-closing SSH tunnels
Native X display support
VNC
Virtual Network Computing
VNC for Unix Documentation - VNC Free Edition 4.1
VNC软件: RealVNC, UltraVNC, TightVNC





-fin-
Website Analytics

Followers