Backup And Recovery In SQL Server Collaborate

66 249 0
Backup And Recovery In SQL Server Collaborate

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

LESSON 3C COLLABORATE 3C. 1 Administering and Troubleshooting SQL Server 2000 INSTRUCTOR NOTES In this section, tell students about the concept of Object Linking and Embedded databases (OLEDB). OLEDB is a set of Application Programming Interfaces (APIs) that enables the user to connect to different data sources. Ensure that the following datafiles are installed on the student nodes: „Employee.mdb „BooksDetails.xls Administering and Troubleshooting SQL Server 2000 3C.2 KNOWLEDGE BYTE Collaborate Knowledge Byte In this lesson, you will learn about: • • monitor SQL Server system activity using System Monitor optimize and troubleshoot SQL Server system activities ©NIIT Collaborate Lesson 3C / Slide 1 of 34 In this section, you will learn to: „monitor SQL Server system activity using System Monitor. „optimize and troubleshoot SQL Server system activities. 3C.3 Administering and Troubleshooting SQL Server 2000 Creating a link between SQL Server 2000 and a OLE DB Provider Collaborate Creating a link between SQL Server 2000 and a OLE DB Provider • ©NIIT Sandra is a database administrator at Bluemun Inc. The company has its branch offices at various locations in the US. These branches use SQL Server 2000 to manage database. The company has recently opened two new branch offices at New Jersey and California. The branch managers of these branches have been maintaining data in Access and Excel as they do not have SQL Server installed. . The head office collects the sales reports from all its branch offices and updates the central database data on a weekly basis. The two new branch offices have sent sales reports in Access and Excel data formats. Therefore, Sandra needs to copy data from these database files to the SQL Server database. Collaborate Lesson 3C / Slide 2 of 34 Administering and Troubleshooting SQL Server 2000 3C.4 Collaborate Creating a link between SQL Server 2000 and a OLE DB Provider (Contd.) • ©NIIT 3C.5 To copy data from Access and Excel into SQL Server database, Sandra needs to create a link server using Object Linking and Embedded databases (OLEDB). OLEDB uses the data provider and data source arguments to connect to various databases. The table below describes various data sources and data providers: Product Data Source Data Provider MS Access MS Access MS Access Oracle System Identifier Oracle System Identifier Oracle System Identifier MS Jet 4.0 OLE DB MS Jet 4.0 OLE DB MS Jet 4.0 OLE DB Collaborate Lesson 3C / Slide 3 of 34 Administering and Troubleshooting SQL Server 2000 Sandra is a database administrator at Bluemun Inc. The company has its branch offices at various locations in the US. These branches use SQL Server 2000 to manage database. The company has recently opened two new branch offices at New Jersey and California. The branch managers of these branches have been maintaining data in Access and Excel as they do not have SQL Server installed. The head office collects the weekly sales reports from all its branch offices and updates the data on the central database. The two new branch offices have sent sales reports in Access and Excel data formats. Therefore, Sandra needs to copy data from these database files to the SQL Server database. To copy data from Access and Excel into SQL Server database, Sandra needs to create a link server using Object Linking and Embedded databases (OLEDB). OLEDB uses the data provider and data source arguments to connect to various databases. Data provider specifies the provider name and the type of data to retrieve. For example, SQLOLEDB.1 is the name of the Microsoft OLEDB Provider for SQL Server. Data source specifies the name of the database to which the data provider connects. The table below describes the provider name and data sources of the different databases: Product Data Source Data Provider MS Access Database File Location MS Jet 4.0 OLE DB Excel Spreadsheet File Location MS Jet 4.0 OLE DB Oracle Oracle System Identifier MS OLE Provider for Oracle Sandra would need to create linked servers between SQL Server and Access and Excel, to enable data access from heterogeneous databases. After creating linked servers, the data from Access and Excel appear as tables in SQL Server Enterprise Manager. You will now look at the steps to create a link between: „Excel and SQL Server „Access and SQL Server Administering and Troubleshooting SQL Server 2000 3C.6 Creating a link to Microsoft Excel Collaborate Creating a link to Microsoft Excel • 1. 2. ©NIIT The process to create a link between SQL Server and Microsoft Excel involves following steps: Specify range of cells for linking Creating a Linked server using T-SQL Collaborate Lesson 3C / Slide 4 of 34 The process to create a link between SQL Server and Microsoft Excel involves following steps: 1. Specifying range of cells for linking 2. Creating a Linked server using T-SQL 1. Specifying the range of cells for linking To specify the range of cells in the BookDetails Excel file sheet that would be linked to SQL Server perform the following steps: 1. Open BookDetails in Microsoft Excel. Click the InsertÆNameÆDefine option, to open the Define Name dialog box. 3C.7 Administering and Troubleshooting SQL Server 2000 2. Next, you need to specify the name of the selected cells in the workbook that you want to link in the Define Name dialog box. Specify the name of the selected cells as Book in the Names in workbook text box, as shown. 3. Click the Refers to textbox to specify the range of cells that you need to copy. Drag the cursor to select the range area on the Excel workbook. A range identifies a cell or a group of cells in an Excel workbook. Administering and Troubleshooting SQL Server 2000 3C.8 4. Click the Add button in the Define Name dialog box to define the new name for the selected range of cells. 5. Click the OK button in the Define Name dialog box to complete the process. 6. Save the changes made to the Excel workbook. You have successfully named a range of cells from the workbook that need to be linked to SQL Server. 2. Creating a Linked Server Using T-SQL After specifying the range of cells, you need to create a linked server to connect the range of cells in Excel with SQL Server. To create a linked server, you need to perform the following steps: 1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆQuery Analyzer to start SQL Query Analyzer. 2. Notice that the Connect to SQL Server dialog box appears. Select the SERVER option from the SQL Server drop-down list and click the OK button to connect to the SQL Server. 3. The SQL Query Analyzer is opened. 3C.9 Administering and Troubleshooting SQL Server 2000 4. The syntax for creating a linked server with Excel worksheet is shown below. execute sp_addlinkedserver @server = '', @srvproduct= 'Excel', @provider='Microsoft.Jet.OLEDB.4.0', @datasrc='', @provstr='' Type the code in the SQL Query Analyzer window, as shown. Execute Query Button 5. To execute the query, click the Execute Query button on the toolbar. SQL Server will display a successful message, as shown. Administering and Troubleshooting SQL Server 2000 3C.10 6. Close the SQL Query Analyzer window. After creating a linked server, verify if the tables are available in SQL Server. Perform the following steps, to verify the link between Excel and SQL Server. 1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆEnterprise Manager, to open the Enterprise Manager window. 2. In the Enterprise Manager window, under the Console Root, expand the default server. Under the database server expand the Security option, as shown. 3C.11 Administering and Troubleshooting SQL Server 2000 3. Click the Linked Servers option to view the linked servers. 4. Expand the linked server, BOOKDETAILS to list the available objects in the server, as shown. Administering and Troubleshooting SQL Server 2000 3C.12 5. Click the Tables option, to view the named ranges as tables. The named ranges appear as tables in Enterprise Manager, as shown. 3C.13 Administering and Troubleshooting SQL Server 2000 You have successfully created a linked server between the named cell, Book, in Excel and SQL Server. Administering and Troubleshooting SQL Server 2000 3C.14 Creating a link to MS Access Collaborate Creating a link to MS Access • • ©NIIT Sandra also needs to create a link between the data in Access and SQL Server to compile the sales report sent by the other branch office. Sandra can use sp_addlinkedserver stored procedure to create a linked server. Collaborate Lesson 3C / Slide 5 of 34 Sandra also needs to create a link between the data in Access and SQL Server to compile the sales report sent by the other branch office. You need to perform the following steps to link the data in Access with SQL Server: 1. Open Microsoft Access and create a new mdb file, Books.mdb. 3C.15 Administering and Troubleshooting SQL Server 2000 2. Next, you need to create a new table, Suppliers, in the books.mdb database. Create the table with the following fields: Supplierid, Suppliername, Contactname, Address, City, Phonenumber, Emailaddress, where Supplierid is the primary key, as shown. Administering and Troubleshooting SQL Server 2000 3C.16 3. After creating the database in MS Access, close the application. 4. Open the SQL Query Analyzer window. 5. The syntax for creating a linked server with the Access database is: execute sp_addlinkedserver '', 'Access 2000', 'Microsoft.Jet.OLEDB.4.0', '' 3C.17 Administering and Troubleshooting SQL Server 2000 6. Type the following code in the SQL Query Analyzer window, to create a linked server, as shown. 7. Click the Execute Query button on the Query Analyzer window toolbar to execute the query. SQL Server displays a successful message in the message window of SQL Query Analyzer, as shown. Administering and Troubleshooting SQL Server 2000 3C.18 8. Finally, close the SQL Query Analyzer window. After creating a linked server, verify if the tables are available in SQL Server. Perform the following steps, to verify the link between Access and SQL Server. 1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆEnterprise Manager, to open the Enterprise Manager window. 2. In the Enterprise Manager window, expand database server. Under database server, expand the Security option. 3. Click the Linked Server option to view the linked servers. 4. Expand the linked server, Books to view the objects. 5. Click the Tables option, to view the tables. Notice that data in MS Access appear as tables in SQL Server Enterprise Manager. 3C.19 Administering and Troubleshooting SQL Server 2000 You have successfully created a linked server between the table, Suppliers, in the Books database in Access and SQL Server. Administering and Troubleshooting SQL Server 2000 3C.20 Alternative Methods to Monitor SQL Server System Activity Collaborate Alternative Methods to Monitor SQL Server System Activity • ©NIIT 3C.21 A database administrator can use the Task Manager to monitor SQL Server system activities. In addition, a database administrator can use the following tools provided by SQL Server 2000, to monitor SQL Server system activities and performance of SQL Server 2000: • Query Analyzer • SQL Profiler • SQL Server Enterprise Manager • Transact-SQL Collaborate Lesson 3C / Slide 6 of 34 Administering and Troubleshooting SQL Server 2000 A database administrator can use the Task Manager to monitor SQL Server system activities. In addition, a database administrator can use the following tools provided by SQL Server 2000, to monitor SQL Server system activities and performance of SQL Server 2000: „Query Analyzer „SQL Profiler „SQL Server Enterprise Manager „Transact-SQL Statements Using Query Analyzer to Monitor SQL Server 2000 System Activity Collaborate Using Query Analyzer to Monitor SQL Server 2000 System Activity • • ©NIIT As a database administrator, you need to monitor the execution of queries to determine the performance of SQL Server 2000 with respect to the response time of the query. The execution of a query is monitored using an Execution plan. An Execution plan is a graphical display of the execution steps of a query. It also displays the various system resources that are used during the execution of the query. Using the information displayed in the execution plan you can monitor execution of the queries, identify possible problems areas, and implement techniques to improve query processing and reduce the response time. Collaborate Lesson 3C / Slide 7 of 34 As a database administrator, you need to monitor the execution of queries to determine the performance of SQL Server 2000 with respect to the response time of the query. The execution of a query is monitored using an Execution plan. An Execution plan is a graphical display of the execution steps of a query. It also displays the various system resources that are used during the execution of the query. Administering and Troubleshooting SQL Server 2000 3C.22 The following are the steps to monitor the execution of a query using the Query Analyzer: 1. Select StartÆ All ProgramsÆ Microsoft SQL ServerÆ Query Analyzer, to open the SQL Query Analyzer window. 2. Select the Northwind database from the database drop-down list on the tool bar, as shown. 3. Type the following code in the SQL Query Analyzer window, to view the execution plan of the query, as shown. 3C.23 Administering and Troubleshooting SQL Server 2000 4. Click the Execute Query button on the Query Analyzer window toolbar to execute the query. 5. The result of the query is displayed in the message window of SQL Query Analyzer, as shown. Administering and Troubleshooting SQL Server 2000 3C.24 6. Select QueryÆ Show Execution Plan and execute the query again to view the execution plan of the query. 7. Click the Execution Plan tab page in the result pane of the SQL Query Analyzer window. The execution plan of the query is displayed in the Execution Plan tab page of the result pane, as shown. 3C.25 Administering and Troubleshooting SQL Server 2000 Administering and Troubleshooting SQL Server 2000 3C.26 8. The Execution Plan tab page of the result pane displays the execution plan of the query in a step-by step manner. You can place the mouse pointer on each step to display the system resources used by the query during its execution, as shown. 3C.27 Administering and Troubleshooting SQL Server 2000 Administering and Troubleshooting SQL Server 2000 3C.28 Using the information displayed in the execution plan you can monitor execution of the queries, identify possible problems areas, and implement techniques to improve query processing and reduce the response time. 3C.29 Administering and Troubleshooting SQL Server 2000 Using SQL Profiler to Monitor SQL Server 2000 System Activity Collaborate Using SQL Profiler to Monitor SQL Server 2000 System Activity • • • ©NIIT SQL Profiler is a graphical tool that is used to identify performance related problems of SQL Server 2000. SQL Profiler uses the concept of Trace Templates to capture information related to specific server events. Trace templates store information that can be used to monitor SQL Server system activity, identify stored procedures that take long time to execute, and identify deadlocks. Collaborate Lesson 3C / Slide 8 of 34 Administering and Troubleshooting SQL Server 2000 3C.30 Collaborate Using SQL Profiler to Monitor SQL Server 2000 System Activity (Contd.) • ©NIIT The following table lists the various pre-configured templates provided by SQL Profiler: • SQLProfilerSP_Counts • SQLProfilerStandards • SQLProfilerTSQL • SQLProfilerTSQL_Duration • SQLProfilerTSQL_Grouped • SQLProfilerTSQL_Replay • SQLProfilerTSQL_SPs • SQLProfilerTuning Collaborate Lesson 3C / Slide 9 of 34 You can monitor SQL Server 2000 system activity using SQL profiler. SQL Profiler is a graphical tool that is used to identify performance related problems of SQL Server 2000. SQL Profiler uses the concept of Trace Templates to capture information related to specific server events. Trace templates store information that can be used to monitor SQL Server system activity, identify stored procedures that take long time to execute, and identify deadlocks. Trace templates are files with extension .TRC. SQL Profiler provides pre-configured trace templates that define the type of information to be captured and monitored. 3C.31 Administering and Troubleshooting SQL Server 2000 The following table lists the various pre-configured templates provided by SQL Profiler: Template Name Captured Information SQLProfilerSP_Counts Captures the number of stored procedures that are executed and also captures the number of times each stored procedure has been executed. SQLProfilerStandards Captures general information regarding the execution of SQL Server batches and stored procedures. SQLProfilerTSQL Captures each Transact-SQL statement that has been executed in the specified order and the number of times each statement is executed. SQLProfilerTSQL_Duration Captures each Transact-SQL statement that has been executed in the specified order and displays this information after arranging it on the basis of time taken to run a statement. SQLProfilerTSQL_Grouped Captures each Transact-SQL statement that has been executed in the specified order and compiles this information according to the user issuing these statements. SQLProfilerTSQL_Replay Captures details about each Transact-SQL statement executed in the specified order. SQLProfilerTSQL_SPs Captures details about the execution of each stored procedure, also including the Transact-SQL commands of each stored procedure. SQLProfilerTuning Captures information and binary data about each stored procedure that is executed. Using these built-in templates and the information they capture, you can monitor specific server events, identify possible problem areas, and implement techniques to improve the performance of events. Administering and Troubleshooting SQL Server 2000 3C.32 Using Enterprise Manager to Monitor SQL Server System Activity Collaborate Using Enterprise Manager to Monitor SQL Server System Activity • ©NIIT 3C.33 In addition, you can monitor SQL Server system activities using SQL Server 2000 Enterprise Manager. Enterprise Manager provides the Current Activity option under the Console RootÆMicrosoft SQL ServersÆSQL Server GroupÆDefault ServerÆManagement folder. This displays detailed information regarding: • currently active processes. • user activity. • locks held by each process. • locks held on various objects Collaborate Lesson 3C / Slide 10 of 34 Administering and Troubleshooting SQL Server 2000 Collaborate Using Enterprise Manager to Monitor SQL Server System Activity (Contd.) • ©NIIT Using the Current Activity option, you can also: • monitor blocked transactions. • monitor transactions that are blocking other transactions. • detect transactions that result in deadlock situations. • view the currently connected users. • view the last statement executed by users Collaborate Lesson 3C / Slide 11 of 34 Administering and Troubleshooting SQL Server 2000 3C.34 You can also monitor SQL Server system activities using SQL Server 2000 Enterprise Manager. Enterprise Manager provides the Current Activity option under the Console RootÆMicrosoft SQL ServersÆSQL Server GroupÆDefault ServerÆManagement folder. This displays detailed information regarding: „currently active processes. „user activity. „locks held by each process. „locks held on various objects. Using the Current Activity option, you can also: „monitor blocked transactions. „monitor transactions that are blocking other transactions. „detect transactions that result in deadlock situations. „view the currently connected users. „view the last statement executed by users. The steps to monitor the system activities using the Current Activity option are: 1. Expand the Console Root option from the Enterprise Manager window, and then expand the Microsoft SQL Servers option. 2. Expand the SQL Server Group option and then expand the registered SQL Server instance option. 3. Expand the Management option and select the Current Activity option, as shown. 3C.35 Administering and Troubleshooting SQL Server 2000 The details pane displays the following three options: „Process Info: Using this option you can view and monitor the details about the active processes in SQL Server 2000. „Locks / Process ID: Using this option you can view and monitor the locks held by each active process. „Locks / Object: Using this option you can view and monitor the locks held on each object. Administering and Troubleshooting SQL Server 2000 3C.36 Using Transact-SQL to Monitor SQL Server System Activity Collaborate Using Transact SQL to Monitor SQL Server System Activity • ©NIIT You can monitor SQL Server 2000 system activity using Transact-SQL statements. You can use Transact-SQL statements to get information about the current system performance or system performance over a specified period of time. T-SQL provides stored procedures and built-in functions to monitor system activity Collaborate Lesson 3C / Slide 12 of 34 You can monitor SQL Server 2000 system activity using Transact-SQL statements. You can use Transact-SQL statements to get information about the current system performance or system performance over a specified period of time. T-SQL provides stored procedures and built-in functions to monitor system activity. 3C.37 Administering and Troubleshooting SQL Server 2000 Stored Procedures Collaborate Stored Procedure • • ©NIIT Stored procedures are a set of T-SQL statements. A stored procedure can accept input parameters for performing specified database operations. A stored procedure is also used to return values. The stored procedures that can be used to monitor SQL Server system activity are: • Sp_who • Sp_who2 • Sp_lock • Sp_spaceused • Sp_monitor Collaborate Lesson 3C / Slide 13 of 34 Stored procedures are a set of T-SQL statements. A stored procedure can accept input parameters for performing specified database operations. A stored procedure is also used to return values. These values enable database administrators to identify the success or failure of the specified database operation. Administering and Troubleshooting SQL Server 2000 3C.38 The following table lists the stored procedures that can be used to monitor SQL Server system activity: Stored Procedure Provides Information About Function sp_who Currently active users, active processes, and executing SQL statements Monitors currently active users and processes sp_who2 Current users and processes with additional information Monitors currently active users and processes sp_lock Current locks Monitors locks, deadlocks, and the processes causing these deadlocks sp_spaceused Estimates current disk space reserved and used by a table or a database Monitors the data pages in the database sp_monitor CPU usage, I/O usage, and Idle Time Monitors system throughput 3C.39 Administering and Troubleshooting SQL Server 2000 Built-in-Functions Collaborate Built-in-Functions • • ©NIIT Transact-SQL provides several built-in-functions, which are also known as T-SQL Globals. These built-in-functions are used to monitor specific system activities, such as performance statistics. The built-in-functions of Transact-SQL that can be used to monitor SQL Server system activity are: • @@CONNECTIONS • @@CPU_BUSY • @@IDLE • @@IO_BUSY • @@PACK_RECEIVED • @@PACK_SENT • @@PACKET_ERRORS • @@TOTAL_ERRORS • @@TOTAL_READ • @@TOTAL_WRITE Collaborate Lesson 3C / Slide 14 of 34 Transact-SQL provides several built-in-functions, which are also known as T-SQL Globals. These built-in-functions are used to monitor specific system activities, such as performance statistics. The information generated using these functions is stored in pre-defined SQL Server counters. These counters provide information to identify system activities that affect the performance of SQL Server. Administering and Troubleshooting SQL Server 2000 3C.40 The following table lists these built-in-functions of Transact-SQL: Built-in-function 3C.41 Function @@CONNECTIONS Counts the number of SQL Server 2000 connections including attempted connections @@CPU_BUSY Counts the time that the processor has spent working. This time is counted in milliseconds. @@IDLE Counts the time the SQL server has been idle. This time is also calculated in milliseconds. @@IO_BUSY Counts the time SQL Server has spent in performing input/output operations. This time is also counted in milliseconds. @@PACK_RECEIVED Counts the total number of input packets read from the network. @@PACK_SENT Counts the number of output packets written to the network. @@PACKET_ERRORS Counts the total number of network packet errors that have occurred on the connections. @@TOTAL_ERRORS Counts the total number of read/write errors that have occurred. @@TOTAL_READ Counts the total number of disk read operations performed. @@TOTAL_WRITE Counts the total number of disk write operations performed. Administering and Troubleshooting SQL Server 2000 Optimizing and Troubleshooting SQL Server System Activity Collaborate Optimizing and Troubleshooting SQL Server System Activity • • • To enhance the performance of SQL server, you can optimize and troubleshoot SQL Server 2000 system activities, such as connection, cache hits, locks, memory allocation, recompilation and transactional throughput. The objective of a database administrator while optimizing the performance of SQL Server is to minimize the response time for each query. As a database administrator, you can also achieve optimum database performance by maximizing the throughput of the database server. You can do this by reducing: • network traffic. • disk I/O. • CPU time for each query. ©NIIT Collaborate Lesson 3C / Slide 15 of 34 To enhance the performance of SQL server, you can optimize and troubleshoot SQL Server 2000 system activities, such as connection, cache hits, locks, memory allocation, recompilation and transactional throughput. The objective of a database administrator while optimizing the performance of SQL Server is to minimize the response time for each query. As a database administrator, you can also achieve optimum database performance by maximizing the throughput of the database server. You can do this by reducing: „network traffic „disk I/O „CPU time for each query To optimize database performance, you also need to analyze application requirements and database architecture. Administering and Troubleshooting SQL Server 2000 3C.42 Troubleshooting Connection Activity Collaborate Troubleshooting Connection Activity • ©NIIT 3C.43 Consider the scenario at Aztec Inc. Mac is the database administrator at the company, which maintains its database in SQL Server 2000. For the past few days, he has being receiving complaints from clients that they are unable to connect to the server. Mac has verified that the clients have necessary logon permissions to the server. He has also verified that both the client and server have identical network protocols installed. Mac consults David, a database consultant, to troubleshoot the problem. Collaborate Lesson 3C / Slide 16 of 34 Administering and Troubleshooting SQL Server 2000 Collaborate Troubleshooting Connection Activity (Contd.) • 1. 2. ©NIIT David suggests that Mac should try the following methods to troubleshoot the problem: Type ping IP_address | server_name at the DOS prompt on the client computer, to test the TCP/IP socket connection. Check for orphaned sessions on the server side. An orphaned session is a session that remains open on the server side even after the client computer has closed the session. You can use the sp_who stored procedure to track information about orphaned sessions. Collaborate Lesson 3C / Slide 17 of 34 Consider the scenario at Aztec Inc. Mac is the database administrator at the company, which maintains its database in SQL Server 2000. For the past few days, he has being receiving complaints from clients that they are unable to connect to the server. Mac has verified that the clients have necessary logon permissions to the server. He has also verified that both the client and server have identical network protocols installed. Mac consults David, a database consultant, to troubleshoot the problem. David suggests that Mac should try the following methods to troubleshoot the problem: 1. Type ping IP_address | server_name at the DOS prompt on the client computer, to test the TCP/IP socket connection. 2. Check for orphaned sessions on the server side. An orphaned session is a session that remains open on the server side even after the client computer has closed the session. These open sessions block server resources, such as cursors and locks. Thereby, affecting the performance of the database server. You can use the sp_who stored procedure to track information about orphaned sessions. In case, there are any orphaned sessions, you can use the kill statement to close the session and release the blocked resources. Administering and Troubleshooting SQL Server 2000 3C.44 Optimizing and Troubleshooting Locks Collaborate Optimizing and Troubleshooting Locks • • ©NIIT You can use SQL Profiler to trace occurrences of a deadlock. A deadlock is a condition where there is cyclic dependency between two or more users for a common set of resources. You can use the lock:cancel or lock:timeout events provided by SQL Profiler to track and identify locking problems. Collaborate Lesson 3C / Slide 18 of 34 You can use SQL Profiler to trace occurrences of a deadlock. A deadlock is a condition where there is cyclic dependency between two or more users for a common set of resources. Consider the following example to understand the concept of deadlock. Suppose a user, John, has exclusive lock on the stores table in the pubs database and a user, Peter, has exclusive lock on sales table in the same database. Peter wants to access the stores table that is already locked by John. John also wants to access the sales table. Both the users need to wait until the resources held by each of them are released. This condition is known as deadlock condition. You can use the lock:cancel or lock:timeout events provided by SQL Profiler to track and identify locking problems. 3C.45 Administering and Troubleshooting SQL Server 2000 Optimizing and Troubleshooting Memory Allocation Collaborate Optimizing and Troubleshooting Memory Allocation • ©NIIT Use the max server memory and min server memory options in the sp_configure system stored procedure to set the virtual memory size required by the SQL Server. Collaborate Lesson 3C / Slide 19 of 34 You can configure the virtual memory size based on the services currently running on the database server. You can use the max server memory and min server memory options in the sp_configure system stored procedure to set the virtual memory size required by the SQL Server. Administering and Troubleshooting SQL Server 2000 3C.46 Optimizing and Troubleshooting Recompilation Collaborate Optimizing and Troubleshooting Recompilation • ©NIIT You can recompile a stored procedure: • Using the WITH RECOMPILE statement when creating stored procedure, which recompiles the stored procedure every time it is executed. • Using the EXECUTE… WITH RECOMPILE statement, which creates the new execution plan, at that time. Collaborate Lesson 3C / Slide 20 of 34 The Query Analyzer in SQL Server creates an execution plan for a stored procedure, when you run the stored procedure for the first time. After the execution plan is created, the stored procedure is executed using the execution plan. This execution plan is used to execute the stored procedure. At times, you might need to create a fresh execution plan for a stored procedure. This process of recreating an execution plan is known as recompilation. You need to recompile a stored procedure if you have to use a stored procedure with varied input parameters. Some of these parameters might affect the JOIN and WHERE clause statements in the stored procedure. So the stored procedure must be recompiled, since a different set of rows needs to be generated every time the stored procedure is executed. You can recompile a stored procedure: „Using the WITH RECOMPILE statement when creating stored procedure, which recompiles the stored procedure every time it is executed. „Using the EXECUTE… WITH RECOMPILE statement, which creates the new execution plan, at that time. 3C.47 Administering and Troubleshooting SQL Server 2000 Improving SQL Server 2000 System Activity Collaborate Improving SQL Server 2000 System Activity • You can improve the performance of SQL Server 2000 system activity using the following: • Standby server • Clustering ©NIIT Collaborate Lesson 3C / Slide 21 of 34 You can improve the performance of SQL Server 2000 system activity using the following: „Standby server „Clustering Standby Server A standby server is a separate server that is used for storing a duplicate copy of the data stored in the primary server. As a database administrator, you can use a standby server as a backup in case the primary server fails or crashes. A standby server minimizes the loss of data due to failure of primary server. It also provides immediate functional support to all the applications that depend on the primary server. A standby server can be used: „as a mirror to the primary server for storing a duplicate copy of the data stored in the primary server. „as a backup arrangement to support applications in case the primary server fails. Administering and Troubleshooting SQL Server 2000 3C.48 „to reduce the burden on the primary server. For example, a standby server can be used for storing read-only copies of data or data that is not accessed frequently. You should ensure that the standby server should be synchronized with the primary server to maintain data consistency. SQL Server 2000 uses the concept of log shipping to synchronize a standby server with the primary server. The log shipping process uses SQL server Agent Jobs to synchronize the servers. The process involves backing up the transaction log files from the database on the primary server to a location on the standby server. The transaction log file is then used to update the database on the standby server. You can configure log shipping using the Database Maintenance Plan wizard. You can select a single database while configuring log shipping. However, if multiple databases are selected on the primary server, the log shipping option is disabled. Clustering SQL Server 2000 uses the SQL Server Failover Clustering feature to improve system performance and to provide failover support during a system failure. This feature enables multiple computers running on SQL Server 2000 to appear as a Virtual Server in a cluster. A cluster is a combination of multiple independent computers that work together and share a common name. You can install a virtual server during the SQL Server 2000 installation process. You can have multiple virtual servers in a cluster. Virtual servers are known as nodes. If a node in a cluster fails, it can be removed using the SQL Server 2000 setup program. The failed node can also be added again using the SQL Server 2000 setup program. INSTRUCTOR NOTES In this section, tell students about the concept of Standby Servers, Log Shipping, and Clustering. 3C.49 Administering and Troubleshooting SQL Server 2000 FROM THE EXPERT’S DESK Collaborate From the Expert’s Desk • • • • ©NIIT Best Practices Tips FAQs Challenge Collaborate Lesson 3C / Slide 22 of 34 In this section, you will identify the best practices for improving SQL Server system activity, using Standby Servers, Log Shipping, and Clustering. Administering and Troubleshooting SQL Server 2000 3C.50 Best Practices Improving the SQL Server System Activity Collaborate Best Practices Improving the SQL Server System Activity • • You need to maintain the integrity of data, to prevent data loss due to inefficiencies such as hardware failure. You can prevent data loss and maintain data consistency using: • Standby Servers • Log Shipping • Clustering ©NIIT Collaborate Lesson 3C / Slide 23 of 34 You need to maintain the integrity of data, to prevent data loss due to inefficiencies such as hardware failure. You can prevent data loss and maintain data consistency using: „Standby Servers: Standby servers are used to provide support to the primary server in case the primary server fails or crashes. Standby servers contain a duplicate copy of the database stored in the primary server. „Log Shipping: Log shipping is used to synchronize a standby server with the primary server. It uses SQL Server Agent Jobs to synchronize the servers. „Clustering: Clustering integrates multiple independent systems running on SQL Server 2000 to work as a single system under a single name. 3C.51 Administering and Troubleshooting SQL Server 2000 Tips Collaborate Tips ©NIIT • Consider a scenario where SQL Server fails to send notifications to operators by e-mail or pager. In this situation, as a database administrator, you should verify if MAPI compliant mail server is installed and configured on the SQL Server. MAPI is an interface of Microsoft Windows program that enables you to send and receive email within any Windows application. Collaborate Lesson 3C / Slide 24 of 34 Consider a scenario where SQL Server fails to send notifications to operators by e-mail or pager. To ensure that e-mail messages are sent to the operator, you need to configure SQLAgentMail to use a valid Messaging Application Programming Interface (MAPI) profile. SQLAgentMail is the mail service of SQL Server 2000 that is used for SQL Server Agent services. SQL Server Agent services are server components that run scheduled SQL Server 2000 administrative tasks. SQLAgentMail is used to send e-mail notifications to the designated users when scheduled tasks, such as database backup or recovery, succeed or fail. You can configure SQLAgentMail to send SQL Server alerts when specific event occurs. SQLAgentMail require MAPI client applications, such as Microsoft Outlook and MAPI messaging profile on SQL Server 2000 computer. MAPI is an interface of Microsoft Windows program that enables you to send and receive e-mail within any Windows application. Administering and Troubleshooting SQL Server 2000 3C.52 FAQs Collaborate FAQs Q. You are the database administrator of a company that maintains its database in SQL Server 2000. You have been receiving complaints from several end users that Query Analyzer gives a “Time Out” message while they are executing T-SQL statements. What will you do in this situation? Ans: If the users of the database get a “Time Out” message when they execute the queries, then database administrators should check the server for deadlocks. Some of the possible causes and corresponding solutions for resolving deadlocks are : • Long-running queries: If any T-SQL statement is taking time to return the result, it is possible that the table is locked. As a database administrator, you can reduce transaction time by optimizing T-SQL codes, optimizing indexes, and avoiding using cursors in queries • Cancelling queries: If users cancel their code that is running a query, it is essential that the users also roll back the transactions. If the code does not roll back the transaction the locks held by the query are not be released resulting in locking. ©NIIT 3C.53 Collaborate Lesson 3C / Slide 25 of 34 Administering and Troubleshooting SQL Server 2000 Collaborate FAQs (Contd.) Q. In which condition does the log shipping option get disabled? Ans. Log shipping allows the transaction logs from the primary server database to be constantly copied to the standby server database. You can only configure log shipping on one database at a time. If you select more than one database, the log shipping option on the Database Maintenance Plan wizard is disabled Q. How will you track SQL Server system activity? Ans. You can use SQL Profiler to keep a track on SQL Server system activity. ©NIIT Collaborate Lesson 3C / Slide 26 of 34 Collaborate FAQs (Contd.) You are a database administrator of a company that maintains its data in SQL Server 2000. The data file and transaction log file of the database are located on a 20 GB hard disk. You have configured each file to grow automatically. The data file currently occupies 15 GB. Which tool enables you to log the utilization of the hard disk by the data and log files? Ans. You need to use System Monitor to log the utilization of the hard disk, if the data and log files are configured to grow automatically. Q. ©NIIT Collaborate Lesson 3C / Slide 27 of 34 Administering and Troubleshooting SQL Server 2000 3C.54 Collaborate FAQs (Contd.) Consider the scenario of a company that uses SQL Server 2000 to maintain employee details. The company also uses Oracle to store inventory details. The Finance department has to compile certain reports from both the database servers. As a database administrator, you want to create these reports on the database server. What should you do in this case? Ans. You can create a linked server between the SQL Server and Oracle Server databases. You can then create a view to join the employee details database in SQL server and the inventory table in the Oracle Server to help the Finance department. Q. ©NIIT Collaborate Lesson 3C / Slide 28 of 34 „You are the database administrator of a company that maintains its database in SQL Server 2000. You have been receiving complaints from several end users that Query Analyzer gives a “Time Out” message while they are executing T-SQL statements. What will you do in this situation? If the users of the database get a “Time Out” message when they execute the queries, then database administrators should check the server for deadlocks. Some of the possible causes and corresponding solutions for resolving deadlocks are: x Long-running queries: If any T-SQL statement is taking time to return the result, it is possible that the table is locked. As a database administrator, you can reduce transaction time by: i optimizing T-SQL codes i optimizing indexes i avoiding using cursors in queries x Cancelling queries: If users cancel their code that is running a query, it is essential that the users also roll back the transactions. If the code does not rolls back the transaction, the locks held by the query are not released resulting in locking. 3C.55 Administering and Troubleshooting SQL Server 2000 „When does the Log shipping option get disabled? Log shipping allows the transaction logs from the primary server database to be constantly copied to the standby server database. You can only configure log shipping on one database at a time. If you select more than one database, the log shipping option on the Database Maintenance Plan wizard is disabled. „How will you track SQL Server system activity? You can use SQL Profiler to keep a track on SQL Server system activity. „You are a database administrator of a company that maintains its data in SQL Server 2000. The data file and transaction log file of the database are located on a 20 GB hard disk. You have configured each file to grow automatically. The data file currently occupies 15 GB. Which tool enables you to log the utilization of the hard disk by the data and log files? You need to use System Monitor to log the utilization of the hard disk, if the data and log files are configured to grow automatically. „Consider the scenario of a company that uses SQL Server 2000 to maintain employee details. The company also uses Oracle to store inventory details. The Finance department has to compile certain reports from both the database servers. As a database administrator, you want to create these reports on the database server. What should you do in this case? You can create a linked server between the SQL Server and Oracle Server databases. You can then create a view to join the employee details database in SQL server and the inventory table in the Oracle Server to help the Finance department. Administering and Troubleshooting SQL Server 2000 3C.56 CHALLENGE Collaborate Challenge 1. ©NIIT 3C.57 Mac is a database administrator at E-Soft Inc. The company is developing e-commerce applications using XML. He needs to install SQL Server 2000 in the development environment to query databases. Which service should he install with SQL server 2000 so that the employees can access data using XML query commands? Collaborate Lesson 3C / Slide 29 of 34 Administering and Troubleshooting SQL Server 2000 Collaborate Challenge (Contd.) 2. Crossword: 1 A 40 2 L 3 41 4 42 C 5 6 7 8 9 10 11 13 17 26 30 39 43 44 45 109 110 46 P 47 48 49 50 R 52 56 66 I 67 68 69 E 82 95 105 S 106 107 108 B 111 121 ©NIIT Collaborate Lesson 3C / Slide 30 of 34 Collaborate Challenge (Contd.) • ©NIIT Across : 1. (1, 11): This option displays the graphical format of all the counters. 2. (40, 11): This method is used to improve SQL server system activity. 3. (66,4) This is a built-in function to count the time when SQL Server stops working. 4. (105, 7) This concept is used to make a backup in case the primary server fails or crashes. Collaborate Lesson 3C / Slide 31 of 34 Administering and Troubleshooting SQL Server 2000 3C.58 Collaborate Challenge (Contd.) • ©NIIT 3C.59 Down : 1. (4, 10) This is used to improve the system performance and provide failover support. 2. (13, 4) This is used to place database files on multiple disks. Collaborate Lesson 3C / Slide 32 of 34 Administering and Troubleshooting SQL Server 2000 1. Mac is a database administrator at E-Soft Inc. The company is developing ecommerce applications using XML. He needs to install SQL Server 2000 in the development environment to query databases. Which service should he install with SQL server 2000 so that the employees can access data using XML query commands? 2. Crossword: 2 1 3 A 5 4 6 7 8 9 10 11 13 C 41 40 42 R 17 26 30 39 43 44 45 47 46 L 48 49 50 51 P 55 67 66 68 69 I E 82 95 106 105 107 108 S 109 111 110 B 121 Administering and Troubleshooting SQL Server 2000 3C.60 Across: 1. (1, 11): This option displays the graphical format of all the counters. 2. (40, 11): This method is used to improve SQL server system activity. 3. (66,4) This is a built-in function to count the time when SQL Server stops working. 4. (105, 7) This concept is used to make a backup in case the primary server fails or crashes. Down: 1. (4, 10) This is used to improve the system performance and provide failover support. 2. (13, 4) This is used to place database files on multiple disks. 3C.61 Administering and Troubleshooting SQL Server 2000 INSTRUCTOR NOTES Collaborate Solutions to Challenge Ans 1. Mac needs to install the IIS service to allow the employees to access data using XML query commands. ©NIIT Collaborate Lesson 3C / Slide 33 of 34 Administering and Troubleshooting SQL Server 2000 3C.62 Collaborate Solutions to Challenge (Contd.) 2. Crossword: 1 A 2 L 3 L 4 C 17 40 L 41 O 42 G 5 O 6 U 7 N 8 T 9 E 10 R 11 S L 30 U 43 S 44 H 45 I 46 P 47 P 48 I 49 N 50 G 13 R 26 A 39 I 52 D 56 T 66 I 105 67 S D 106 ©NIIT 3C.63 68 T L 107 A 69 E 82 R 95 I 108 N 121 G 109 D 110 B 111 Y Collaborate Lesson 3C / Slide 34 of 34 Administering and Troubleshooting SQL Server 2000 Solutions to Challenge: Ans 1: 1 2 3 4 5 6 7 8 9 10 11 13 A L L C O U N T E R S 17 R 26 L A 30 39 U 40 41 42 43 I 44 45 L O G S H I 46 47 48 49 50 P P I N G 51 D 55 T 66 67 I 68 69 D L E 82 R 95 I 105 106 107 108 109 110 111 S T A N D B Y 121 G Ans 2: Mac needs to install the IIS service to allow the employees to access data using XML query commands. Administering and Troubleshooting SQL Server 2000 3C.64 COLLABORATIVE EXERCISES INSTRUCTOR NOTES Group Discussion on IIS Virtual Directory BlueMun Corp. is a consulting firm and has two offices, in Washington DC and Detroit. Both the offices have Windows 2003 computers with SQL Server 2000 and IIS installed on them. The firm has been using SQL Server 2000 databases for a long time. The promoters of the firm want to share confidential data between the two offices using the Internet. They have employed you as the database administrator of the firm. You need to: „Configure IIS and SQL Server 2000 on the computers to allow data access. „Ensure that only the senior management should be able to access the database server using the Internet. „Audit successful and failed logins to the database server. What will you do to achieve the above stated objectives? 3C.65 Administering and Troubleshooting SQL Server 2000 Recommended Solution Divide the class in groups. Moderate the discussion based on the following points: „Configuring the IIS virtual directory to allow URL queries „Creating new Windows user accounts „Creating corresponding Windows authenticated logins on the database server „Configuring the IIS virtual directory to always use Windows authenticated logins when connecting to the database server To configure remote access and authentication modes a database administrator need to consider the following options: „Use XML enabled database server, to present the data on the web as XML pages in response to HTTP queries. The generated XML page can be used for exchanging information across different platforms. SQL Server 2000 supports XML to convert an SQL Server 2000 instance into an XML enabled database server. „Configure IIS virtual directory for exchanging data with an instance of SQL Server 2000 Server to enable access to SQL Server 2000 database objects, such as tables through Hypertext Transfer Protocol (HTTP). „Configure the Windows authentication mode to allow users to access data from remote tables. „Make necessary settings that allow users to execute queries by writing SQL statement in the URL. Administering and Troubleshooting SQL Server 2000 3C.66 [...]... Manager, as shown 3C.13 Administering and Troubleshooting SQL Server 2000 You have successfully created a linked server between the named cell, Book, in Excel and SQL Server Administering and Troubleshooting SQL Server 2000 3C.14 Creating a link to MS Access Collaborate Creating a link to MS Access • • ©NIIT Sandra also needs to create a link between the data in Access and SQL Server to compile the sales... Analyzer window toolbar to execute the query SQL Server displays a successful message in the message window of SQL Query Analyzer, as shown Administering and Troubleshooting SQL Server 2000 3C.18 8 Finally, close the SQL Query Analyzer window After creating a linked server, verify if the tables are available in SQL Server Perform the following steps, to verify the link between Access and SQL Server 1... 3C.19 Administering and Troubleshooting SQL Server 2000 You have successfully created a linked server between the table, Suppliers, in the Books database in Access and SQL Server Administering and Troubleshooting SQL Server 2000 3C.20 Alternative Methods to Monitor SQL Server System Activity Collaborate Alternative Methods to Monitor SQL Server System Activity • ©NIIT 3C.21 A database administrator... Manager window, and then expand the Microsoft SQL Servers option 2 Expand the SQL Server Group option and then expand the registered SQL Server instance option 3 Expand the Management option and select the Current Activity option, as shown 3C.35 Administering and Troubleshooting SQL Server 2000 The details pane displays the following three options: „Process Info: Using this option you can view and monitor... Administering and Troubleshooting SQL Server 2000 3C.28 Using the information displayed in the execution plan you can monitor execution of the queries, identify possible problems areas, and implement techniques to improve query processing and reduce the response time 3C.29 Administering and Troubleshooting SQL Server 2000 Using SQL Profiler to Monitor SQL Server 2000 System Activity Collaborate Using... to monitor SQL Server system activities In addition, a database administrator can use the following tools provided by SQL Server 2000, to monitor SQL Server system activities and performance of SQL Server 2000: • Query Analyzer • SQL Profiler • SQL Server Enterprise Manager • Transact -SQL Collaborate Lesson 3C / Slide 6 of 34 Administering and Troubleshooting SQL Server 2000 A database administrator... execute, and identify deadlocks Collaborate Lesson 3C / Slide 8 of 34 Administering and Troubleshooting SQL Server 2000 3C.30 Collaborate Using SQL Profiler to Monitor SQL Server 2000 System Activity (Contd.) • ©NIIT The following table lists the various pre-configured templates provided by SQL Profiler: • SQLProfilerSP_Counts • SQLProfilerStandards • SQLProfilerTSQL • SQLProfilerTSQL_Duration • SQLProfilerTSQL_Grouped... expand the Security option, as shown 3C.11 Administering and Troubleshooting SQL Server 2000 3 Click the Linked Servers option to view the linked servers 4 Expand the linked server, BOOKDETAILS to list the available objects in the server, as shown Administering and Troubleshooting SQL Server 2000 3C.12 5 Click the Tables option, to view the named ranges as tables The named ranges appear as tables in. .. monitor SQL Server system activities In addition, a database administrator can use the following tools provided by SQL Server 2000, to monitor SQL Server system activities and performance of SQL Server 2000: „Query Analyzer „ SQL Profiler „ SQL Server Enterprise Manager „Transact -SQL Statements Using Query Analyzer to Monitor SQL Server 2000 System Activity Collaborate Using Query Analyzer to Monitor SQL. .. 3C.25 Administering and Troubleshooting SQL Server 2000 Administering and Troubleshooting SQL Server 2000 3C.26 8 The Execution Plan tab page of the result pane displays the execution plan of the query in a step-by step manner You can place the mouse pointer on each step to display the system resources used by the query during its execution, as shown 3C.27 Administering and Troubleshooting SQL Server

Ngày đăng: 16/10/2015, 21:33

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan