Management of oracle data guard

DataGuard off state
Enable the standby database:
SQL>STARTUP NOMOUNT;
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session; (synchronize but not apply logs in real time)
Close the standby database:
SQL>alter database recover managed standby database cancel;
SQL>shutdown immediate;
Open from closed state:
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database open read only;
Open read-only from recovery state:
SQL>
SQL>
SQL>alter database recover managed standby database using current logfile disconnect from session; (synchronize and apply logs in real time)
 
------------------------------------------------------------------------
Switching of the main and standby databases:
Main library:
SQL>alter database commit to switchover to physical standby;
SQL>shutdown immediate;
SQL>startup nomount;
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session;
Standby library:
SQL>alter  database commit to switchover to primary;
SQL>shutdown immediate;
SQL>startup;
------------------------------------------------------------------
 
Abnormal switching: (when the main library is down) start fallover
Standby library:
SQL>alter database recover managed standby database finish;
SQL>alter database commit to switchover to primary;
SQL>shutdown immediate;
SQL>startup;
-----------------------------------------------------------------
Routine maintenance commands: 
Query database status:
SQL>select instance_name,status from v$instance;
 
Query the active and standby databases:
SQL> select database_role from v$database;
 
Check the switchable state of the database:
SQL>
select switchover_status from v$database;
 
To archive a log:
alter system switch logfile;
 
Query whether archived logs are applied:
SQL> select sequence#,dest_id,first_time,next_time,archived,applied from v$archived_log;
 
Check whether the standby database is synchronized with the main database:
SQL> select archived_thread#,archived_seq#,applied_thread#,applied_seq# from v$archive_dest_status;
 
Query log shipping status:
SQL> select * from v$archive_gap;
 
Query the running status of the current host:
SQL> select switchover_status,database_role,protection_mode from v$database;
 
View some process conditions and process IDs of the current standby database
SQL> select process,status,thread#,sequence#,block#,blocks from v$managed_standby;
 
View sync error conditions:
SQL> select error from v$archive_dest;
 
Verify the passed archive:
SQL> select sequence#,first_time,next_time,applied,completion_time from v$archived_log order by sequence#;
 
Query whether the maximum serial numbers of the archive files of the active and standby databases are the same;
SQL> select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;
 
------------------------------------------------------------------
 
Detailed explanation of the switching of the main and standby databases:
 
 
Main library side:
Check the switchable state of the database:
SQL>
select switchover_status from v$database;
 
If it is TO STANDBY, it can be switched normally,
alter database commit to switchover to physical standby;
If it is SESSIONS ACTIVE, it means that a session is currently in the ACTIVE state.
alter database commit to switchover to physical standby with session shutdown;
After the operation is completed, the main database is modified to the standby database
 
 
 
Standby side:
Restart the main library
shutdown immediate;
startup mount;
 
Query the switchable status of the standby database:
select switchover_status from v$database;
 
If it is TO PRIMARY, it can be switched normally,
alter  database commit to switchover to primary;
If SESSIONS ACTIVE then:
alter  database  commit  to switchover  to primary  with session shutdown ;
After running, the backup library becomes the main library:
 
----------------------------------------------------------------------
Main library open log:
SQL>
show parameter log_archive_dest_state_;
alter system set log_archive_dest_state_2=enable scope=both;
-------------------------------------------------------------------
Open the standby database
SQL>
alter database recover managed standby database using current logfile disconnect from session;
alter database recover managed standby database cancel;
alter database open;
alter database recover managed standby database using current logfile disconnect from session;
 
--------------------------------------------------------------------------
View the protection mode of the database:
select DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database;
Maximum protection: ensure that the main library writes at the same time as the standby library, (MAXIMUM PROTECTION)
Highest Availability: Provides maximum protection of data without affecting the main library, (MAXIMUM AVAILABILITY)
Highest performance: not synchronous writing, almost synchronous (MAXIMUM PERFORMANCE) in a good network environment
 
Modify protected mode:
alter system set log_archive_dest_2="SERVICE=DG2 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DG2";
 
 
 
 
 
1. Query the number of connections to oracle
select count(*) from v$session;
2. Query the number of concurrent connections to oracle
select count(*) from v$session where status='ACTIVE';
3. View the number of connections of different users
select username,count(username) from v$session where username is not null group by username;
4. View all users:
select * from all_users;
5. View user or role system permissions (system permissions directly assigned to users or roles):
select * from dba_sys_privs;
select * from user_sys_privs;
6. View the permissions contained in the role (only the roles owned by the logged-in user can be viewed)
select * from role_sys_privs;
7. View user object permissions:
select * from dba_tab_privs;
select * from all_tab_privs;
select * from user_tab_privs;
8. View all roles:
select * from dba_roles;
9. View the roles owned by a user or role:
select * from dba_role_privs;
select * from user_role_privs;
10. Check which users have sysdba or sysoper system permissions (requires corresponding permissions when querying)
select * from V$PWFILE_USERS;
 
 
 
 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324801106&siteId=291194637