Tibero备用集群(Tibero Standby Cluster)
Tibero备用集群提供高可用性、数据保护和灾难恢复,是Tibero的核心功能。
Tibero备用服务器使用物理上独立的事务单元维护源数据的副本。拥有源数据的数据库称为主数据库(以后称为主数据库),保存复制数据的数据库称为备用数据库(以后称为备用数据库)。
后台进程将主数据库创建的重做日志传输给备用数据库,每个备用数据库使用重做日志将主数据库的所有更改应用于自己。
下图展示了Tibero备用集群的工作方式:
Tibero Standby Cluster's Operation
当主服务器无法处理服务请求的数据时,Tibero使用备用数据库快速重新启动服务。即使主服务器的一个磁盘损坏了,并且很难恢复,Tibero也会用备用数据库保护损坏的数据。
Tibero Standby Cluster has the following processes:
-
Records Redo logs that were transmitted from Primary to Standby databases in the online Redo log file.
Standby databases operate in RECOVERY boot mode, not in MOUNT or NORMAL. While Standby databases are operating, LNR is used instead of a log writer (LGWR). LNR works as a thread of the RCWP process.
-
SMR (Standby Managed Recovery)
Performs the recovery process by reading the online redo log and applying it to Standby databases. SMR works as a thread of the RCWP process.
-
进程
Tibero备用集群有以下过程:
LNW(日志网络写进程)
将重做日志从主数据库传输到备用数据库。
不管日志传输方法是什么,日志的实际发送总是在LNW中执行。
每个备用服务器都存在一个LNW实例。最多可以有9个备用数据库。
LNR(日志网络读进程)
在线重做日志文件中从主数据库传输到备用数据库的记录重做日志。
备用数据库在恢复启动模式下运行,而不是在MOUNT或NORMAL模式下。当备用数据库运行时,使用LNR而不是日志写入器(LGWR)。LNR是RCWP进程的一个线程。
-
SMR(备用管理恢复)
-
通过读取联机重做日志并将其应用于备用数据库来执行恢复过程。SMR是RCWP进程的一个线程。
-
Log transmission from Primary to Standby databases is performed as follows:
Primary Settings and Operations主要设置与操作
Primary的操作方式如下:
Operation Mode | Description |
---|---|
保护模式 |
Primary must connect to one or more Standby databases which receive Redo log files with LGWR SYNC. When Primary sends a Redo log file to Standby databases, LGWR needs to receive at least one successful reply from a Standby database. If LGWR does not receive a successful reply from any Standby, Primary will terminate. 主数据库必须连接到一个或多个备用数据库,这些备用数据库使用LGWR同步接收重做日志文件。 当主服务器向备用数据库发送重做日志文件时,LGWR需要从备用数据库接收至少一个成功的应答。如果LGWR没有从任何备用服务器接收到成功的应答,主服务器将终止。 |
最大可用性模式 |
Primary must connect to one or more Standby databases which receive Redo log files with LGWR SYNC. If LGWR does not receive a successful reply from any Standby database, the Primary will not try to send a Redo log file, but it will not terminate. 主数据库必须连接到一个或多个备用数据库,这些备用数据库使用LGWR同步接收重做日志文件。 如果LGWR没有从任何备用数据库接收到成功的应答,主数据库将不会尝试发送重做日志文件,但它不会终止。 |
性能模式 |
Primary can use any log transmission method. Even if LGWR does not receive a successful reply from any Standby database, the Primary will not terminate. 主要可以使用任何日志传输方法。即使LGWR没有从任何备用数据库接收到成功的应答,主数据库也不会终止。 |
Primary's operation mode, Standby databases that will connect to Primary, and the log transmission method for each Standby can be specified with the following file:
<$TB_SID.tip>
LOG_REPLICATION_MODE = {PROTECTION|AVAILABILITY|PERFORMANCE} LOG_REPLICATION_DEST_1 = "hostname_1:port_1 {LGWR SYNC|LGWR ASYNC|ARCH ASYNC}" LOG_REPLICATION_DEST_2 = "hostname_2:port_2 {LGWR SYNC|LGWR ASYNC|ARCH ASYNC}" ... LOG_REPLICATION_DEST_N = "hostname_N:port_N {LGWR SYNC|LGWR ASYNC|ARCH ASYNC}"
The initialization parameters specified in the above file are as follows:
replication 复制,回答,反响
-
This determines if the focus is on protecting data or on maximizing efficiency. It only needs to be specified once.
- 这决定了重点是保护数据还是最大化效率。只需要指定一次。
-
The values that can be specified in this parameter are as follows:
Value Description PROTECTION If there are no Standby databases to receive Redo log files with LGWR SYNC, an initialization error will occur. To solve this error, connect to one or more Standby databases with LGWR SYNC and restart Primary.
如果没有备用数据库来接收LGWR同步的重做日志文件,就会发生初始化错误。要解决此错误,请使用LGWR同步连接到一个或多个备用数据库并重新启动主数据库。
AVAILABILITY If there are no Standby databases to receive Redo log files with LGWR SYNC, an initialization error will occur. To solve this error, connect to one or more Standby databases with LGWR SYNC and restart Primary. PERFORMANCE This does not guarantee synchronization between the Primary and Standby databases, but can improve system performance.
这并不能保证主数据库和备用数据库之间的同步,但可以提高系统性能。
-
This determines the log transmission method and connection information (hostname:port) for each Standby. The maximum number (N) of Standby databases that can be specified is nine. Specify this parameter as many times as is needed, starting with LOG_REPLICATION_DEST_1.
-
The port number in the connection information is set to LISTENER_PORT + 4 by default and can be modified using a relevant parameter.
这将确定每个备用服务器的日志传输方法和连接信息(主机名:端口)。可以指定的备用数据库的最大数目(N)是9。根据需要多次指定该参数,从LOG_REPLICATION_DEST_1开始。
连接信息中的端口号默认设置为LISTENER_PORT + 4,可以使用相关参数进行修改。
-
The values that can be specified in this parameter are as follows:
Value Description LGWR SYNC Standby databases which receive Redo log files with this method operate by receiving information from the Redo buffer of Primary. Because they receive Redo log files most frequently with this method, this method provides the most data protection but lowers Primary's performance. Building the Primary and Standby databases with similar hardware specifications is recommended.
This method can be used in PERFORMANCE mode. In this mode, Primary continues to operate even if data is not protected. Therefore, it is recommended to operate Primary in ARCHIVELOG mode if a Standby has low performance because Redo logs in an online Redo log file or an archive log file can be read and transferred in this mode.
使用此方法接收重做日志文件的备用数据库通过从主数据库的重做缓冲区接收信息进行操作。由于使用此方法最频繁地接收重做日志文件,因此此方法提供了最多的数据保护,但降低了主服务器的性能。建议使用类似的硬件规范构建主数据库和备用数据库。
该方法可用于性能模式。在此模式下,即使数据不受保护,Primary也会继续操作。因此,如果备用服务器的性能较低,建议以ARCHIVELOG模式操作主服务器,因为可以在这种模式下读取和传输在线重做日志文件或归档日志文件中的重做日志。
LGWR ASYNC
LGWR异步
Standby databases receive Redo log files with this method more frequently than with ARCH ASYNC but less frequently than with LGWR SYNC.
It is recommended to operate Primary in ARCHIVELOG mode if a Standby has low performance because archive log files can instead be read and transferred.
备用数据库使用此方法接收重做日志文件的频率比使用ARCH异步方法高,但比使用LGWR同步方法低。
如果备用服务器的性能较低,建议以ARCHIVELOG模式操作主服务器,因为归档日志文件可以被读取和传输。
ARCH ASYNC
归档异步
If one or more Standby databases which receive Redo log files with this method exist, Primary must operate in ARCHIVELOG mode. If not, a corresponding server normally starts, but corresponding Standby databases does not operate.
ARCHIVELOG模式下操作。如果没有,对应的服务器通常启动,但是对应的备用数据库不运行。
-
Dynamically add a standby database while a primary database operates. Use the following SQL statements.
在主数据库运行时动态添加备用数据库。使用以下SQL语句。
-
sql> alter system set LOG_RELICATION_MODE={PROTECTION|AVAILABILITY|PERFORMANCE} sql> alter system set LOG_REPLICATION_DEST_1 = "hostname_1:port_1 {LGWR SYNC|LGWR ASYNC|ARCH ASYNC}" sql> alter system set LOG_RELICATION_1_ENABLE=Y; (If set to N, synchronization mode is disabled.)
Configuring and Operating Standby Databases
The followings tasks should be completed to operate a Standby:
-
Copy the backup files from Primary and configure Standby.
Copy all data files, including control files, online log files, and password files. The password file is necessary because Primary has SYS authority for Standby so their SYS passwords must match.
-
Open Standby's $TB_SID.tip file and modify DB_NAME to be the same as Primary.
-
Check that the control file path in the $TB_SID.tip file is the same as the path where the Primary files were copied.
DB_BLOCK_SIZE
should also be the same as Primary to be able to open the copied data files.If the Standby directory path to the backup is different, change the information for the path in Standby's $TB_SID.tip file as shown below:
配置和操作备用数据库
操作备用系统须完成下列工作:
1 从主服务器复制备份文件并配置备用服务器。
复制所有数据文件,包括控制文件、在线日志文件和密码文件。密码文件是必要的,因为主系统有备用的SYS权限,所以它们的SYS密码必须匹配。
2 打开备用TB_SID美元。提示文件,并将DB_NAME修改为与主服务器相同。
3 检查$TB_SID中的控制文件路径。tip文件与复制主文件的路径相同。
DB_BLOCK_SIZE也应该与主服务器相同,以便能够打开复制的数据文件。
如果备份的备用目录路径不同,请更改备用目录$TB_SID中的路径信息。提示文件如下:
Changing the $TB_SID.tip File Path in Standby
STANDBY_FILE_NAME_CONVERT="Primary's abosolute path, Standby's absolute path"
主数据库和备用数据库的绝对路径是主实例目录和备用实例目录的绝对路径。
4 After starting up Standby in MOUNT mode and executing the following DDL, the database is set to the Standby mode and the changed path will be set in the control file.
Standby Control File Configuration
SQL> ALTER DATABASE Standby controlfile;
如果在更改路径时未执行此步骤,则在启动时将出现数据文件无法按控制文件中指定的路径打开的错误。
5 准备工作完成后,使用以下命令将数据库引导为备用。
Starting Up Standby
$ tbboot -t RECOVERY
Standby Read-Only Mode
Users cannot access a Standby because the server runs in the RECOVERY mode, which writes redo logs received from the Primary and recovers and applies them to the data file.
To continue to read from the Standby while it is applying redo logs as for a Standby in read only cluster, execute the following DDL statement to allow the Standby to continue to perform recovery while allowing read only session requests.
用户无法访问备用服务器,因为服务器运行在恢复模式中,该模式将写入从主服务器接收到的重做日志,并将其恢复并应用到数据文件。
对于只读集群中的备用服务器,在它对其应用重做日志时,要继续从备用服务器读取数据,请执行以下DDL语句,以允许备用服务器在允许只读会话请求的同时继续执行恢复。
Standby Read-Only Continue Recovery
SQL> alter database open read only continue recovery;
If the Standby is synchronized with the Primary in LGWR SYNC mode, recently committed changes can be seen in Standby as in the Primary. Note that data can be changed even though the database is in read-only mode.
Execute the following DDL to change back from Standby to RECOVERY mode.
Database Role Switchover 数据库角色转换
To change a Standby into Primary, do the following after shutting down the Primary in SWITCHOVER mode:
若要将备用设备更改为主设备,请在切换模式下关闭主设备后执行以下操作:
-
Execute the following command on the Primary:
Switchover Command Execution
$ tbdown -t SWITCHOVER
在主服务器中创建的所有重做日志都被传输到备用服务器,然后主服务器像在正常模式下一样关闭。
2 在关闭备用服务器后,使用故障转移模式引导,使备用服务器成为新的主服务器。
要使用前面的主服务器作为新的备用服务器,在$TB_SID中配置初始化参数LOG_REPLICATION_MODE和LOG_REPLICATION_DEST_n。提示文件的新主数据库。在恢复模式下启动前一个主服务器,然后在故障转移模式下启动新主服务器,以切换它们的角色。
这两个数据库已经处于同步状态,因此在最初配置备用数据库和执行ALTER database备用控制文件时需要从新主数据库复制数据库文件。另外,即使先前的与备用相关的配置仍然保留在$TB_SID中。提示文件,它只在数据库正常模式下使用。
All Redo logs that have been created in the Primary are transmitted to Standby, and then the Primary is shut down like in NORMAL mode.
2 After shutting down a Standby, boot using FAILOVER mode to make the Standby the new Primary server.
LOG_REPLICATION_MODE
andLOG_REPLICATION_DEST_n
in the $TB_SID.tip file of the new Primary database. Boot the previous Primary in RECOVERY mode, and then boot the new Primary in FAILOVER mode to switch their roles.The two databases are already in a synchronized state, so the copying of the database files from the new Primary that was required when originally configuring the Standby and the executing of the ALTER DATABASE Standby control fileare not necessary. Also, even though the previous Standby-related configuration remains in the $TB_SID.tip file of the new Standby, it is only used when the database operates in NORMAL mode.
Failover 故障转移
If Primary terminates abnormally or is inaccessible, one of the Standby databases can be used as Primary. To use a Standby as Primary, reboot the Standby in FAILOVER mode.
To start a Standby database that uses _USE_STANDBY_REDO_LOG in FAILOVER mode, start it without changing the _USE_STANDBY_REDO_LOG parameter.
Note
The existing Primary cannot be included in a Tibero Standby Cluster as a Primary or as a Standby after a new Primary is operating.
如果主数据库非正常终止或无法访问,可以使用一个备用数据库作为主数据库。若要将备用作为主服务器,请在故障转移模式下重新启动备用服务器。
要在故障转移模式下启动使用_USE_STANDBY_REDO_LOG的备用数据库,请在不更改_USE_STANDBY_REDO_LOG参数的情况下启动它。
请注意
现有主服务器不能作为主服务器或在新主服务器运行后作为备用服务器包含在Tibero备用集群中。
To access both Primary and Standby, specify the access information of each DB in the tbdsn.tbr file as shown below:
<tbdsn.tbr>
PrimaryDB_SID=( (INSTANCE=(HOST=primaryDB_hostname) (PORT=primaryDB_port) (DB_NAME=cluster_DB_NAME) ) ) StandbyDB_SID=( (INSTANCE=(HOST=StandbyDB_hostname) (PORT=StandbyDB_port) (DB_NAME=cluster_DB_NAME) ) )
For each SID, write the DB_NAME that was used when configuring the $TB_SID.tip file for Primary and each Standby.
A standby Redo log group is an online log group that can be used only for standby databases. When log switch occurs, checkpoints of logs to reuse are not checked, and only whether to archive the logs is checked.
Restore a backup set, and then perform the following to use standby Redo log groups.
备用重做日志组是只能用于备用数据库的在线日志组。当日志切换发生时,不检查要重用的日志检查点,只检查是否归档日志。
还原备份集,然后执行下列操作以使用备用重做日志组。
-
Set the following in a tip file.
_USE_STANDBY_REDO_LOG=Y
-
Execute the following statements.
sql> alter database standby controlfile; sql> alter database add standby logfile group 1 '$DEST_DIR/0001.slf' size 100M; (The size must be the same as the online log file size in the Primary database.) sql> alter database add standby logfile group 2 '$DEST_DIR/0002.slf' size 100M; sql> alter database add standby logfile group 3 '$DEST_DIR/0003.slf' size 100M; sql> alter database add standby logfile group 4 '$DEST_DIR/0004.slf' size 100M; sql> alter database add standby logfile group 5 '$DEST_DIR/0005.slf' size 100M; sql> alter database add standby logfile group 6 '$DEST_DIR/0006.slf' size 100M; (The group count can be arbitrary, but 2 times of online log count in the Primary database is recommended.) sql> alter database enable public standby redo thread 0; sql> alter database recover automatic for standby;
-
Ends the database and reboots it in Recovery mode.
Viewing Tibero Standby Cluster Data
Tibero provides the dynamic views shown below to view the data about a Tibero Standby Cluster's status.
Because Tibero Standby Cluster transfers Redo logs created by Primary to Standby databases without any changes, the system environment, such as the CPU bus size, endianness, OS, and the size of database blocks in the $TB_SID.tip files in Primary and the Standby must be the same.
由于Tibero备用集群将主数据库创建的重做日志传输到备用数据库而不做任何更改,所以系统环境,例如CPU总线大小、endianness、OS和$TB_SID中的数据库块大小。主服务器和备用服务器中的提示文件必须相同。
As a property of a Standby Cluster that applies Redo logs, some DDL that modify the state of a tablespace or database file are not allowed. These operations must be performed without Standby. In other words, a database must be backed up before applying it to Standby.
作为应用重做日志的备用集群的一个属性,一些修改表空间或数据库文件状态的DDL是不允许的。这些操作必须在没有备用的情况下执行。换句话说,在将数据库应用到备用数据库之前,必须对其进行备份。
The following operations are not supported by Standby clusters. DPL and DPI are not supported in previous versions because they do not leave logs, but now they are supported because they leave logs when connecting to Standby.
备用集群不支持以下操作。以前的版本不支持DPL和DPI,因为它们不留下日志,但是现在支持它们,因为它们在连接到备用时留下日志。
-
DDL that modifies portions of a tablespace 修改表空间部分的DDL
ALTER TABLESPACE READ ONLY ALTER TABLESPACE READ WRITE
-
DDL that modifies portions of a database
ALTER DATABASE ADD LOGFILE ALTER DATABASE DROP LOGFILE ALTER DATABASE TEMPFILE ALTER DATABASE RENAME FILE
-
Creates GLOBAL TEMP TABLE
CREATE GLOBAL TEMPORARY TABLE