Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Replication Administrators
SQL Server 2014
Other Versions
Configuring Replication
Does activity need to be stopped on a database when it is published?
No. Activity can continue on a database while a publication is being created. Be aware that producing a snapshot can be
resource-intensive, so it is best to generate snapshots during periods of lower activity on the database (by default a snapshot
is generated when you complete the New Publication Wizard).
What happens if the Snapshot Agent has not completed when the Distribution or Merge Agent
starts?
It will not cause an error if the Distribution Agent or Merge Agent runs at the same time as the Snapshot Agent. However,
you must be aware of the following:
If the Distribution Agent or Merge Agent is configured to run continuously, the agent applies the snapshot
automatically after the Snapshot Agent completes.
If the Distribution Agent or Merge Agent is configured to run on a schedule or on-demand, and there is no
snapshot available when the agent runs, the agent will shut down with a message stating that a snapshot is not yet
available. You must run the agent again to apply the snapshot after the Snapshot Agent has completed. For more
information on running agents, see Synchronize a Push Subscription, Synchronize a Pull Subscription,
and Replication Agent Executables Concepts.
Why does replication add a column to replicated tables; will it be removed if the table isn't
published?
To track changes, merge replication and transactional replication with queued updating subscriptions must be able to
uniquely identify every row in every published table. To accomplish this:
Merge replication adds the column rowguid to every table, unless the table already has a column of data
type uniqueidentifier with the ROWGUIDCOL property set (in which case this column is used). If the table is
dropped from the publication, the rowguid column is removed; if an existing column was used for tracking, the
column is not removed.
If a transactional publication supports queued updating subscriptions, replication adds the
column msrepl_tran_version to every table. If the table is dropped from the publication,
the msrepl_tran_version column is not removed.
A filter must not include the rowguidcol used by replication to identify rows. By default this is the column added at
the time you set up merge replication and is namedrowguid.
How do I find information on the Distributor and Publisher, such as which objects in a database
are published?
This information is available through SQL Server Management Studio, and a number of replication stored procedures. For
more information, see Distributor and Publisher Information Script.
The Web synchronization option for merge replication. For more information, see Web Synchronization for Merge
Replication.
All types of Microsoft SQL Server replication can replicate data over a VPN, but you should consider Web synchronization if
you are using merge replication.
Does replication work over low bandwidth connections? Does it use compression?
Yes, replication does work over low bandwidth connections. For connections over TCP/IP, it uses the compression provided
by the protocol but does not provide additional compression. For Web synchronization connections over HTTPS, it uses the
compression provided by the protocol and also additional compression of the XML files used to replicate changes.
How can grants on the subscription database be configured to match grants on the publication
database?
By default, replication does not execute GRANT statements on the subscription database. If you want the permissions on the
subscription database to match those on the publication database, use one of the following methods:
Execute GRANT statements at the subscription database directly.
Use a post-snapshot script to execute the statements. For more information, see Execute Scripts Before and After
the Snapshot Is Applied.
Use the stored procedure sp_addscriptexec to execute the statements.
In the Article Properties - <Article> dialog box in the Destination Object section, select a value
of Keep existing object unchanged, Delete data. If article has a row filter, delete only data that
matches the filter. or Truncate all data in the existing object for the option Action if name is in use.
For more information on accessing this dialog box, see View and Modify Publication Properties.
Database Maintenance
Why can't I run TRUNCATE TABLE on a published table?
TRUNCATE TABLE is a non-logged operation that does not fire triggers. It is not permitted because replication cannot track
the changes caused by the operation: transactional replication tracks changes through the transaction log; merge replication
tracks changes through triggers on published tables.
Replication Maintenance
How do I determine if the data at Subscribers is synchronized with data at the Publisher?
Use validation. Validation reports on whether a given Subscriber is synchronized with the Publisher. For more information,
see Validate Replicated Data. Validation does not provide information on which rows if any are not synchronized correctly,
but the tablediff utility does.
Solution
Here is a list of commonly asked replication interview questions or questions that may come
up during your routine DBA duties. I hope you find them useful.
EASY
1) What is SQL Server replication?
Replication is subset of SQL Server that can move data and database objects in an automated way
from one database to another database. This allows users to work with the same data at different
locations and changes that are made are transferred to keep the databases synchronized.
Snapshot replication - As the name implies snapshot replication takes a snapshot of the published
objects and applies it to a subscriber. Snapshot replication completely overwrites the data at the
subscriber each time a snapshot is applied. It is best suited for fairly static data or if it's acceptable
to have data out of sync between replication intervals. A subscriber does not always need to be
connected, so data marked for replication can be applied the next time the subscriber is
connected. An example use of snapshot replication is to update a list of items that only changes
periodically.
Transactional replication - As the name implies, it replicates each transaction for the article being
published. To set up transactional replication, a snapshot of the publisher or a backup is taken and
applied to the subscriber to synchronize the data. After that, when a transaction is written to the
transaction log, the Log Reader Agent reads it from the transaction log and writes it to the
distribution database and then to the subscriber. Only committed transactions are replicated to
ensure data consistency. Transactional replication is widely applied where high latency is not
allowed, such as an OLTP system for a bank or a stock trading firm, because you always need realtime updates of cash or stocks.
Merge replication - This is the most complex types of replication which allows changes to happen
at both the publisher and subscriber. As the name implies, changes are merged to keep data
consistency and a uniform set of data. Just like transactional replication, an initial synchronization is
done by applying snapshot. When a transaction occurs at the Publisher or Subscriber, the change is
written to change tracking tables. The Merge Agent checks these tracking tables and sends the
transaction to the distribution database where it gets propagated. The merge agent has the
capability of resolving conflicts that occur during data synchronization. An example of using merge
replication can be a store with many branches where products may be centrally stored in inventory.
As the overall inventory is reduced it is propagated to the other stores to keep the databases
synchronized.
Push - As the name implies, a push subscription pushes data from publisher to the subscriber.
Changes can be pushed to subscribers on demand, continuously, or on a scheduled basis.
Pull - As the name implies, a pull subscription requests changes from the Publisher. This allows the
subscriber to pull data as needed. This is useful for disconnected machines such as notebook
computers that are not always connected and when they connect they can pull the data.
Snapshot Agent- The Snapshot Agent is used with all types of replication. It prepares the schema
and the initial bulk copy files of published tables and other objects, stores the snapshot files, and
records information about synchronization in the distribution database. The Snapshot Agent runs at
the Distributor.
Log Reader Agent - The Log Reader Agent is used with transactional replication. It moves
transactions marked for replication from the transaction log on the Publisher to the distribution
database. Each database
published using transactional replication has its own Log Reader Agent that runs on the Distributor
and connects to the Publisher (the Distributor can be on the same computer as the Publisher)
Distribution Agent - The Distribution Agent is used with snapshot replication and transactional
replication. It applies the initial snapshot to the Subscriber and moves transactions held in the
distribution database to Subscribers. The Distribution Agent runs at either the Distributor for push
subscriptions or at the Subscriber for pull subscriptions.
Merge Agent - The Merge Agent is used with merge replication. It applies the initial snapshot to
the Subscriber and moves and reconciles incremental data changes that occur. Each merge
subscription has its own Merge Agent that connects to both the Publisher and the Subscriber and
updates both. The Merge Agent runs at either the Distributor for push subscriptions or the
Subscriber for pull subscriptions.
Queue Reader Agent - The Queue Reader Agent is used with transactional replication with the
queued updating option. The agent runs at the Distributor and moves changes made at the
Subscriber back to the
Publisher. Unlike the Distribution Agent and the Merge Agent, only one instance of the Queue
Reader Agent exists to service all Publishers and publications for a given distribution database.
Replication is not dependent on any particular recovery model. A database can participate in
replication whether it is in simple, bulk-logged, or full. However how data is tracked for
replication depends on the type of replication used.
Medium
1) What type of locking occurs during the Snapshot generation?
o
o
o
In snapshot replication, the snapshot agent locks the object during the entire snapshot
generation process.
In transactional replication, locks are acquired initially for a very brief time and then
released. Normal operations on a database can continue after that.
In merge replication, no locks are acquired during the snapshot generation process.
2) What options are there to delete rows on the publisher and not on the subscriber?
One option is to replicate stored procedure execution instead of the actual DELETE command. You
can create two different versions of the stored procedures one on the publisher that does the delete
and the other on the subscriber that does not do the delete.
Another option is to not replicate DELETE commands.
3) Is it possible to run multiple publications and different type of publications from the same
distribution database?
Yes this can be done and there are no restrictions on the number or types of publications that can
use the same distribution database. One thing to note though is that all publications from a
Publisher must use the same Distributor and distribution database.
4) Data is not being delivered to Subscribers, what can be the possible reasons?
There are a number of possible causes for data not being delivered to Subscribers:
o The table is filtered, and there are no changes to deliver to a given Subscriber.
o One or more agents are not running or are failing with an error.
o Data is deleted by a trigger, or a trigger includes a ROLLBACK statement.
o A transactional subscription was initialized without a snapshot, and changes have occurred
on the Publisher since the publication was created.
o Replication of stored procedure execution for a transactional publication produces different
results at the Subscriber.
o The INSERT stored procedure used by a transactional article includes a condition that is not
met.
o Data is deleted by a user, a replication script, or another application.
Sp_replcounters is a system stored procedure that returns information about the transaction rate,
latency, and first and last log sequence number (LSN) for each publication on a server. This is run
on the publishing server. Running this stored procedure on a server that is acting as the distributor
or subscribing to publications from another server will not return any data
Hard
1) How will you monitor replication latency in transactional replication?
Tracer tokens were introduced with SQL Server 2005 transactional replication as a way to monitor
the latency of delivering transactions from the publisher to the distributor and from the distributor
to the subscriber(s). For details, please refer tip to this tip: Monitor SQL Server replication latency
using tracer tokens
2) If I create a publication with one table as an article, and then change the schema of the
published table (for example, by adding a column to the table), will the new schema ever be
applied at the Subscribers?
Yes. Schema changes to tables must be made by using Transact-SQL or SQL Server Management
Objects (SMO). When schema changes are made in SQL Server Management Studio, Management
Studio attempts to drop and re-create the table and since you cannot drop a published objects, the
schema change will fail.
Yes this can be done using heterogeneous replication. In SQL Server 2000, publishing data to other
databases such as DB2 or Oracle was supported; however, publishing data from other databases
was not supported without custom programming. In SQL Server 2005 and later versions, Oracle
databases can be directly replicated to SQL Server in much the same way as standard SQL Server
replication. For more information, please read tip:Introduction to SQL Server Heterogeneous
Replication
4) How will you monitor replication activity and performance? What privilege do you need to
use replication monitor?
The easiest way to monitor replication activity and performance is to use replication monitor, but
you can also use the below tools to monitor replication performance:
o T-SQL commands. For more details refer msdn article - http://msdn.microsoft.com/enus/library/ms147874.aspx
o Microsoft SQL Server Management studio. For more details refer msdn article http://msdn.microsoft.com/en-us/library/ms152763.aspx
To monitor replication, a user must be a member of the sysadmin fixed server role at the Distributor
or a member of the replmonitor fixed database role in the distribution database. A system
administrator can add any user to the replmonitor role, which allows that user to view replication
activity in Replication Monitor; however, the user cannot administer replication.
5) Can you tell me some of the common replication DMV's and their use?
sys.dm_repl_articles - Contains information about each article being published. It returns data
from the database being published and returns a row for each object being published in each article.
sys.dm_repl_schemas - Contains information about each table and column being published. It
returns data from the database being published and returns one row for each column in each object
being published
sys.dm_repl_traninfo - Contains information about each transaction in a transactional replication
The master database holds information for all databases located on the SQL Server instance. As SQL Server cannot
start without a functioning master database, we must administer this database with care and monitor Start-up
Parameters in Configuration Manager.
The msdb database stores information regarding database backups, SQL Agent information, DTS packages, SQL Server
jobs, and some replication information such as for log shipping.
The tempdb holds temporary objects such as global and local temporary tables and stored procedures.
The model is essentially a template database used in the creation of any new user database created in the instance.
The resource Database is a read-only database that contains all the system objects that are included with SQL Server.
SQL Server system objects, such as sys.objects, are physically persisted in the Resource database, but they logically
appear in the sys schema of every database. The Resource database does not contain user data or user metadata.
18. What is Service Broker?
Service Broker is a message-queuing technology in SQL Server that allows developers to integrate SQL Server fully into
distributed applications. Service Broker is feature which provides facility to SQL Server to send an asynchronous,
transactional message. it allows a database to send a message to another database without waiting for the response, so
the application will continue to function if the remote database is temporarily unavailable.
19. Where SQL server user names and passwords are stored in SQL server?
They get stored in System Catalog Views sys.server_principals and sys.sql_logins.
20. What is Policy Based Management (PBM)?
Policy Based Management in SQL SERVER 2012 Administration allows you to define and enforce policies for configuring
and managing SQL Server across the enterprise. Policy-Based Management is configured in SQL Server Management
Studio (SSMS). Navigate to the Object Explorer and expand the Management node and the Policy Management node;
you will see the Policies, Conditions, and Facets nodes.
21. What is Replication with Database Mirroring?
Database mirroring can be used with replication to provide availability for the publication database. Database mirroring
involves two copies of a single database that typically reside on different computers. At any given time, only one copy of
the database is currently available to clients which are known as the principal database. Updates made by clients to the
principal database are applied on the other copy of the database, known as the mirror database. Mirroring involves
applying the transaction log from every insertion, update, or deletion made on the principal database onto the mirror
database.
22. What are Sparse Columns in SQL Server?
A sparse column is another tool used to reduce the amount of physical storage used in a database. They are the
ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null
values at the cost of more overhead to retrieve non null values.
1.
regarding the database such as providing information about the procedure cache. Validation commands
include commands that validate the database such as the ever-popular CHECKDB. Finally, miscellaneous
commands are those that obviously don't fit in the other three categories. This includes statements like
DBCC HELP, which provides the syntax for a given DBCC command.
How can you control the amount of free space in your index pages?
You can set the fill factor on your indexes. This tells SQL Server how much free space to leave in the index
pages when re-indexing. The performance benefit here is fewer page splits (where SQL Server has to copy
rows from one index page to another to make room for an inserted row) because there is room for growth
built in to the index.
Why would you call Update Statistics?
Update Statistics is used to force a recalculation of query optimization statistics for a table or indexed view.
Query optimization statistics are automatically recomputed, but in some cases, a query may benefit from
updating those statistics more frequently. Beware though that re-computing the query statistics causes
queries to be recompiled. This may or may not negate all performance gains you might have achieved by
calling update statistics. In fact, it could have a negative impact on performance depending on the
characteristics of the system.
What is a correlated sub-query?
A correlated sub-query is a nested query that is linked to the outer query. For instance, say I wanted to find
all the employees who have not entered their time for the week. I could query the Employee table to get
their first and last name, but I need to look at the TimeEntry table to see if they've entered their time or
not. I can't do a straight join here because I'm looking for the absence of time data, so I'll do a correlated
sub-query similar to this:
SELECT FirstName, LastName
FROM EMPLOYEE e
WHERE NOT EXISTS (SELECT 1 FROM TimeEntry te
WHERE te.EmpID = e.EmpID
AND te.WeekID = 35)
Notice that the inner query relates to the outer query on the employee ID, thus making it a correlated subquery. The inner query will be evaluated once per outer query row.
What authentication modes does SQL Server support?
SQL Server supports Windows Authentication and mixed-mode. Mixed-mode allows you to use both
Windows Authentication and SQL Server Authentication to log into your SQL Server. Its important to note
that if you use Windows Authentication, you will not be able to log in as sa.
Conclusion
In this article, I list the top 10 DBA interview question (as I see it anyway). I would, however, encourage
you to also ask the DBA the SQL Server Developer questions from my previous article. As I said in that
article though, every workplace and project has different needs. I hope you found at least a few that you
can use in yours.