Restoring the Server Parameter File

Oracle数据库SPFILE恢复指南
当Oracle数据库的SPFILE丢失或损坏时,可以通过PFILE重建或者从RMAN备份中恢复。本文详细介绍了如何在不同情况下使用RMAN进行SPFILE恢复,包括从自动备份中恢复的步骤,并提供了示例命令。在恢复过程中,可能需要指定DBID、设置恢复日期、选择备份位置等。恢复完成后,可创建PFILE指定SPFILE位置以重启数据库。

SPFILE损坏或丢失不是大问题,可通过PFILE重建,如果PFILE也丢失就从alert log中复制一份。但如果RMAN备份了SPFILE,就可以通过RMAN来恢复

恢复SPFILE分以下情况

Note the following considerations when restoring the server parameter file:

  1. 如果数据库已使用SPFILE启动

If the instance is already started with the server parameter file, then you cannot overwrite the existing server parameter file.

  1. 如果数据库已使用PFILE启动

When the instance is started with a client-side initialization parameter file, RMAN restores the server parameter file to the default location if the TO clause is not used in the restore command. The default location is platform-specific, for example, ?/dbs/spfile.ora on Linux.

  1. 如果使用了catalog

A recovery catalog simplifies the recovery procedure because you can avoid recording and remembering the DBID. This procedure assumes that you are not using a recovery catalog.

To restore the server parameter file from autobackup:

  1. Start RMAN and do one of the following:

如果SPFILE丢失时数据库启动中可直接连接;如果未启动则需要连接后并指定DBID

If the database instance is started at the time of the loss of the server parameter file, then connect to the target database.

If the database instance is not started when the server parameter file is lost, and if you are not using a recovery catalog, then run the SET DBID command to set the DBID of the target database:

SET DBID 320066378;

  1. Shut down the database instance and restart it without mounting the database.

这时数据库会用一个假的parameter file启动到nomount

When the server parameter file is not available, RMAN starts the instance with a dummy parameter file. For example, enter the following command:

STARTUP FORCE NOMOUNT;

  1. Execute a RUN command to restore the server parameter file.

Depending on the situation, you may need to execute multiple commands in the RUN command. Note the following considerations:

  1. If restoring from tape, then use ALLOCATE CHANNEL to allocate an SBT channel manually. If restoring from disk, then RMAN uses the default disk channel.
  2. If the autobackups were not produced with the default format (%F), then use the SET CONTROLFILE AUTOBACKUP FOR DEVICE TYPE command to specify the format in effect when the autobackup was performed.
  3. If the most recent autobackup was not created today, then use SET UNTIL to specify the date from which to start the search.
  4. If RMAN is not connected to a recovery catalog, then use SET DBID to set the DBID for the target database.
  5. To restore the server parameter file to a nondefault location, specify the TO clause or TO PFILE clause on the RESTORE SPFILE command.
  6. If you know that RMAN never produces more than n autobackups each day, then you can set the RESTORE SPFILE FROM AUTOBACKUP ... MAXSEQ parameter to n to reduce the search time. MAXSEQ is set to 255 by default, and RESTORE counts backward from MAXSEQ to find the last backup of the day. To terminate the restore operation if you do not find the autobackup in the current day (or specified day), set MAXDAYS 1 on the RESTORE command.

示例

RUN {

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS ...;

  SET UNTIL TIME 'SYSDATE-7';

  SET CONTROLFILE AUTOBACKUP FORMAT

    FOR DEVICE TYPE sbt TO '/disk1/control_files/autobackup_%F';

  SET DBID 123456789;

  RESTORE SPFILE TO '/tmp/spfileTEMP.ora' FROM AUTOBACKUP MAXDAYS 10; }

注如果使用指定备份没必要指定DBID来恢复,如

RMAN> restore spfile from '/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp';

  1. Restart the database instance with the restored file.

如果SPFILE不在默位置可以手动创建一个PFILE文件,在PFILE文件中指定SPFILE选项

If you are restarting RMAN with a server parameter file in a nondefault location, then create an initialization parameter file with the line SPFILE=new_location, where new_location is the path name of the restored server parameter file. Then, restart the instance with the client-side initialization parameter file.

For example, create a file /tmp/init.ora which contains the single line:

SPFILE=/tmp/spfileTEMP.ora

You can use the following RMAN command to restart the instance with the restored server parameter file:

STARTUP FORCE PFILE=/tmp/init.ora;

示例:

  1. RMAN配置

RMAN> configure controlfile autobackup on;

  1. 全备  

RMAN> BACKUP DATABASE ARCHIVELOG ALL;

  1. 查看DBID

SQL> select dbid from v$database;    --1514939295

  1. 查看是否有SPFILE备份

RMAN> list backup of spfile;    

List of Backup Sets

===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    

------- ---- -- ---------- ----------- ------------ -------------------

15      Full    9.36M      DISK        00:00:00     2018-09-18 21:37:13

        BP Key: 15   Status: AVAILABLE  Compressed: NO  Tag: TAG20180918T213713

        Piece Name:

/oracle/fast_recovery_area/ORCL/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp

  SPFILE Included: Modification time: 2018-09-18 21:34:42

  SPFILE db_unique_name: ORCL

  1. 关闭数据库模拟SPFILE丢失 

SQL> shutdown immediate 

$ mv spfileorcl.ora spfileorcl.old

$ mv initorcl.ora initorcl.old

  1. RMAN启动到NOMOUNT

$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue Sep 18 21:13:42 2018

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

connected to target database (not started)

RMAN> startup nomount;

注:没有参数文件SQL*PLUS是无法启动到NOMOUNT,但RMAN可以

  1. 恢复SPFIEL

方式一:使用自动备份的spfile,但需要指定dbid

RMAN> set dbid=1514939295;

RMAN> restore spfile from autobackup;

方式二:直接指定备份集,不需要指定dbid

RMAN> restore spfile from '/oracle/fast_recovery_area/ORCL/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp';

  1. 关闭数据库重启启动

RMAN> SHUTDOWN IMMEDIATE;

RMAN> STARTUP;

Options: --networkMessageCompressors arg (=snappy,zstd,zlib) Comma-separated list of compressors to use for network messages General options: -h [ --help ] Show this usage information --version Show version information -f [ --config ] arg Configuration file specifying additional options --configExpand arg Process expansion directives in config file (none, exec, rest) --port arg Specify port number - 27017 by default --ipv6 Enable IPv6 support (disabled by default) --listenBacklog arg Set socket listen backlog size --maxConns arg (=1000000) Max number of simultaneous connections --pidfilepath arg Full path to pidfile (if not set, no pidfile is created) --timeZoneInfo arg Full path to time zone info directory, e.g. /usr/share/zoneinfo -v [ --verbose ] [=arg(=v)] Be more verbose (include multiple times for more verbosity e.g. -vvvvv) --quiet Quieter output --logpath arg Log file to send write to instead of stdout - has to be a file, not directory --logappend Append to logpath instead of over-writing --logRotate arg Set the log rotation behavior (rename|reopen) --timeStampFormat arg Desired format for timestamps in log messages. One of iso8601-utc or iso8601-local --setParameter arg Set a configurable parameter --extensions arg Specify paths to extensions to load --bind_ip arg Comma separated list of ip addresses to listen on - localhost by default --bind_ip_all Bind to all ip addresses --noauth Run without security --transitionToAuth For rolling access control upgrade. Attempt to authenticate over outgoing connections and proceed regardless of success. Accept incoming connections with or without authentication. --slowms arg (=100) Value of slow for profile and console log --slowTaskWaitTimeProfilingMs arg (=50) Value of slow wait time for tasks --slowOpSampleRate arg (=1) Fraction of slow ops to include in the profile and console log --profileFilter arg Query predicate to control which operations are logged and profiled --auth Run with security --clusterIpSourceAllowlist arg Network CIDR specification of permitted origin for `__system` access --profile arg 0=off 1=slow, 2=all --cpu Periodically show cpu and iowait utilization --sysinfo Print some diagnostic system information --noscripting Disable scripting engine --notablescan Do not allow table scans --proxyPort arg The port that accepts connections with a proxy protocol header. --keyFile arg Private key for cluster authentication --clusterAuthMode arg Authentication mode used for cluster authentication. Alternatives are (keyFile|sendKeyFile|sendX509|x509) Replication options: --oplogSize arg Size to use (in MB) for replication op log. default is 5% of disk space (i.e. large is good) Replica set options: --replSet arg arg is <setname>[/<optionalseedhostlist >] --replSetName arg arg is <setname> Serverless mode: --serverless arg Serverless mode implies replication is enabled, cannot be used with replSet or replSetName. Sharding options: --configsvr Assigns the config-server role to this node in a sharded cluster. The default listening port is 27019 and the default database directory is /data/configdb. --shardsvr Assigns the shard-server role to this node in a sharded cluster. The default listening port is 27018. --routerPort [=arg(=27016)] Assigns the router role to this node in a sharded cluster, and results in listening to a dedicated port (27016 by default) to serve routing requests. --maintenanceMode arg Allows this node to skip starting up sharding components or both replication and sharding components. This allows for performing maintenance on this node. To skip setting up just sharding components use --maintenanceMode=replic aSet. To skip setting up both sharding and replication components use --maintenanceMode=standalone. --replicaSetConfigShardMaintenanceMode Bypasses validation of configuration mismatches between startup parameters and the stored replSetConfig. Enables restarting the node as a configsvr even if the stored configuration is for a replica set, and vice versa. Storage options: --storageEngine arg What storage engine to use - defaults to wiredTiger if no data files present --dbpath arg Directory for datafiles - defaults to \data\db\ which is C:\data\db\ based on the current working drive --directoryperdb Each database will be stored in a separate directory --syncdelay arg Seconds between disk syncs --journalCommitInterval arg how often to group/batch commit (ms) --upgrade Upgrade db if needed --repair Run repair on all dbs --validate Run validation on all collections --restore This should only be used when restoring from a backup. Mongod will behave differently by handling collections with missing data files, allowing database renames, skipping oplog entries for collections not restored and more. --oplogMinRetentionHours arg (=0) Minimum number of hours to preserve in the oplog. Default is 0 (turned off). Fractions are allowed (e.g. 1.5 hours) TLS Options: --tlsOnNormalPorts Use TLS on configured ports --tlsMode arg Set the TLS operation mode (disabled|allowTLS|preferTLS|requireTLS ) --tlsCertificateKeyFile arg Certificate and key file for TLS. Certificate is presented in response to inbound connections always. Certificate is also presented for outbound connections if tlsClusterFile is not specified. --tlsCertificateKeyFilePassword arg Password to unlock key in the TLS certificate key file --tlsClusterFile arg Certificate and key file for internal TLS authentication. Certificate is presented on outbound connections if specified. --tlsClusterPassword arg Internal authentication key file password --tlsCAFile arg Certificate Authority file for TLS. Used to verify remote certificates presented in response to outbound connections. Also used to verify remote certificates from inbound connections if tlsClusterCAFile is not specified. --tlsClusterCAFile arg CA used for verifying remotes during inbound connections --tlsCRLFile arg Certificate Revocation List file for TLS --tlsDisabledProtocols arg Comma separated list of TLS protocols to disable [TLS1_0,TLS1_1,TLS1_2,TLS1_3 ] --tlsAllowConnectionsWithoutCertificates Allow client to connect without presenting a certificate --tlsAllowInvalidHostnames Allow server certificates to provide non-matching hostnames --tlsAllowInvalidCertificates Allow connections to servers with invalid certificates --tlsCertificateSelector arg TLS Certificate in system store --tlsClusterCertificateSelector arg SSL/TLS Certificate in system store for internal TLS authentication --tlsLogVersions arg Comma separated list of TLS protocols to log on connect [TLS1_0,TLS1_1,TLS1_2 ,TLS1_3] --tlsClusterAuthX509ExtensionValue arg If specified, clients who expect to be regarded as cluster members must present a valid X.509 certificate containing an X.509 extension for OID 1.3.6.1.4.1.34601.2.1.2 which contains the specified value. --tlsClusterAuthX509Attributes arg If specified, clients performing X.509 authentication must present a certificate with a subject name with the exact attributes and values provided in this config option to be treated as peer cluster nodes. AWS IAM Options: --awsIamSessionToken arg AWS Session Token for temporary credentials WiredTiger options: --wiredTigerCacheSizeGB arg Maximum amount of memory to allocate for cache in GB; Defaults to 1/2 of physical RAM. Only one of either wiredTigerCacheSizePct or wiredTigerCacheSizeGB can be provided --wiredTigerCacheSizePct arg Maximum amount of memory to allocate for cache as a percentage of physical RAM; Defaults to 1/2 of physical RAM and a minimum of 256MB. Only one of either wiredTigerCacheSizePct or wiredTigerCacheSizeGB can be provided --zstdDefaultCompressionLevel arg (=6) Default compression level for zstd compressor --wiredTigerJournalCompressor arg (=snappy) Use a compressor for log records [none|snappy|zlib|zstd] --wiredTigerDirectoryForIndexes Put indexes and data in different directories --wiredTigerLiveRestoreSource arg Path to the source for live restore. --wiredTigerLiveRestoreThreads arg (=8) Number of live restore background threads. --wiredTigerLiveRestoreReadSizeMB arg (=1) 'The read size for data migration, in MB, must be a power of two. This setting is a best effort. It does not force every read to be this size.' --wiredTigerCollectionBlockCompressor arg (=snappy) Block compression algorithm for collection data [none|snappy|zlib|zstd] --wiredTigerIndexPrefixCompression arg (=1) Use prefix compression on row-store leaf pages Windows Service Control Manager options: --install Install Windows service --remove Remove Windows service --reinstall Reinstall Windows service (equivalent to --remove followed by --install) --serviceName arg Windows service name --serviceDisplayName arg Windows service display name --serviceDescription arg Windows service description --serviceUser arg Account for service execution --servicePassword arg Password used to authenticate serviceUser
最新发布
11-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值