Currently, I have a problem that I cannot create replication on database restored from backup.
The production database is running transactional replication.
A backup was made and then database was restored on the test server under the same name.
Replication was running on the test server before.
Now I cannot create replication on the test server. When I try to create a publication I get the message: Sql server could not create publication "test".
Publication "test" does not exists. Object "test" does not exist or is not a valid object for this operation. Change database context to "Database name"
I have tried all the procedures available to clean up / drop replication but is not helping. As far as I know it was a normal full backup and a normal restore datatabse done.
Related
I am attempting to restore a DB for example versionB using a .bak file of version A.
It seems like that is not the right thing to do because I am getting an error:
TITLE: Microsoft SQL Server Management Studio
Restore of database 'B' failed.
(Microsoft.SqlServer.Management.RelationalEngineTasks)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The backup set holds a backup of a database other than the existing 'B' database. (Microsoft.SqlServer.SmoExtended)
To overwrite a database with a backup taken from a different database you must specify the WITH REPLACE option in the RESTORE command.
REPLACE should be used rarely and only after careful consideration.
Restore normally prevents accidentally overwriting a database with a
different database. If the database specified in a RESTORE statement
already exists on the current server and the specified database family
GUID differs from the database family GUID recorded in the backup set,
the database is not restored. This is an important safeguard.
There are many queries of restoring database in SQL Server - below are two:
Query #1
restore database database_name
from disk = 'databaselocation+name'
Query #2
use master
restore database database_name
from disk = 'location'
What is the difference between simple restoration and master restoration?
There is no difference between these two queries. However, management queries are created using the master database by default when created by the SSMS. It is better you also do this as these queries may change some information inside the master database.
I'm setting up an Azure SQL DB for our Web App. We have enabled Point In Time Retention (PITR) and Long Term Retention (LTR). Our process is to keep backups for 1 year.
Periodically, we need to upgrade the DB by applying SQL scripts. Sometimes there is a problem with the upgrade scripts and the upgrade fails. We need to rollback the database to the previous version.
To rollback the DB I tried the restore feature. However, the restore feature seems to only create new DBs; therein lies the problem. Restoring to a new DB and removing the old one works great, but we lose all our backup history. It appears backups are tied to the DB (probably to the ResourceId).
So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?
Unfortunately, restoring from a backup in Azure SQL Database always creates a new database. The secret here may be to rename the newly restored database with the name of the original database. You will even see that the restored database once renamed it then shows all the security recommendations, automatic tuning recommendations of the original database.
So delete existing database, restored the database, and rename it as the original database.
You can reference this document Recover an Azure SQL database using automated database backups , it gives the answer that all the recover are creating new database.
By default, SQL Database backups are stored in geo-replicated blob storage (RA-GRS). The following options are available for database recovery using automated database backups:
Create a new database on the same SQL Database server recovered to a specified point in time within the retention period.
Create a database on the same SQL Database server recovered to the
deletion time for a deleted database.
Create a new database on any SQL Database server in the same region
recovered to the point of the most recent backups.
Create a new database on any SQL Database server in any other region
recovered to the point of the most recent replicated backups.
If you configured backup long-term retention, you can also create a new database from any LTR backup on any SQL Database server.
improtant:
You cannot overwrite an existing database during restore.
"So, how can I use Azure SQL DB and periodically restore a DB and still maintain all the back up history?"
You can use Database replacement:
If the restored database is intended as a replacement for the original database, you should specify the original database's compute size and service tier. You can then rename the original database and give the restored database the original name using the ALTER DATABASE command in T-SQL.
Hope this helps.
I restored a database (db1) which was subscribed to a publisher database. After restoring the db1, I lost the subscription to the publisher, and when I tried to create a new subscription, I get this error:
Subscription already exist for the database
Well that's one way. Another involves reading the Replication documentation.
Dropping a Subscription:
https://learn.microsoft.com/en-us/sql/relational-databases/replication/delete-a-pull-subscription
https://learn.microsoft.com/en-us/sql/relational-databases/replication/delete-a-pull-subscription
Bakup and Restore procedures for Repllication:
https://learn.microsoft.com/en-us/sql/relational-databases/replication/administration/strategies-for-backing-up-and-restoring-snapshot-and-transactional-replication
after struggling for a little. restored the db with new name say db2.
then created a subscription for the db2. which worked fine and dropped the db1. later re named the db2 back to db1. this worked for me and i was able to access the publisher again
We have transaction replication between two server (production and staging) which is running on SQL Server 2008 R2. The distributor is running on the staging server. Now my management is asking to create a copy of database on the production environment and replication few tables to that database. Is it possible to replicate twice? Could you please help me on this. If not possible through replication, is there any other way to do it?
You sure can. Create another publication, add the subset of tables to that, and subscribe the other database to the new publication. NB, this will create another copy of changes for this table at the distributor so take that into account.