I have a question regarding database mirroring. I've tried reading the documentation, I think I understand it, but - it's a production database and I really don't want to mess this up!!
I have a primary server - called COMPANYSQL - with the primary database. In SQL Server Manager it says DBNAME (Principal, Disconnected).
I have a backup server - called COMPANYREMOTE - with the one-way mirror of the database for failover purposes. It says DBNAME (Mirrored, Suspended / Restoring).
To re-establish the mirror, I think I can right click on the COMPANYREMOTE database, choose Tasks > Launch Database Mirroring Manager.
The I see under the Database Mirroring Monitor:
DBNAME (Suspended, COMPANYSQL->COMPANYREMOTE\MIRRORED-DBNAME).
I can right click and choose "Register Mirrored Database".
From here I get confused. It tells me to select the principal DB, so from the first dropdown I choose COMPANYSQL and the primary database (DBNAME) appears in the list. Current role is Principal and Partner (Connect As) is COMPANYREMOTE\MIRRORED-DBNAME.
I think if I hit Ok here...it'll re-establish the mirror?
Just don't want to mirror it the other way by mistake and overwrite anything on my production.
THANKS!
Run below mention command in Principal Node
Alter database DBNAME set partner resume
Thanks,
Mani
Eh, no responses, it's ok. I got some advice and it turns out it's best to delete the mirror and re-create it when it gets messed up. In my case, there was approximately 30GB of unsent data that was going to take forever to mirror so it chokes out.
Related
So I have a third party vendor software that I have to call in an SQL Agent Job to restore my databases. So my first step is to set the database in single user mode, my second step is to call the software to start the restore. The problem is, the software takes so long to actually start the restore (its doing it all across the network) that another user can swoop in and take over the database.
Is there a way to put the DB in single user mode and then grab that connection right away? I have tried with a few "Select Getdate()" but I feel that is taking it from the system, and not the database. Do I have to select from a specific table in the database to get it to work?
Thanks
Rather than place the database in single user mode, take the database offline in the context of another database:
USE tempdb;
ALTER DATABASE DatabaseToRestore
SET OFFLINE WITH ROLLBACK IMMEDIATE;
Use the "Client Application Name" option along with the "-m" option that places SQL into single user mode.
That way only an application that matches the name given can connect and take the connection. Obviously you need to ensure that your client process that's doing the restore has a distinct name!
See here for info on the various SQL Server startup options: https://msdn.microsoft.com/en-us/library/ms190737.aspx
Also, I was under the impression you had to be an admin to connect in single user mode, which of course your normal users should not be. Please someone correct me if I'm wrong on that point!
I have set up an Azure database instance which supposedly replicates into a 'read only' secondary database using standard geo-replication. In the Azure portal I can see the status of the replication is 'online' and 'Secondary type' is 'Offline', which appears to be normal.
My question is, is there a way for me to see the actual contents of the secondary database, to ensure the replication is actually working as planned?
I cannot 'Manage' the database in the portal. I can connect to the instance in SQL Management Studio, where I can see the database but expanding tables / stored procedures shows nothing (a bit like connecting to a secure database using the non-secure connection string). I am also not able to run any queries against it as it gives me 'Connection to an offline secondary database is not allowed.'
I've searched this site an did a web search for an answer but can't seem to find one. Am I supposed to blindly rely on the fact that Azure is perfoming the replication correctly (with no way to double-check), or am I missing something here?
Many thanks in advance for any light you are able to shed on this.
Standard Geo-Replicated Secondary DBs are offline copies that do not accept client connections (so there is no way to query the data directly). If you need a readable Geo-Replicated Secondary then you must use the Active Geo-Replication available for Premium DBs.
Even though you can't query Standard Geo-Replicated DBs directly, you can use the DMVs in the Master to determine if the continuous copy is working correctly.
On the Master try the following:
SELECT * FROM sys.dm_database_copies
SELECT * FROM sys.dm_Continuous_copy_status
I hope this helps!
For more information about Standard Geo-Replication, Active Geo-Replication Or Checking the activity of continuous copy use the following links.
Standard Geo-Replication: https://msdn.microsoft.com/en-us/library/azure/Dn758204.aspx
Active Geo-Replication: https://msdn.microsoft.com/en-us/library/azure/dn741339.aspx
Continuous Copy DMV Blog: http://www.sqlservercentral.com/blogs/pie-in-the-sky/2014/12/25/monitoring-geo-replication-in-sql-azure-using-dmvs/
I tried to repro your situation and I think I understand the confusion.
When the Secondary Type = "Offline" then it is a standard Geo-Replicated Secondary. The Primary Databases page is confusing, but when you click on the link to the secondary should show that it is offline.
As far as understanding if the continuous copy is working, run the script below against the Primary (I was mistaken last time, Sorry).
SELECT * FROM sys.dm_Continuous_copy_status
You should see the linked server, database, and Replication State.
As before if you need to read from your secondary, you will have to created a premium active-Geo Replicated Secondary.
Hope This helps!
Ok, so I'm having a bit of an issue - I executed some code on my SQL Server and didn't realize that I didn't have the WHERE bit selected. Of course, when I saw the "608 rows affected" rather than "1 row affected", I freaked a bit.
Luckily, I have a backup saved, but for some reason, I'm getting a couple issues. Now, I took the server down, so I know that it's not being used by anyone, but it's giving me the following error
"Restore failed for Server 'myserver'.
System.Data.sqlclient.sqlerror: Exclusive access could not be obtained
because the database is in use. (Microsoft.SqlServer.Smo)"
I saw something that stated I should be using
Alter Database Databases
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE PRODUCT
FROM DISK = ''
but I'm having three reservations about this code. First, I'm completely unsure of how to turn multi_user back on. Second, I don't know where the program stores its backups. Third, this SQL is a bit above my head - I'm relatively new to the language, honestly, so I'm not sure how this will affect things.
Anyone have any answers to my troubles?
I might suggest instead of overwriting the existing database from the backup, that you instead recover the backup with a different database name... this way you can have the current and previous databases side-by-side.
Then, you can simply write an update statement to recover the data from just that one specific table instead of resetting the whole database.
EDIT: The specifics would depend on your environment, but the restore would look something like this:
restore database PRODUCT_OLD
from disk='C:\PRODUCT.bak'
with
move 'PRODUCT_Data' to 'C:\PRODUCT_OLD_Data.MDF',
move 'PRODUCT_Log' to 'C:\PRODUCT_OLD_Log.LDF'
And then the update statement would also be based on your specific table...
right on the database click tasks->takeoffline , when its succeed do the same thing but put it Bring Online
then try to restore your database
Set the database to single user is correct. When you are complete with your restoration you'll execute this
alter database YourDb
set multi_user
As for where your .bak file resides, you'll have to find it prior to restoring.
Scary.
Ok, some things to check:
Make sure you are the only person connected to the server.
Make sure no other applications, web servers, app servers, etc. hold connections to your DB.
Make sure your SQL manager has no open windows to tables or other objects in your database.
THEN you should be able to do the restore w/o single user stuff.
Go to the activity Monitor and see if users are still logged in then kill the process for that user using the respective db.
Then go ahead restore the backup
I am using SQL Server 2008 Enterprise for development. I find from SQL Server logs, there are items like,
2009-09-20 19:54:33.55 spid53 Starting up database 'DummyOrderDB'.
My confusion is, I think we could only start/stop database server instance (the contained database will be started/stopped when the containing database server instance start/stop), can we just start/stop a database without touch database server instance? I did not find such menu from SSMS.
thanks in advance,
George
That is an auto close database. Auto-close databases are 'closed' when not in use and each time an user uses one, they run a short recovery and the text above is displayed. SQL Express creates databases as auto close ON by default. To turn off the auto-close behavior, run:
ALTER DATABASE <dbname> SEt AUTO_CLOSE OFF;
Yes, we can. Of course Starting and Stopping databases only make sense when the server itself is started (that helps ;-) ), but each individual database has to be, say, initialized before it can be used in earnest. Also when you detach a database, it first shuts down. (which ensures data integrity and other clean-up are taken care of etc.)
I am having a problem with one database on my SQL Server 2005 production server.
A number of databases are already set up for mirroring, however when I right click and go to properties in SSMS, on one particular database there is no "Mirroring" property page available.
I have done the normal tasks, such as setting Full Recovery model, running a full backup of the database and backing up the logs.
I can't see that this is a server specific issue as other databases are happily mirroring.
I've looked around and I can't see that I'm missing a setting, any help would be appreciated.
Thanks.
EDIT: This is nothing to do with the Mirror Database yet, I can't get as far as specifying the Mirror Database , I cannot see the "Mirroring" page on the principle.
EDIT: I have managed to setup mirroring using t-sql commands. However I am still unable to see the "Mirroring Page".
UPDATE: This applies to the Transaction Log Shipping option as well. I can successfully set it up in SQL but not through SSMS.
Check theese items:
2 . The mirror database has to be created from a full backup of the principal server and should be restored in "Restore with Norecovery" model. It is followed by a restore of transaction log backup of the principal database so that the log sequence numbers of the mirror and the principal database are in synch with each other.
3 . The mirror database must have the same name as the principal database.
...
8 . DB Mirroring is available in Enterprise, Developer and Standard Editions, however, please refer to Microsoft website for a comparison chart as some features are not available in the Standard Edition. SQL Server Workgroup and Express Editions can only be used as witness servers.
Database Mirroring in Microsoft SQL Server 2005
Test monitoring with sp_dbmmonitorresults (Transact-SQL)
I don't have the answer, but I ran across the same symptom yesterday, and I remembered your question here, hahaha. My problem was that I set up database mirroring using the wizards, but one of the systems had a firewall blocking the mirroring port. The wizard setup went all the way to the final part of enabling database mirroring, and then errored out - but at that point, mirroring was already set up. Mirroring worked great, but there was something in the database metadata that wasn't set quite right. Even when I removed the firewall, parts of SSMS acted as if mirroring wasn't set up for that particular database, even though it was.
I then set up additional databases for mirroring (with the firewall off) and they worked great. My solution was to remove mirroring on that database and then add it again, and it worked fine. Doesn't sound like that's worked for you, though.
I ended up having to have a Microsoft Support call for the problem I was facing. Anyway after sometime and a number of support sessions they worked out that the database with the problem had an ID of 4 in sys.databases. IDs 1-4 are usually reserved for the system databases and if a database has any of these ids the T-log or Mirroring properties are not displayed. So somehow our database got the ID 3 and now I better get on and detach and reattach some databases to reassign IDs.