Set Up Plant Applications SQL Server for Replication
About this task
Important:
In this task, angle brackets (< >) indicate placeholder text. If such placeholder text is part of a command, you must replace it with an appropriate value before running the command.
Before you begin
- When installing Microsoft SQL, in the Feature Selection page, ensure that the SQL Server Replication check box is selected.
- Ensure that you are a system administrator (that is, you must be assigned the sysadmin role).
Procedure
- Access the server that hosts the Plant Applications database.
- Access SQL Server Management Studio (SSMS).
- Create a user login with the sysadmin role for the Plant Applications database.Note:For more information, refer to the SSMS documentation.Important:
- You can configure Windows or SQL Server authentication for the login.
- You can replace the sysadmin role of the user login with the db_datareader role after you perform the Create Backups of Plant Applications SQL Server Transaction Log task later in the deployment process.
- Execute the following query to switch the database to full recovery model:
USE [master]; ALTERDATABASE [SOADB] SET RECOVERY FULL ;
- Install the replication components for the Plant Applications SQL server instance using the SQL Server Installation Wizard.Note:For more information, refer to the SSMS documentation.
- Ensure that the SQLSERVERAGENT service is running, and then create a local publication of the Plant Applications database.Important:You must perform the following steps while creating the local publication:
- Set Transactional publishing as the Publishing Type.
- Select at least one database owner (dbo) table to publish.
- Configure the Snapshot Agent process to run under the SQL Server Agent service account by impersonating the process account.
- Enter AR_PUBLICATION_00006 as the Publication Name.
- Set up a distribution database as a system administrator by performing one of the following steps:
-
After the AlwaysOn Availability group is created and articles are used, set up
only one distribution database (if it does not exist).
Note:For instructions on setting up transactional replication, refer to https://docs.microsoft.com/en-us/sql/relational-databases/replication/configure-distribution?view=sql-server-ver15.
-
Run the transaction log backup script. You can backup the transaction logs on
Fileshare or on the primary node.
Note:The following lines of code is a sample script for a full backup:If you want to use Fileshare, update the file path in the scripts. This will maintain the latest transaction log backup with the current state of the database. It is ideal to maintain at least 30 days of transaction data for highly changing databases. This gives us enough time to reconnect to the database in case of a complete hub failure or any similar issues.
The following lines of code is a sample script for a logs backup:DECLARE @backuppath varchar(250),@filename varchar(250); --Change the path as per what's configured in the system for backpath SET @backuppath = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\'; SET @filename = CONCAT(@backuppath,'SOADB_FULL.bak') BACKUP DATABASE SOADB TO DISK = @filename WITH FORMAT, NAME = 'Full DATABASE Backup of SOADB';
DECLARE @backuppath varchar(250),@filename varchar(250); --Change the path as per what's configured in the system for backpath SET @backuppath = N'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\'; -- Perform a Transaction Log Backup of the Database SET @filename = CONCAT(@backuppath ,'SOADB_backup_' +CONVERT(varchar, GETUTCDATE(), 23)+N'.bak' ) BACKUP LOG SOADB TO DISK = @filename WITH RETAINDAYS = 30, NOFORMAT, NOINIT, NAME = 'SOADB Database LOG Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO
Note:Backup transaction logs only after you have performed a full backup of the database. You cannot backup transaction logs using a simple recovery model. You cannot restore transaction logs without a corresponding database backup. For more information, refer to https://www.easeus.com/backup-utility/three-sql-server-recovery-models.html. - Optional: Perform the following steps on the Plant Applications SQL server instance to verify whether its configuration supports replication: