Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Microsoft Access wikipedia , lookup
Commitment ordering wikipedia , lookup
Data vault modeling wikipedia , lookup
Serializability wikipedia , lookup
Expense and cost recovery system (ECRS) wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Relational model wikipedia , lookup
Versant Object Database wikipedia , lookup
Database model wikipedia , lookup
Ten Things Every Accidental DBA Needs to Know Now Cheat Sheet Security There are two types of security: o SQL Authentication – based upon a login / password combination o Windows Authentication – authenticates based upon the actively-logged-in user on a device. You’ll not supply a password. Logins exist at the server level -uniquely identified by an ID called a sid Users exist at the database level – uniquely identified by an ID called a sid If the login sid <> the user sid then the user is said to be “orphaned” and you’ll not be able to connect using that login. This is only an issue with SQL logins – not logins based upon Windows Authentication. There are various roles that exist at the server and database levels – sysadmin is the mostpowerful and should only be granted to those users that must be able to do everything on a SQL sever. db_owner is the database-level counterpart. Only assign to individuals who would need to have the ability to do everything against a database – including dropping it. You can create your own roles and assign users appropriately. The sa login is the default “god” login on every server (you can eliminate that if you don’t build a SQL instance with “Mixed” Authentication. Since this login exists and is the most powerful it’s frequently subject of hack attempts. You can rename this login then create a new login called “sa” and grant it minimal rights – then monitor for its use – this is called a “honeypot”. Think of schemas as collections of objects in a database. You can set rights – and limit rights – to specific schemas and set default schemas for all users. This is a valid security and organizational construct. Configuration Manager Use CM to control all services. Do not use the services.msc tool to start, stop, change any SQL service. Corruption can occur. You can also set what protocols are used for access: named pipes, shared memory, tcp/ip. You can change the ports SQL listens on here. By default SQL listens on port 1433. If using a non-default port number be sure that it’s static – not dynamic – for most installs. SSMS Tips & Tricks Registered Servers o Can use this tool as a storage unit of connections – can share via export o Can group multiple servers; registrations don’t need to be unique o Can use groups to execute the same query against multiple instances at once. o Color Coding o Non-Default ports: register with server_name,port_number Template Explorer o Predefined scripts – can create own o Construct for template parameters: <param_name, optional descriptor, default_value> o Control+Shift+M to replace parameter values When results are in grid view can copy and paste from SSMS to Excel and other tools via Control+C and Control+Shift+C (to include column names in export.) You can drag and drop from the Object Explorer to a query window Suggest including BEGIN TRANSACTION at the start of every new query so if you hit “Execute” by mistake you can roll back the code. Server Options You’ll want to ensure the options on the Database Options tab are set: o Default Data Location o Default Log Location o Default Backup Location You’ll want to adjust the default values under the Advanced tab for: o Max Degrees of Parallelism – recommend leaving at 0 which allows SQL to determine if a query goes parallel – just how many cores are involved in the parallel process(es) o Cost Threshold for Parallelism – determines at what “cost” a query goes parallel. Cost is an advanced term but the default value of 5 is way too low to start with. I recommend starting at 50 and adjusting if you see too much or not enough parallelism. Database Options The key options you want to pay attention to here are: o Recovery Model – set to Simple if the need for point-in-time recovery is not important. If you set to Full or Bulk-Logged be sure to configure transaction log backups for the database. o Auto Create and Auto Update Statistics – for almost every instance I recommend these be set to on. If you are dealing with a very large database you still may need to manually update statistics from time-to-time since the trigger for auto updating stats is based upon a percentage of rows changed to the total number of rows. Statistics is “data” about your data – histograms of how it’s distributed. This information is critical for SQL creating and choosing the right query plan for a request. o Owner – the owner of a database has complete control. Set it wisely. It defaults to whomever created or restored a database so keep in mind that you may need to reset it after a restore. o Auto Close and Auto Shrink – I’ve yet to see a good reason for these to be turned on. Make sure they’re set to Off. Auto Shrink wreaks havoc with the transaction log and performance as a result. Files Data Files – multiple data files splitting IO across multiple underlying LUNs possibly in a high-IO environment for performance improvements. Splitting Indexes from tables also can improve performance. Transaction Log File – only one per database – you can create more but don’t. Works in roundrobin format. Once the log file hits the end it will re-use itself granted there have been checkpoints and log backups taken. If not it will continue to grow until one of those things happen or the underlying volume is completely consumed. If that happens the database is essentially dead since no new transactions can be logged and written to disk. Use flash storage of some kind or if using SAN-based storage try to use RAID 5 for data files and RAID 1+0 for transaction log files to improve performance. Backups Full o A complete copy of the database at that state; also includes some bits of in-flight transactions from the transaction log too. Transaction Log • Only available if database is in Full or Bulk-Logged recovery • This is the only type of backup that will “clear” the transaction log if in Full or BL • Includes transaction info for DDL and DML that are: Not persisted in full backup Or last transaction log backup Or last differential backup. Differential • All committed transactions written to data file since last full backup • Will continue to get larger until next full backup is run • Can compress backups Restore • Restores are more important than backups • Can restore databases, files, filegroups, or pages • Practice restores and backups regularly to test both backup validity and restore process. • In full recovery you’d restore in following order: 1. Last full backup prior to time you want to restore to. Followed by 2. Any differential backups taken between the full backup and the time to restore to. Then 3. All transaction logs in sequence to get you to the point of recovery. • Leave database in restoring state between each restore step by ensuring the WITH NORECOVERY command is used in the restore statement.. Bring a database online using WITH RECOVERY SQL Agent SQL Agent is your 24 hour DBA. Use it to schedule jobs that can execute SQL commands, PowerShell statements, VBscript, SSIS packages… Set Database Mail, alerts and operators to get notifications should a critical issue occur. Free Tools • Ola Hallengren (olahallengren.com) Maintenance Solution • sp_whoisactive performance analysis solution from Adam Machanic. • Plan Explorer from SQL Sentry