Bright DBA

ORACLE DBA – Tips and Techniques

Skip to content
  • Home
  • DBA Monitor
    • Scripts
      • DBA Sheet v6.1
      • DBA Sheet v7.0
      • DBA Daily Report
      • Generate INSERT statements from the SELECT query
      • Generate INSERT statements to a flat file using a PL/SQL query
    • OS
    • DATABASE
    • NETWORK
    • STORAGE
  • Oracle
    • DB-Install
      • Install 10g
      • Install Oracle Software in silent mode 11gR2
      • Deinstall Oracle 11gR2 Database binaries
      • Uninstall Oracle Client on Windows
      • Create database -DBCA silent mode
      • Delete database -DBCA silent mode
      • Drop Database
      • Patch Terminology
    • DB-Admin
      • How to change SQL  prompt to show connected user and database name
      • Change Archive Dest
      • Enable Archivelog
      • How to Recover Loss of DATA – (Without a Backup!)
      • Configure OEM DBConsole manually
      • Proxy User
      • Database Link
      • DBMS_SCHEDULER
      • Enable/Disable JOBS during Maintenance
      • ORA-00054
      • Blocking Sessions
      • Create Service using DBMS_SERVICE
      • Error TNS-12543
      • Store DB credentials in Oracle Wallet
      • Under Edit
    • BACKUP
      • BACKUP ORACLE HOME AND INVENTORY
      • Datapump
        • SCHEMA REFRESH FROM 11G TO 12C PDB
      • RMAN
        • CATALOG
        • RMAN Database Restore RAC – RAC
        • RMAN Database Restore ASM – ASM
        • RMAN Database Restore from ASM to File System
        • RMAN ACTIVE DUPLICATION ASM TO ASM
        • Backup Based RMAN Duplicate Database
    • 12c/18c/19c
      • Install 12.2 Database Binaries in silent mode
      • Upgrade DB Manually 11.2.0.4 to 12.2.0.1
      • Upgrade DB using DBUA from 11.2.0.4 to 12.2.0.1
      • CREATE PDB USING SEED
      • CREATE NEW PDB BY CLONING AN EXISTING PDB
      • CREATE PDB USING DBCA
      • DROP PDB MANUALLY
      • Configure OEM Express 12c
      • CREATE NON-CDB ON ORACLE 12C IN SILENT MODE
      • Create Non-CDB on Oracle 12c using DBCA (GUI)
      • Convert Non-CDB to PDB with DBMS_PDB
      • SCHEMA REFRESH FROM 11G TO 12C PDB
      • STARTUP/SHUTDOWN CDB AND PDB
      • Apply RU on DATABASE 12.2
      • ROLLBACK RU from DATABASE 12.2
      • How to Change MAX_STRING_SIZE on Physical Standby Environment
      • 18C
        • Install 18c
        • Deinstall Oracle 18c Database Binaries
        • 18c DB Patching
      • Install 19c GUI
      • Install 19c in silent mode
      • Oracle 19c Deinstall
      • Create DB 19C – DBCA-GUI
      • Create DB 19C – DBCA-SILENT
      • Apply Patch RU on Database 19c
      • Upgrade Oracle Database from 12.2.0.1 to 19c using DBUA
      • Upgrade Oracle Database Manually from 12.2.0.1 to 19c
      • Rolling Upgrade With an Existing Physical Standby Database
      • Upgrade TIMEZONE Version
  • PT
    • Tuning Stage 1
      • Statistics
      • Oracle Histograms
      • Export/Import schema statistics
      • CONTROL MANAGEMENT PACK ACCESS
      • Generate Explain Plan
      • SQL Query is really hanged or not
    • Tuning Stage 2
      • STATSPACK
      • ASH
      • AWR
      • Colored SQL_ID
      • SYSAUX Tablespace
    • Tuning Stage 3
      • Troubleshooting Long Running Queries
      • SQL Tuning Advisor
      • SQLT
        • How to Install SQLT
        • How to Run SQLT
        • How to Create Custom SQL Profile
        • Uninstall SQLT
      • Tracing
      • TRCA – Trace Analyzer
  • HA
    • DG 11g
      • CONFIGURATION
        • Active Dataguard on Non-ASM
        • Active Dataguard on ASM
        • Convert Physical Standby Database to Snapshot Standby Database
        • Convert Snapshot Standby database to Physical Standby database
        • Configure Cascading Standby Database
        • DG Broker Configuration
        • DG Broker Error – ORA-16714
        • Disable DG Broker
      • SWITCHOVER
        • Switchover Manual No-Broker
        • Switchover with Broker
      • FAILOVER
        • Failover with Broker(No Flashback)
        • Failover with No Broker (No Flashback)
        • Failover with Broker using Flashback
        • Failover with No Broker using Flashback
      • Enable Real-Time Apply
      • Apply DB PSU on Standby
      • Refresh Standby Database using RMAN Incremental SCN Backup
      • Resetlogs on Primary where Standby in place
      • Drop SRL
    • DG 12c
      • 12.2 Active Dataguard in CDB on Non-ASM
      • Create Physical Standby using RMAN Backup Without Duplicate Command
      • Create Physical Standby using RMAN Backup with Duplicate Command
      • 12c DG Broker Configuration
      • Upgrade Database to 12.2 with Physical Standby
    • ASM
      • Move ASM Spfile to diff. DiskGroup
      • ASM Commands
      • Instantiating disk: failed
      • CSSD won’t start automatically
    • RAC
      • Create users, groups and Paths for Oracle RAC
      • Configure ASMLib for Oracle ASM
      • Configure UDEV Rules for Oracle ASM
      • RAC Install
        • RAC Install 11.2.0.3
        • Upgrade GI to 11.2.0.4
        • Downgrade GI to 11.2.0.3
        • root.sh failed with ORA-29783 on RAC
        • Delete Node
        • Add Node
        • Delete Node without remove software
        • Add Node Back which was DELETED without remove software
      • RAC Admin
        • How to take OCR backup on 11.2.0.4
        • Cluster Name
        • Move/Relocate OCR
        • Restore loss of all VOTE disk
        • Cluster Startup issues
        • Add SCAN
      • RAC Tools
        • CLUVFY
        • OSWatcher
      • RAC Standby 12.2
      • Create ACFS File System on RAC
  • Exa
    • CellCLI Commands
  • GG
    • GG 11g
      • GoldenGate Installation
      • Unidirectional DML Replication
      • Zero Downtime Migration
      • DDL Replication
    • GG 12C
      • GoldenGate 12C Installation
      • Integrated Capture
      • Oracle GoldenGate Heterogeneous Replication
      • Credential Store
      • ADD NEW TABLE TO AN EXISTING GOLDENGATE CONFIGURATION
    • GG 19C
      • Install Oracle GoldenGate 19C for Database 12C
      • Install Oracle GoldenGate 19C for Database 19C
  • OEM
    • Install OEM 13.2
    • Install OEM 13.3
    • Add Targets Manually on EM Cloud Control 13c
    • Upgrade OMSPatcher
    • Apply Patch on OMS 13.1
    • Apply Patch on Agent 13.1
  • PostgreSQL
    • Install PostgreSQL 13 using yum Repository on Linux
    • Install PostgreSQL Using Source Code
    • How to START/STOP PostgreSQL 13 on Linux
    • Create Database in PostgreSQL
    • PostgreSQL User Management
    • PostgreSQL pg_hba.conf
    • Change Data Directory
    • WAL Files (Redo log files)
    • Change WAL Directory Location (pg_wal)
    • Enable Archive Mode (WAL Archiving)
    • Disable ARCHIVELOG Mode
    • PostgreSQL Tablespace
    • pg_dump & pg_restore
    • Backup and Restore Using pg_dumpall
    • pg_basebackup
    • Clone PostgreSQL Cluster (No Archive Mode)
    • Backup and Restore on Same Host Using pg_basebackup
    • PostgreSQL Backup & Restore+Recover to New Host with WAL Archive files
    • PostgreSQL Point-in-Time Recovery (PITR)
    • Incremental backups in PostgreSQL 17
    • Streaming Replication (Active Dataguard)
    • Failover Streaming Replication
    • Synchronous Replication in PostgreSQL
    • How to setup repmgr for PostgreSQL Automatic Failover
  • DB2
    • Install DB2 V10.5 using GUI
    • DB2 STOP and START
    • DB2 Troubleshooting Guide
  • MDB
  • Redis
  • Mongo
  • GaussDB
  • DevOps
    • How to Install Jenkins on Linux
  • MSSQL
    • SQL Server Basics
    • Install Microsoft SQL Server Express 2014
    • Install Only SQL Server Management Studio
    • Create Database using GUI
    • Enable TCP/IP Connection
    • Allow Remote Connection
    • Authentication Method
    • Create SQL Server Authenticated Login in SQL Server
    • Create Windows Group Authentication Login in SQL Server
    • Create Windows Authentication Login
    • Create SQL Server Authenticated Login in SQL Server
    • Create a new domain user account in Windows
    • SQL Server – Recovery Models
    • Database Backup-FULL-DIFFERENTIAL-TLOG
    • Restore Database without Tail Backup
    • Log Shipping (SQL Server 2022)
    • Windows Server 2022 Failover Cluster
    • Always On Availability Group
  • MySQL
    • Install MySQL 8 on Linux 7 Using RPM Packages
    • Create MySQL Database
    • Create New User Account in MySQL
    • Grant Privileges in MySQL
    • Create Roles in MySQL
    • How To Backup MySQL Database Using mysqldump
    • How to Restore Database from Single MySQL Database Backup
    • How to Restore A Single Database From A Backup File Which Contains Multiple Databases
    • How To Restore Single Table From Full Database Backup in MySQL
    • How To Configure MySQL Master-Slave Replication?

Always On Availability Group

SQL Server Always On Availability Group (2022)

This guide explains how to configure a 4-node SQL Server 2022 Always On Availability Group
using an existing Windows Server Failover Cluster (WSFC).

Table of Contents


1. Prerequisites
2. Enable Always On Availability Groups
3. Prepare Databases
4. Create Availability Group (Primary Node)
5. Create HADR Endpoints (All Nodes)
6. Join Secondary Replicas (All secondary)
7. Grant CREATE ANY DATABASE (All Nodes)
8. Add Database to Availability Group (Primary Node)
9. Verify


0. Environment

ItemHostnamePublic IPSQL Replication IP
DC / Witness ServerDC01192.168.2.20NA
DB Node 1NTICBPSQLSGV01192.168.2.2110.10.10.11
DB Node 2NTICBPSQLSGV02192.168.2.2210.10.10.12
DB Node 3NTICBPSQLSGV03192.168.2.2310.10.10.13
DB Node 4NTICBPSQLSGV04192.168.2.2410.10.10.14
WSFC Cluster NameNTICBPSQLSGC05192.168.2.25NA
AG Listener NameNTICBPSQLSGL05192.168.2.26NA
Availability Group NameNTICBPSQLSGA05NANA

1. Prerequisites

  • Windows Server Failover Cluster (WSFC) already configured (4-node cluster)
  • SQL Server 2022 Enterprise Edition installed on all nodes
  • Databases must use FULL recovery model
  • Full backup taken before adding to AG
  • All nodes in the same Active Directory domain
  • Proper DNS resolution between nodes
  • Dedicated domain service account MSAPICBSGSQL for SQL Server (same on all nodes)
  • Same Directory Path on ALL SQL Nodes (Mandatory for AG)


2. Enable Always On Availability Groups

Run on each SQL Server node:












3. Prepare Databases (On PRIMARY )

Set recovery model to FULL

CREATE DATABASE TEST;

ALTER DATABASE TEST SET RECOVERY FULL;
GO

Take a full backup

BACKUP DATABASE [TEST] TO DISK = 'K:\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup\TEST.bak'; 
GO


4. Create Availability Group (Primary Node)

Run on NTICBPSQLSGV01

USE master;
GO

CREATE AVAILABILITY GROUP NTICBPSQLSGA05
	WITH (
		AUTOMATED_BACKUP_PREFERENCE = PRIMARY,
		FAILURE_CONDITION_LEVEL = 3,
		HEALTH_CHECK_TIMEOUT = 30000
		)
FOR
REPLICA ON
    'NTICBPSQLSGV01' WITH (
        ENDPOINT_URL = 'TCP://10.10.10.11:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 30,
        PRIMARY_ROLE(ALLOW_CONNECTIONS = ALL),
        SESSION_TIMEOUT = 10,
        SEEDING_MODE = AUTOMATIC
    ),
    'NTICBPSQLSGV02' WITH (
        ENDPOINT_URL = 'TCP://10.10.10.12:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 30,
        PRIMARY_ROLE(ALLOW_CONNECTIONS = ALL),
        SESSION_TIMEOUT = 10,
        SEEDING_MODE = AUTOMATIC
    ),
    'NTICBPSQLSGV03' WITH (
        ENDPOINT_URL = 'TCP://10.10.10.13:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 30,
        PRIMARY_ROLE(ALLOW_CONNECTIONS = ALL),
        SESSION_TIMEOUT = 10,
        SEEDING_MODE = AUTOMATIC
    ),
    'NTICBPSQLSGV04' WITH (
        ENDPOINT_URL = 'TCP://10.10.10.14:5022',
        AVAILABILITY_MODE = SYNCHRONOUS_COMMIT,
        FAILOVER_MODE = AUTOMATIC,
        BACKUP_PRIORITY = 30,
        PRIMARY_ROLE(ALLOW_CONNECTIONS = ALL),
        SESSION_TIMEOUT = 10,
        SEEDING_MODE = AUTOMATIC
    )
	
LISTENER 'NTICBPSQLSGL05' ( WITH IP ( ('192.168.2.26','255.255.255.0')), PORT = 1433);
GO

IF EXISTS (SELECT * FROM sys.server_event_sessions WHERE name = 'AlwaysOn_health')
BEGIN
    ALTER EVENT SESSION [AlwaysOn_health] ON SERVER WITH (STARTUP_STATE = ON);
END

IF NOT EXISTS (SELECT * FROM sys.dm_xe_sessions WHERE name = 'AlwaysOn_health')
BEGIN
    ALTER EVENT SESSION [AlwaysOn_health] ON SERVER STATE = START;
END
GO



5. Create HADR Endpoints (All Nodes)

On NTICBPSQLSGV01:

USE [master]
GO
CREATE ENDPOINT [Hadr_endpoint]
	STATE = STARTED
	AS TCP (LISTENER_PORT = 5022, LISTENER_IP = (10.10.10.11))
	FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE,ENCRYPTION = DISABLED)
GO

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
	ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END

GO

USE [master]
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SQL\MSAPICBSGSQL$];
GO

ALTER AUTHORIZATION ON ENDPOINT::[Hadr_endpoint] TO [sa];
GO

Repeat on other nodes using their respective IP addresses.

On NTICBPSQLSGV02:

USE [master] 
GO
CREATE ENDPOINT [Hadr_endpoint]
	STATE = STARTED
	AS TCP (LISTENER_PORT = 5022, LISTENER_IP = (10.10.10.12))
	FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE,ENCRYPTION = DISABLED)
GO

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
	ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END

GO

USE [master]
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SQL\MSAPICBSGSQL$];
GO

ALTER AUTHORIZATION ON ENDPOINT::[Hadr_endpoint] TO [sa];
GO

On NTICBPSQLSGV03:

USE [master] 
GO
CREATE ENDPOINT [Hadr_endpoint]
	STATE = STARTED
	AS TCP (LISTENER_PORT = 5022, LISTENER_IP = (10.10.10.13))
	FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE,ENCRYPTION = DISABLED)
GO

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
	ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END

GO

USE [master]
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SQL\MSAPICBSGSQL$];
GO

ALTER AUTHORIZATION ON ENDPOINT::[Hadr_endpoint] TO [sa];
GO

On NTICBPSQLSGV04:

USE [master] 
GO
CREATE ENDPOINT [Hadr_endpoint]
	STATE = STARTED
	AS TCP (LISTENER_PORT = 5022, LISTENER_IP = (10.10.10.14))
	FOR DATA_MIRRORING (ROLE = ALL, AUTHENTICATION = WINDOWS NEGOTIATE,ENCRYPTION = DISABLED)
GO

IF (SELECT state FROM sys.endpoints WHERE name = N'Hadr_endpoint') <> 0
BEGIN
	ALTER ENDPOINT [Hadr_endpoint] STATE = STARTED
END
GO

USE [master]
GO
GRANT CONNECT ON ENDPOINT::[Hadr_endpoint] TO [SQL\MSAPICBSGSQL$];
GO

ALTER AUTHORIZATION ON ENDPOINT::[Hadr_endpoint] TO [sa];
GO


6. Join Secondary Replicas

Run on NTICBPSQLSGV02, NTICBPSQLSGV03, NTICBPSQLSGV04

USE master;
GO
ALTER AVAILABILITY GROUP [NTICBPSQLSGA05] JOIN;
GO
  

7. Grant CREATE ANY DATABASE

Run on all nodes – NTICBPSQLSGV01, NTICBPSQLSGV02, NTICBPSQLSGV03, NTICBPSQLSGV04

USE master;
GO
ALTER AVAILABILITY GROUP [NTICBPSQLSGA05]
GRANT CREATE ANY DATABASE;
GO
   

8. Add Database to Availability Group

Run on Primary Node (NTICBPSQLSGV01)

USE master;
GO
ALTER AVAILABILITY GROUP [NTICBPSQLSGA05]
ADD DATABASE [TEST];
GO



9. Verify


Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.

Thank you,
Rajasekhar Amudala
Email: br8dba@gmail.com
Linkedin: https://www.linkedin.com/in/rajasekhar-amudala/

Rajasekhar Amudala

   Rajasekhar Amudala

Master of Business Administration (MBA)
Oracle 10g Certified Professional (OCP)
Oracle 11g Certified Professional (OCP)
Oracle 10g RAC Certified Expert (OCE)
Oracle 11g RAC Certified Expert (OCE)
Oracle Database 12c Admin Workshop
Oracle RAC 12c Admin Workshop
Oracle Golden Gate 12c Workshop
Oracle Golden Gate Certified
Oracle Exadata Certified
OCI Architect Professional
About me - Rajasekhar Amudala
 

Loading Comments...