Monday, December 30, 2019

SQL Server Service Startup Options

When you install SQL Server, Setup writes a set of default startup options in the Microsoft Windows registry. You can use these startup options to specify an alternate master database file, master database log file, or error log file.
Startup options can be set by using SQL Server Configuration Manager. For information, see How to: Configure Server Startup Options (SQL Server Configuration Manager).
Default startup optionsDescription
-d master_file_pathThe fully qualified path for the master database file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\master.mdf). If you do not provide this option, the existing registry parameters are used.
-e error_log_pathThe fully qualified path for the error log file (typically, C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG). If you do not provide this option, the existing registry parameters are used.
-l master_log_pathThe fully qualified path for the master database log file (typically C:\Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\Data\mastlog.ldf). If you do not specify this option, the existing registry parameters are used.
You can override the default startup options temporarily and start an instance of SQL Server by using the following additional startup options.
Other startup optionsDescription
-cShortens startup time when starting SQL Server from the command prompt. Typically, the SQL Server Database Engine starts as a service by calling the Service Control Manager. Because the SQL Server Database Engine does not start as a service when starting from the command prompt, use -c to skip this step.
-fStarts an instance of SQL Server with minimal configuration. This is useful if the setting of a configuration value (for example, over-committing memory) has prevented the server from starting. Starting SQL Server in minimal configuration mode places SQL Server in single-user mode. For more information, see the description for -m that follows.
-g memory_to_reserveSpecifies an integer number of megabytes (MB) of memory that SQL Server will leave available for memory allocations within the SQL Server process, but outside the SQL Server memory pool. The memory outside of the memory pool is the area used by SQL Server for loading items such as extended procedure .dll files, the OLE DB providers referenced by distributed queries, and automation objects referenced in Transact-SQL statements. The default is 256 MB.
Use of this option might help tune memory allocation, but only when physical memory exceeds the configured limit set by the operating system on virtual memory available to applications. Use of this option might be appropriate in large memory configurations in which the memory usage requirements of SQL Server are atypical and the virtual address space of the SQL Server process is totally in use. Incorrect use of this option can lead to conditions under which an instance of SQL Server may not start or may encounter run-time errors.
Use the default for the -g parameter unless you see any of the following warnings in the SQL Server error log:
  • "Failed Virtual Allocate Bytes: FAIL_VIRTUAL_RESERVE <size>"
  • "Failed Virtual Allocate Bytes: FAIL_VIRTUAL_COMMIT <size>"
These messages might indicate that SQL Server is trying to free parts of the SQL Server memory pool in order to find space for items such as extended stored procedure .dll files or automation objects. In this case, consider increasing the amount of memory reserved by the -g switch.
Using a value lower than the default will increase the amount of memory available to the buffer pool and thread stacks; this may, in turn, provide some performance benefit to memory-intensive workloads in systems that do not use many extended stored procedures, distributed queries, or automation objects.
-hReserves virtual address space for Hot Add memory metadata when AWE is enabled with 32-bit SQL Server. Required for Hot-Add memory with 32-bit AWE, but consumes about 500 MB of virtual address space and makes memory tuning more difficult. Not required for 64-bit SQL Server. Hot Add Memory is only available for Windows Server 2003, Enterprise and Datacenter editions. It also requires special hardware support from the hardware vendor.
-mStarts an instance of SQL Server in single-user mode. When you start an instance of SQL Server in single-user mode, only a single user can connect, and the CHECKPOINT process is not started. CHECKPOINT guarantees that completed transactions are regularly written from the disk cache to the database device. (Typically, this option is used if you experience problems with system databases that should be repaired.) Enables the sp_configure allow updates option. By default, allow updates is disabled. Starting SQL Server in single-user mode enables any member of the computer's local Administrators group to connect to the instance of SQL Server as a member of the sysadmin fixed server role. For more information, see Troubleshooting: Connecting to SQL Server When System Administrators Are Locked Out. For more information about single-user mode, see Starting SQL Server in Single-User Mode.
-m"Client Application Name"When you use the -m option with SQLCMD or SQL Server Management Studio, you can limit the connections to a specified client application. For example, -m"SQLCMD" limits connections to a single connection and that connection must identify itself as the SQLCMD client program. Use this option when you are starting SQL Server in single-user mode and an unknown client application is taking the only available connection. To connect through the Query Editor in Management Studio, use -m"Microsoft SQL Server Management Studio - Query".
Client Application Name is case sensitive.
Important
Do not use this option as a security feature. The client application provides the client application name, and can provide a false name as part of the connection string.
-nDoes not use the Windows application log to record SQL Server events. If you start an instance of SQL Server with -n, we recommend that you also use the -e startup option. Otherwise, SQL Server events are not logged.
-sAllows you to start a named instance of SQL Server. Without the -s parameter set, the default instance will try to start. You must switch to the appropriate BINN directory for the instance at a command prompt before starting sqlservr.exe. For example, if Instance1 were to use \mssql$Instance1 for its binaries, the user must be in the \mssql$Instance1\binn directory to start sqlservr.exe -s instance1.
-T trace#Indicates that an instance of SQL Server should be started with a specified trace flag (trace#) in effect. Trace flags are used to start the server with nonstandard behavior. For more information, see Trace Flags (Transact-SQL).
-xDisables the following monitoring features:
  • SQL Server performance monitor counters
  • Keeping CPU time and cache-hit ratio statistics
  • Collecting information for the DBCC SQLPERF command
  • Collecting information for some dynamic management views
  • Many extended-events event points
Caution
When you use the –x startup option, the information that is available for you to diagnose performance and functional problems with SQL Server is greatly reduced.
-EIncreases the number of extents that are allocated for each file in a filegroup. This option may be helpful for data warehouse applications that have a limited number of users running index or data scans. It should not be used in other applications because it might adversely affect performance. This option is not supported in 32-bit releases of SQL Server.
Note
When specifying a trace flag with the -T option, use an uppercase "T" to pass the trace flag number. A lowercase "t" is accepted by SQL Server, but this sets other internal trace flags that are required only by SQL Server support engineers. (Parameters specified in the Control Panel startup window are not read.)
Using Startup Options for Troubleshooting

Some startup options such as single-user mode and minimal configuration mode are principally used during troubleshooting. Starting the server for troubleshooting with the –m or –f options is most easily done at the command line, while manually starting sqlservr.exe.
Note
When SQL Server is started by using net start, startup options use a slash (/) instead of a hyphen (-).
Using Startup Options During Normal Operations

You may want to use some startup options every time you start SQL Server. These options, such as –g or starting with a trace flag, are most easily done by configuring the startup parameters by using SQL Server Management Studio or SQL Server Configuration Manager. These tools save the startup options as registry keys, enabling SQL Server to always start with the startup options

Sunday, November 24, 2019

Replication Questions!!

requently Asked Questions for Replication Administrators
The following questions and answers provide guidance on a variety of tasks faced by administrators of replicated databases.


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).

Are tables locked during snapshot generation?

The length of time that the locks are taken depends on the type of replication used:

• For merge publications, the Snapshot Agent does not take any locks.

• For transactional publications, by default the Snapshot Agent takes locks only during the initial phase of snapshot generation.

• For snapshot publications the Snapshot Agent takes locks during the entire snapshot generation process.

Because locks prevent other users from updating the tables, the Snapshot Agent should be scheduled to execute during periods of lower activity on the database, especially for snapshot publications.

When is a subscription available; when can the subscription database be used?

A subscription is available after the snapshot has been applied to the subscription database. Even though the subscription database is accessible prior to this, the database should not be used until after the snapshot has been applied. Use Replication Monitor to check the status of snapshot generation and application:

• The snapshot is generated by the Snapshot Agent. View the status of snapshot generation on the Agents tab for a publication in Replication Monitor. For more information, see How to: View Information and Perform Tasks for the Agents Associated With a Publication (Replication Monitor).

• The snapshot is applied by the Distribution Agent or Merge Agent. View the status of snapshot application in the Distribution Agent or Merge Agent page of Replication Monitor. For more information, see How to: View Information and Perform Tasks for the Agents Associated With a Subscription (Replication Monitor).

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 How to: Synchronize a Push Subscription (SQL Server Management Studio), How to: Synchronize a Pull Subscription (SQL Server Management Studio), and Replication Agent Executables Concepts.

Should I script my replication configuration?

Yes. Scripting the replication configuration is a key part of any disaster recovery plan for a replication topology. For more information on scripting, see Scripting Replication.

What recovery model is required on a replicated database?

Replication functions properly using any of the recovery models: simple, bulk-logged, or full. Merge replication tracks change by storing information in metadata tables. Transactional replication tracks changes by marking the transaction log, but this marking process is not affected by the recovery model.

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.

How do I manage constraints on published tables?

There are a number of issues to consider regarding constraints on published tables:

• Transactional replication requires a primary key constraint on each published table. Merge replication does not require a primary key, but if one is present, it must be replicated. Snapshot replication does not require a primary key.

• By default, primary key constraints, indexes, and check constraints are replicated to Subscribers.

• The NOT FOR REPLICATION option is specified by default for foreign key constraints and check constraints; the constraints are enforced for user operations but not agent operations. For more information, see Controlling Constraints, Identities, and Triggers with NOT FOR REPLICATION.

For information on setting the schema options that control whether constraints are replicated, see How to: Specify Schema Options (SQL Server Management Studio) and How to: Specify Schema Options (Replication Transact-SQL Programming).

How do I manage identity columns?

Replication provides automatic identity range management for replication topologies that include updates at the Subscriber. For more information, see Replicating Identity Columns.

Can the same objects be published in different publications?

Yes, but with some restrictions. For more information, see the section "Publishing Tables in More Than One Publication" in the topic Publishing Data and Database Objects.

Can multiple publications use the same distribution database?

Yes. There are no restrictions on the number or types of publications that can use the same distribution database. All publications from a given Publisher must use the same Distributor and distribution database.

If you have multiple publications, you can configure multiple distribution databases at the Distributor to ensure that the data flowing through each distribution database is from a single publication. Use the Distributor Properties dialog box or sp_adddistributiondb (Transact-SQL) to add a distribution database. For more information about accessing the dialog box, see How to: View and Modify Distributor Properties (SQL Server Management Studio).

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 information, see Replication Properties and Distributor and Publisher Information Script.

Does replication encrypt data?

No. Replication does not encrypt data that is stored in the database or transferred over the network. For more information, see the "Encryption" section of the topic Security Overview (Replication).

How do I replicate data over the Internet?

Replicate data over the Internet using:

• A Virtual Private Network (VPN). For more information, see Publishing Data over the Internet Using VPN.

• 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 resume if a connection is dropped

Yes. Replication processing resumes at the point at which it left off if a connection is dropped. If you are using merge replication over an unreliable network, consider using logical records, which ensures related changes are processed as a unit. For more information, see Grouping Changes to Related Rows with Logical Records.

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. For more information about replicating over low bandwidth connections, see A Slow Network Is Causing Problems.

Logins and Object Ownership



Are logins and passwords replicated?

No. You could create a DTS package to transfer logins and passwords from a Publisher to one or more Subscribers. For more information, see Designing and Implementing Packages (Integration Services).

What are schemas and how are they replicated?

Beginning with Microsoft SQL Server 2005, schema has two meanings:

• The definition of an object, such as a CREATE TABLE statement. By default, replication copies the definitions of all replicated objects to the Subscriber.

• The namespace within which an object is created: ..

. Schemas are defined using the CREATE SCHEMA statement. For moreinformation on schemas, see Schemas (Database Engine). • Replication has the following default behavior in the New Publication Wizard with respect to schemas and object ownership: • For articles in merge publications with a compatibility level of 90 or higher, snapshot publications, and transactional publications: by default, the object owner at the Subscriber is the same as the owner of the corresponding object at the Publisher. If the schemas that own objects do not exist at the Subscriber, they are created automatically. • For articles in merge publications with a compatibility level lower than 90: by default, the owner is left blank and is specified as dbo during the creation of the object on the Subscriber. • For articles in Oracle publications: by default, the owner is specified as dbo. • For articles in publications that use character mode snapshots (which are used for non-SQL Server Subscribers and SQL Server Compact 3.5 SP1 Subscribers): by default, the owner is left blank. The owner defaults to the owner associated with the account used by the Distribution Agent or Merge Agent to connect to the Subscriber. The object owner can be changed through the Article Properties - dialog box and through the following stored procedures: sp_addarticle, sp_addmergearticle, sp_changearticle, and sp_changemergearticle. For more information, see How to: View and Modify Publication and Article Properties (SQL Server Management Studio), How to: Define an Article (Replication Transact-SQL Programming), and How to: View and Modify Article Properties (Replication Transact-SQL Programming). 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 Executing Scripts Before and After the Snapshot Is Applied. • Use the stored procedure sp_addscriptexec to execute the statements. What happens to permissions granted in a subscription database if a subscription is reinitialized? By default, objects at the Subscriber are dropped and recreated when a subscription is reinitialized, which causes all granted permissions for those objects to be dropped. There are two ways to handle this: • Reapply the grants after the reinitialization using the techniques described in the previous section. • Specify that objects should not be dropped when the subscription is reinitialized. Prior to reinitialization, either: o Execute sp_changearticle or sp_changemergearticle. Specify a value of 'pre_creation_cmd' (sp_changearticle) or 'pre_creation_command' (sp_changemergearticle) for the parameter @property and a value of 'none', 'delete' or 'truncate' for the parameter @value. o In the Article Properties - 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 How to: View and Modify Publication and Article Properties (SQL Server Management Studio). 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. What is the effect of running a bulk insert command on a replicated database? For transactional replication, bulk inserts are tracked and replicated like other inserts. For merge replication, you must ensure that change tracking metadata is updated properly. For more information, see the section "Bulk Inserting Data into Published Tables" in Considerations for Merge Replication. Are there any replication considerations for backup and restore? Yes. There are a number of special considerations for databases that are involved in replication. For more information, see Backing Up and Restoring Replicated Databases. Does replication affect the size of the transaction log? Merge replication and snapshot replication do not affect transaction log size, but transactional replication can. If a database includes one or more transactional publications, the log is not truncated until all transactions relevant to the publications have been delivered to the distribution database. If the transaction log is growing too large, and the Log Reader Agent is running on a scheduled basis, consider shortening the interval between runs. Or, set it to run in continuous mode. If it is set to run in continuous mode (the default), ensure that it is running. For more information on checking Log Reader Agent status, see How to: View Information and Perform Tasks for the Agents Associated With a Publication (Replication Monitor). Additionally, if you have set the option 'sync with backup' on the publication database or distribution database, the transaction log is not truncated until all transactions have been backed up. If the transaction log is growing too large, and you have this option set, consider shortening the interval between transaction log backups. For more information on backing up and restoring databases involved in transactional replication, see Strategies for Backing Up and Restoring Snapshot and Transactional Replication. How do I rebuild indexes or tables in replicated databases? There are a variety of mechanisms for rebuilding indexes. They can all be used with no special considerations for replication, with the following exception: primary keys are required on tables in transactional publications, so you cannot drop and recreate primary keys on these tables. How do I add or change indexes on publication and subscription databases? Indexes can be added at the Publisher or Subscribers with no special considerations for replication (be aware that indexes can affect performance). CREATE INDEX and ALTER INDEX are not replicated, so if you add or change an index at, for example, the Publisher, you must make the same addition or change at the Subscriber if you want it reflected there. How do I move or rename files for databases involved in replication? In versions of SQL Server prior to SQL Server 2005, moving or renaming database files required detaching and reattaching the database. Because a replicated database cannot be detached, replication had to be removed from these databases first. Beginning with SQL Server 2005, you can move or rename files without detaching and re-attaching the database, with no effect on replication. For more information about moving and renaming files, see ALTER DATABASE (Transact-SQL).

How do I drop a table that is being replicated? First drop the article from the publication using sp_droparticle, sp_dropmergearticle, or the Publication Properties - dialog box, and then drop it from the