how to extract tweets about...
This was the Powershell code I used to create the all the podcasts I’ve ever tweeted about post.
I downloaded the tweets from Twitter itself - I think there was a link somewhere within ‘Settings’
The .csv file looks like this:
So the code is:
$PodTweets = Import-Csv c:temptweets.csv | ? text -like "*podcast*"
$TweetsAsHtml = foreach ($P in $PodTweets)
{
# write-output $P.timestamp.Substring(0,10)
# Splitting the tweet text into words to allow for the processing of urls
$TweetTextAsArray = $P.text.split(" ")
$TextWithLink=""
foreach ($Word in $TweetTextAsArray)
{
if ($Word -like "http:*")
{
# if there is an expanded_url, then use that instead
if ($P.expanded_urls -ne "")
{
$Word = $P.expanded_urls
# for some reason the expanded url is sometimes repeated in the download
if ($Word -like "*,*")
{
$Word = $Word.split(",")[0]
}
}
# re-format the URL as a link
$Word = "`<a href=`"$Word`"`>$Word`<`/a`>"
}
$TextWithLink = "$TextWithLink$Word "
}
# create an object and output that
$properties = @{'TweetDate'=$P.timestamp.Substring(0,10);
'TweetText'=$TextWithLink}
$ReformattedTweets = New-Object -Type PSObject -Prop $properties
write-output $ReformattedTweets
}
$TweetsAsHtml | fl | out-file -encoding ascii -FilePath x.txt -width 1000
show sql errorlog messages since a specified date
This almost speaks for itself…but it might be worth noting that:
-
I’m only interrogating the latest file here
-
it’s a teeny bit cumbersome - I would probably function-alize it
-
the big advantage here compared to the GUI is you can cut-and-paste it really easily
dir sqlserver:sql\the_server_name
$logs.readerrorlog(0) |
where logdate -gt ([datetime]::ParseExact('25/02/2015 07:27:36',"dd/MM/yyyy HH:mm:ss",$null)) |
select processinfo, text |
ft -a -wrap
system databases not included in powershell sqlserver provider 'databases' folder
I hadn’t noticed this before.
If you do a dir listing of the databases for an instance within the Powershell Sqlserver provider, it doesn’t show the system databases
PS C:powershell> dir SQLSERVER:\SQL\my_pcinst2012\databases
Name Status Recovery Model CompatLvl Collation Owner
---- ------ -------------- --------- --------- -----
AdventureWorks2012 Normal Simple 110 SQL_Latin1_General_CP1_CI_AS matty
TSQL2012 Normal Full 110 Latin1_General_CI_AS matty
To get a listing for the system databases you can do the following. I would imagine there’s a better way (perhaps some equivalent to ls -a?)…but I can’t think of it at the minute1
PS C:powershell> foreach ($DB in ("master", "msdb", "model", "tempdb")) {gi SQLSERVER:\SQL\my_pcinst2012\databases\$DB }
Name Status Recovery Model CompatLvl Collation Owner
---- ------ -------------- --------- --------- -----
master Normal Simple 110 Latin1_General_CI_AS sa
msdb Normal Simple 110 Latin1_General_CI_AS sa
model Normal Simple 110 Latin1_General_CI_AS sa
tempdb Normal Simple 110 Latin1_General_CI_AS sa
-
The ‘better way’ is to use
gci -force
. That includes all the system databases. ↩︎
penflip markdown cheatsheet
This is extracted from Adam Pritchard’s Markdown Cheatsheet.
It’s what I would see as the useful bits….but of course my useful bits won’t be the same as your useful bits!
Feature | Code |
---|---|
Heading | # |
Bold | __bold__ |
Italics | _italics_ |
Strikout | ~~italics~~ |
Numbered list | 1. First |
Numbered list | __1. First second level with space not underscores |
Numbered list | 2. Second |
Numbered list | __Indent under list with space not underscores |
Link | [Link](https://mattypenny.net) |
Image |  |
Footnotes | [^1].<br>[^1]: Here is the footnote. |
Escape | _ |
Blockquotes | > Blockquote |
Line | --- |
Html | Use html tags |
sql server 2005 install hangs at 'Removing Backup Files'
I’m installing sqlserver 2005, and it seemed to hang towards the end of the installation.
The installer hung while it was installing ‘Workstation Components, Books Online’, with the progress message being ‘Removing Backup Files’. As it happened I kicked this off at the end of the day, and it was still hanging the next morning
I checked the installer log but there was nothing very interesting
<Func Name='LaunchFunction'>
Function=Set_CommitFlag
<Func Name='GetCAContext'>
<EndFunc Name='GetCAContext' Return='T' GetLastError='0'>
Doing Action: Set_CommitFlag
PerfTime Start: Set_CommitFlag : Mon Jan 26 16:46:51 2015
<Func Name='Set_CommitFlag'>
Can I commit?
Set_CommitFlag called successfully.Committed
<EndFunc Name='Set_CommitFlag' Return='0' GetLastError='0'>
PerfTime Stop: Set_CommitFlag : Mon Jan 26 16:46:51 2015
<EndFunc Name='LaunchFunction' Return='0' GetLastError='0'>
It turned out to be very much a problem between the chair and the keyboad.
At the start of the install I’d had this warning message:
I wasn’t too worried about it - I’m installing an old version of SQL on a newer OS - but I left the warning message window open…partly so that I could investigate further later.
Anyway…as soon as I shut that warning window down, the install kicked back into life and soon completed.
sql server 2005 install hangs at 'Removing Backup Files'
I’m installing sqlserver 2005, and it seemed to hang towards the end of the installation.
The installer hung while it was installing ‘Workstation Components, Books Online’, with the progress message being ‘Removing Backup Files’. As it happened I kicked this off at the end of the day, and it was still hanging the next morning
I checked the installer log but there was nothing very interesting
<Func Name='LaunchFunction'>
Function=Set_CommitFlag
<Func Name='GetCAContext'>
<EndFunc Name='GetCAContext' Return='T' GetLastError='0'>
Doing Action: Set_CommitFlag
PerfTime Start: Set_CommitFlag : Mon Jan 26 16:46:51 2015
<Func Name='Set_CommitFlag'>
Can I commit?
Set_CommitFlag called successfully.Committed
<EndFunc Name='Set_CommitFlag' Return='0' GetLastError='0'>
PerfTime Stop: Set_CommitFlag : Mon Jan 26 16:46:51 2015
<EndFunc Name='LaunchFunction' Return='0' GetLastError='0'>
It turned out to be very much a problem between the chair and the keyboad.
At the start of the install I’d had this warning message:
I wasn’t too worried about it - I’m installing an old version of SQL on a newer OS - but I left the warning message window open…partly so that I could investigate further later.
Anyway…as soon as I shut that warning window down, the install kicked back into life and soon completed.
Problem: php commenting out not working in wordpress
This was a bit of a ‘Duh!’ moment.
I use the following to ‘comment out’ chunks of Wordpress pages that I’m still working on
<?php /*
Some old rubbish that I have'nt finished working on yet
*/?>
This seemed to have ‘stopped working’.
The reason was my ‘Exec-PHP’ plugin was de-activated. I don’t remember de-activating it. I guess it’s possible that an automat(t)ic update might have done so, but I don’t know.
How to do a sql server equivalent of Oracle 'set feedback on'
I haven’t been able to find a T-sql equivalent of the Oracle ‘set feedback on’, which outputs a line telling you how many rows have been effected by the last sql statement.
The closest thing, I think, is:
select 'Rows updated: ' + CAST(@@ROWCOUNT as varchar(10))
How to generate the t-sql to disable all your triggers
This seems to work:
SELECT
'disable trigger ' + USER_NAME(trig.schema_id) + '.' + trig.name +
' on ' +
USER_NAME(tab.schema_id) + '.' + OBJECT_NAME(trig.parent_object_id) +
char(10) +
'go'
FROM sys.objects trig
INNER JOIN sys.objects tab
ON trig.parent_object_id = tab.object_id
WHERE trig.type = 'TR'
It generates sql like this:
disable trigger dbo.tr_AfterUpdate on dbo.BigTable
go
disable trigger dbo.tr_BeforeUpdate on dbo.BigTable
go
How to generate the t-sql to disable all your triggers
This seems to work:
SELECT
'disable trigger ' + USER_NAME(trig.schema_id) + '.' + trig.name +
' on ' +
USER_NAME(tab.schema_id) + '.' + OBJECT_NAME(trig.parent_object_id) +
char(10) +
'go'
FROM sys.objects trig
INNER JOIN sys.objects tab
ON trig.parent_object_id = tab.object_id
WHERE trig.type = 'TR'
It generates sql like this:
disable trigger dbo.tr_AfterUpdate on dbo.BigTable
go
disable trigger dbo.tr_BeforeUpdate on dbo.BigTable
go
How to use t-sql to show SSRS permissions
I’m not great at T-sql, and I know that cursors are unfashionable in Microsoft world, but this gives me the output I want, as below:
Path | Username | GrantedPermissions |
/Data Sources | cfcjmourinho | Browser,Content Manager,My Reports,Publisher,Report Builder |
/Data Sources/Statszone | BUILTINAdministrators | Content Manager |
/Data Sources/Statszone | cfcjmourinho | Browser,Content Manager,My Reports,Publisher,Report Builder |
/Data Sources/Statszone | cfcjmourinho | Browser,Content Manager,My Reports,Publisher,Report Builder |
/zTest/By far the greatest team report | cfcjmourinho | Browser,Content Manager,My Reports,Publisher,Report Builder |
/zTest/By far the greatest team report | cfcbbuck | Browser |
/zTest/By far the greatest team report | cfcrfaria | Content Manager |
drop table #ReportPermissions
create table #ReportPermissions
(Path varchar(100),
Username varchar(100),
GrantedPermissions varchar(100))
declare
UserWithPermissionsCursor cursor for
select -- ,roles.[RoleID]
rolename
-- ,users.[UserID]
,username
-- ,catalog.[PolicyID]
,path
FROM [ReportServerRep01].[dbo].[PolicyUserRole],
roles,
users,
catalog
where policyuserrole.RoleID = roles.roleid
and policyuserrole.UserID = users.userid
and policyuserrole.policyid = catalog.PolicyID
order by path, username, rolename
declare @rolename varchar(100)
declare @username varchar(100)
declare @path varchar(100)
declare @PermissionsString varchar(100)
declare @Savedusername varchar(100)
declare @Savedpath varchar(100)
open UserWithPermissionsCursor
FETCH UserWithPermissionsCursor INTO @rolename, @username, @path
WHILE 0 = @@fetch_status
BEGIN
if (@SavedUserName = @username AND @SavedPath = @path)
set @PermissionsString = @PermissionsString + ',' + @Rolename
else
begin
-- Output the line
insert into #ReportPermissions
(Path,
Username,
GrantedPermissions)
values
(@SavedPath,
@SavedUserName,
@PermissionsString)
-- Reinitialize variables
set @SavedPath = @path
set @SavedUsername = @username
set @PermissionsString = @rolename
end
FETCH UserWithPermissionsCursor INTO @rolename, @username, @path
END
close UserWithPermissionsCursor
deallocate UserWithPermissionsCursor
select * from #ReportPermissions
Problem: ssrs error: 'System.Data.OracleClient requires Oracle client software version 8.1.7 or greater'
A quick post on a quick fix.
I installed Sql Server Reporting Services 2008 R2 on the report server, then installed Oracle client 11.2.0.4.
I copied across a valid tnsnames.ora file, and verified connectivity with both sqlplus and tnsping.
However, trying to connect to one of the Oracle databases from within SSRS I got:
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
…helpfully highlighted in an angry red.
Fix is fairly straightforward - SSRS hadn’t picked up the change to %PATH% done by the Oracle install yet, so the fix was to re-start the SSRS service.
Problem: ssrs error: 'System.Data.OracleClient requires Oracle client software version 8.1.7 or greater'
A quick post on a quick fix.
I installed Sql Server Reporting Services 2008 R2 on the report server, then installed Oracle client 11.2.0.4.
I copied across a valid tnsnames.ora file, and verified connectivity with both sqlplus and tnsping.
However, trying to connect to one of the Oracle databases from within SSRS I got:
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
…helpfully highlighted in an angry red.
Fix is fairly straightforward - SSRS hadn’t picked up the change to %PATH% done by the Oracle install yet, so the fix was to re-start the SSRS service.
Powershell pattern matching to check if a string is hex
I’ve been playing with pattern matching in Powershell.
I was trying to use ‘-match’ to ‘Check if the string is a hexadecimal number’ for the ‘Perl one-liners in Powershell’ page I’ve been working on.
I can’t pretend to entirely understand or explain pattern matching in Powershell, or in linux, but this seems to work.
$X = "21e" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}"
This says match the string against ‘any combination of the characters within the square brackets (i.e. the hex digits) to the same length as the original string’.
So, the square brackets contain the allowable characters.
The curly brackets give the number of characters.
I tried just doing:
$X = "21e" ; $X -match "[0123456789abcde]{$X.length}"
…but this didn’t seem to work.
Tests
I tried the following strings - they all seemed to come up with the right answer: ``` $ $X = "21e" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" True $ $X = "21edjhsd" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" False $ $X = "21e34782348237847832748723" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" True $ $X = "21e34782348237847832748723f" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" False $ $X = "21e34782348237847832748723acbdaaa" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" True $ $X = " " ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}" False ```….although I’m not sure whether this is right or wrong:
$ $X = "" ; $Y = $X.length ; $X -match "[0123456789abcde]{$Y}"
True
notes about wordpress version of salisburyandstonehenge.net
This page is a bit of documentation for how I do stuff on the multifarious websites that I’ve perpetrated over the years. These are very much notes for myself but if anybody else should happen upon this page I hope you find it useful :)
On This Day - how it works
These are a couple of vim things I use regularly.
My local history website has a list of stuff that happened on this day' in Salisbury’s history
I maintain the list by adding a page for each event into a Wordpress page structure that looks like this:
- on-this-day
- month
- event page, title of which is prefixed by the date
I fill in the event pages' ‘Order’ field (under ‘Page Attributes’) with the day of the month. The months' ‘Order’ field has the ‘number of the month’ (i.e. 1 is January, 2 is February etc). This keeps everything in order.
Then the top level page has this:
<ul class="sitemap-pages">
I think I’m going to change this to have a separate wp_list_pages for each month. This will allow me to have a table of contents, although it will slow it down, I guess.
On This Day - reformatting from dynamic list of Wordpress child pages to static list for the weekly post
Anyhoo, I use the top level list to create a weekly post, summarizing that weeks events in Salisbury history.
There are a couple of vim things that help me do that.
When I grab the page source from the top level list, each page looks like this:
<li class="page_item page-item-7354"><a href="/on-this-day/april/28th-april-1948-terry-pratchetts-birthday">28th April 1948 - Terry Pratchett's birthday</a>
which looks like this on the page:
I could just cut and paste that, but I think it looks a little bit nicer, in the context of a post to do the following, in gvim.
This removes the ‘class=“page_item page-item-7354”’ bit. I’m not sure what it’s for but I’m pretty sure it’s not useful in this context
:%s/ class="page_item page-item-[0-9][0-9]*"//
Then I’m moving the date out of the anchor text to the start of the line. I could probably do this in one hit, but for the time being I’m mapping a key and then executing it manually once for each line
:map b />[0-9]ld4w0lllp
Then typing ‘b’ renders the html like this:
<li>6th April 1967 - <a href="/on-this-day/april/6th-april-1967-pink-floyd-play-salisbury-city-hall">Pink Floyd play Salisbury City Hall</a>
…which looks like this:
I prefer this for the posts.
On This Day - reformatting for the Parish Mag
A slight variation on the above - this is for re-formatting the On This Day stuff for the Parish mag
map q /[0-9][0-9][0-9][0-9] dw$A (pi).
then
/ May
cw:
WH Smith Deep Linking
Get the Deep Link
Go to the Deep Link page:
https://www.affiliatewindow.com/affiliates/customise_link.php?mid=3017
Paste in the URL from the product page:
This generates a Deep Link:
<a href="http://www.awin1.com/cread.php?awinmid=3017&awinaffid=171527&clickref=Notes%20From%20a%20Small%20Island&p=http%3A%2F%2Fwww.whsmith.co.uk%2Fproducts%2Fnotes-from-a-small-island%2Fproduct%2F9780552996006" target="_top">WHSmith</a>
For a simple text link that’s all you need.
For the picture credit, book end the text link with:
Pic: The book cover is an ‘affliate link’, which means that if you click on it it will take you to the
and
If you buy anything on Smith’s website I get a commission. The image is copyrighted, but because it’s essentially a way of advertizing the product, so I think that this is ‘fair use’
To turn this into a picture link
Insert the image as normal. This gives you some html like this:
``````
Replace the anchor text section (i.e. ‘WHSmith') with the image spec from what was inserted from the Wordpress gallery
<a href="http://www.awin1.com/cread.php?awinmid=3017&awinaffid=171527&clickref=Notes%20From%20a%20Small%20Island&p=http%3A%2F%2Fwww.whsmith.co.uk%2Fproducts%2Fnotes-from-a-small-island%2Fproduct%2F9780552996006" target="_top"><img src="/images/Bill-Bryson-Notes-from-a-Small-Island-192x300.jpg" alt="Bill Bryson - Notes from a Small Island" width="192" height="300" class="alignright size-medium wp-image-9114" /></a>
Problem: SSIS: 'Hresult: 0x800703E6 Description: Invalid access to memory location'
Problem came up trying to connect to a remote Oracle source:
Started: 12:03:03
Error: 2013-10-09 12:03:03.84
Code: 0xC0202009
Source:
Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x800703E6.
An OLE DB record is available. Source: "Microsoft OLE DB Service Components" Hresult: 0x800703E6 Description: "Invalid access to memory location.".
End Error
Error: 2013-10-09 12:03:03.84
Code: 0xC020801C
Source: Copy Data
Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "xxx" failed with error code 0xC0202009. There may be error messages posted before this with more information on why the AcquireConnection method call failed.
End Error
Error: 2013-10-09 12:03:03.84
Code: 0xC0047017
Source: xxxx
Description: component "xxx" (1) failed validation and returned error code 0xC020801C.
End Error
DTExec: The package execution returned DTSER_FAILURE (1).
Fix was to go into job step properties, select the ‘Execution options’ tab and click on ‘Use 32-bit runtime’.
I’m wondering whether we had an Oracle 32-bit install, or a 32-bit install that wasn’t entirely removed
24Hop Notes
Clustering Conundrum - Allan Hirt
Running some HA classes in Europe.
Loose definition - networked servers.
Used in different contexts in sqlserver - clusterered indexes, SETI type stuff, windows clusters, NLB, WSFC
- Windows - network load balance, windows server failover cluster(wsfc)
- Sqlserver - failover cluster instance
Can’t have the latter without the former
Sqlserver built on WSFC
75% of problems tend not to be SS
Resource group - like a folder of resources
Resources are often interdependent
Quorum - what you need to have to be up or down
Has become much easier from 2008 onwards.
Availability Groups - are sql-level
www.sqlha.com/2012/01/0… www.sqlha.com/2013/04/2…
Need to get involved with the Windows very heavily - can’t just do the sql bit. <— big takeaway
DBAs tend to become expert in Windows clustering
Can’t convert a standalone instance to cluster. Has to be new install.
Can do a 2-node cluster at Standard Edition.
2008 needs to be Windows Enterprise. 2012 onwards can be standard or datacenter editions
You get a ‘tranport error’ during failover, but SSMS, at least, automatically failsover.
Got to have AD
Only one default instance per WSFC, but can have multiple instances on one WSFC
Keys to success Learn WSFC Validation can show up problems Need to have test clustered instances Need to be an WSFC expert
www.sql ha.com MS Cluster Team blog KBs: find the slide
Hands-on fundamentals for good SQL programming - Kevin Kline
Test harness needs: dbcc freeproccache dbcc dropcleanbuffers set statistics time set statistics io set showplan text|xml
sys.dm_os_performance counters sys.dm_os_wait_stats
sqlskills.com - Glenn Berry
Scan count - number of scans! Reads - in 8K pages Read-ahead - it dynamically goes multi-page read (i.e. multiblock reads)
set showplan_text on - does the command line style explain plan
clustered index scan is equivalent of an Oracle FTS, because, by default tables are held in clustered indexes
Can set statistics time and i/o from within the toolbar
Worth enabling:
-
estimated execution plan and
-
actual execution plan
-
it shows up differences, which can show problems with statisitcs etc
Sys.dm_os_wait_stats
- shows bottlenecks
Sys.dm_exec_query_stats
- query performance stats
sys.dm_db_index_usage_stats
sys.dm_io_virtual_file_stats
Queries from SQLAgent man ?
Spools are red flags.
As are, scans, parallelism
Kimberly Tripps articles on ‘indexes from every angle’
Window Function Fundamentals - Christina Leo
Stuff like:
SELECT empid, ordermonth, qty, SUM(qty) OVER(PARTITION BY empid ORDER BY ordermonth ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS runqty FROM Sales.EmpOrders;
Indexing segment and sequence operators in Explain Plan
Index should be POC
- Partition
- Ordering
- Columns
Even if this doesn’t improve the elapsed time of the query it will eat up less memory.
The where clause happens before the select, so the filter happens before the Window function kicks in
CTE - the view thing at the top of the query with the WITH
Powerpivot - Susan O'Connell
Self service BIFree add-in in 2010, native in 2013
Very worthwhile to leeave stuff out of the data model, both for performance and so as to simplify from a user perspective.
There are options to hide stuff from the users anyway.
Needs 8G of RAM on client
Data Internals - Bradley Balls
@sqlballs
Why learn internals - it conveys the idea that you know what you’re talking about!
Byte swapping - swaps hex pairs to protect proprietry data
dbcc ind dbcc page dbcc traceon(3604) -output goes to smss window
Record structure
- Tag bytes
- null bitmap
- fixed length
- null bitmap
- variable offset attay
- variable length columns
forwarding records - only in heaps like chains in Oracle
- only occurs in heaps
Text records
- LOBS > 8000 bytes (or sometimes 4000 bytes)
- 24 byte pointer to LOB
Ghost record
- deleted record left in place for undo optimization
- when in snapshot isolation mode
Versioned Records
- when Version Store os used. e.g. got online index rebuilds
MCM Video Series - especially
Record structure
- Tag bytes
- null bitmap
- fixed length
- null bitmap
- variable offset attay
- variable length columns
In the bitmap, 1 is null, 0 is not null
Record structure
- Tag bytes
- null bitmap
- fixed length
- null bitmap
- variable offset attay
- variable length columns
Pages
Data page header 96 bytes data 8096 bytes Row offest array (aka slot array) at the bottom
Index page leaf non-leaf
Text text tree lob text mox slob
sort
boot page 1:9 in any database dbcc page (‘db name’ , 1, 9, 3) - shows lots of boot info about database <— worth doing
Extents
- grouping of 8 pages
Allocation bitmaps
- free pages and allocated pages
Structure is: page is allocated is mixed allocation page is iam page page has ghosted rows space indicator - 3 bits show whether over 10% full, 30% full etc
IAM page
Storage and Virtualization - Denny Cherry
@mrdenny says 'noise in the data centre can slow down data retrieval' . Interesting - would never have thought of that #24hopWith Fusion IO, disk i/o is no longer the bottleneck
OLTP systems don’t much use the SAN cache because they don’t tend to use the same data twice. Data warehouses get more value because of pre-fetching.
Implies San cache is more about pre-cacheing than re-use
Force flushing effectively disables the cache until it’s finished. Don’t want to do it Low-water mark should be around 20% - you don’t want to be flushing immediately High-water mark 90% - because force flushes are bad
Power failure - most arrays have internal batteries.
Planned outage - MUST shut down sql server before the cache flushes.
Disk alignment matters
Big Data Visualization for Business Intelligence Professionals - @JenStirrup
eye vegetables as well as eye candy Garner: 50% of data is unused Frawley quote on fountain of wisdom vs flood if data Challenger chart - the box of crayons Powerview - specific business questions Powermap - business mysteries Powerpreviw ?Powerview - anti-spiderman. great power, but no responsibility for the data
Powermap -3d excel plugin. Formerly known as geo flow
Hortonworks sandbox- free download with hadoop stuff
Database Design - @DataAudrey
Worth going through the slide deck at some stage - a bit too sleepy at the minute!Availabilty Groups - Joe Dantoni
ex-Entergy chap!
Valid DR plan - we can do without system X, but not system Y.
Dilbert Our Disaster Recovery Plan Goes Something Like This <— google this
HA DR
Clustering works well from windows/sql 2008 on, but it’s not a DR solution.
Most cloud providers don’t charge for inbound data.
RPO - recovery point objective. How much data can we afford to lose? RTO - recovery time objective. How long can we do without a system?
Everything should be written down, and executive signed off.
Free Azure capacity with MSDN ? are we DR-ing Reporting Services?
Software as a service - gmail, salesforce.com
Infrastructure as a service - Azure, Amazon
platform as a service - Azure SQL, Amazon Relational Database Service
Sql azure now knwon as Windows Azure Sql Database (WASD).
Security in the Cloud
- are your security standards as good as Microsoft or Amazons
MS compliant with SOX and European regulations
Always On Availability Groups
- doesn’t need shared storage
- can go across IP subnets
- can therfore be a DR solution
Is based on log shipping(?)
Availability Groups is standard only, but there are ways of doing log-shipping. No failover capacity in standard.
Dont quite get why you nedd wsfc
Scalability - Glenn Berry
Largest sql database 350Tb Largest OLTP 17TbCommon issues:
- overuse of query generators
- ad-hoc sql from the application
- lots of xml columns
- user-defined functions
- too much business logic in the database
- overuse of DML triggers
- overuse of CLR assemblies
Glenn has sql server diagnostic information queries <—-worth downloading
Intel tick-tock release strategy
Servers are like pets - scale up Servers are like cattle - commodity
Problem: 'Access is denied. [0x80070005]' when changing sql server agent login
Trying to change the sql server agent to run as a non-admin user, I couldn’t get Sql Server Agent to work without giving it administrator privileges. I got:
WMI Provider Error
Access is denied. [0x80070005]
OK
You have to grant two privileges - both the Agent User and the MSSQL user.
- SQLServerSQLAgentUser$bigserver$inst01
- SQLServerMSSQLUser$bigserver$inst01
Problem: 'Access is denied. [0x80070005]' when changing sql server agent login
Trying to change the sql server agent to run as a non-admin user, I couldn’t get Sql Server Agent to work without giving it administrator privileges. I got:
---------------------------
WMI Provider Error
---------------------------
Access is denied. [0x80070005]
---------------------------
OK
---------------------------
You have to grant two privileges - both the Agent User and the MSSQL user.
- SQLServerSQLAgentUser$bigserver$inst01
- SQLServerMSSQLUser$bigserver$inst01
Mis-spelling in Powershell
This was spectacularly incompetent even by my high standards of incompetence.
It illustrates that if you spell the name of a column incorrectly in Powershell, you don’t get an error, you just get a null column
get-wmiobject -class win32_operatingsystem -computer rdm016 |
select __Server, ServicePackMajorVerstion
And got:
__SERVER ServicePackMajorVerstion
-------- ------------------------
RDM016
I thought that no service packs had been applied. This, as more attentive readers will have spotted, was not the case. The null under ServicePackMajorVerstion is because you don’t spell ‘version’ with a ’t'. Two learnings from this:
- one should test one’s code
- if you put something invalid in a ‘select’ list in Powershell it won’t necessarily error
How to report mp3 tags in Powershell
I’m slowly getting to grips with Powershell.
# -----------------------------------------------------------------
# Script - Catalog-MP3s.ps1 #
# Gets mp3 tags from the mp3 file.
# -----------------------------------------------------------------
# Parameter is either a directory or an individual mp3 Param ( $P_DIR_OR_MP3 )
# --------------------------
# Function: get-mp3info
# The function gets the tags
# for the specified mp3
# --------------------------
Function get-mp3info ($P_MP3)
{
# Get the tages into a variable
$TAGS = [TagLib.File]::Create("$P_MP3")
$TAGS_OBJECT = @{Filename = $TAGS.Name;
Bitrate = $TAGS.Properties.AudioBitRate;
Artist = $TAGS.tag.FirstArtist;
Title = $TAGS.tag.Title;
Genre = $TAGS.tag.FirstGenre;
LP = $TAGS.tag.Album}
# Output as an object
New-Object PSObject -Property $TAGS_OBJECT
}
# --------------------------
# Main body
# --------------------------
# Store the location of the taglib dll
$TAGLIB="C:\Users\Matt\Downloads\taglib-sharp-2.1.0.0-windows\taglib-sharp-2.1.0.0-windows\Libraries\tag\lib-sharp.dll"
# Load the DLL
[System.Reflection.Assembly]::LoadFile($Taglib)
# Get a list of all the MP3s under the specified folder
# - exclude anything that's not an mp3
# - Fullname contains the full path and filename
$MP3_LIST = gci -recurse Filesystem::$DIR_OR_MP3 |
where {$_.Extension -eq '.mp3'} |
select FullName
# Walk through the list, and output the tags
foreach ($MP3 in $MP3_LIST)
{
get-mp3info $MP3.Fullname
}
The heavily borrows from:
SQLServer Maintenance Cleanup Task not working
I set up a Sqlserver Maintenance Cleanup Task, but couldn’t get it to delete the appropriate backup files.
The log looked like this:
Maintenance Cleanup Task ()
Maintenance Cleanup on Local server connection
Cleanup Database Backup files
Age: Older than 5 Weeks
Task start: 2011-11-09T11:45:01.
Task end: 2011-11-09T11:45:01.
Success
Command:EXECUTE master.dbo.xp_delete_file 0,N''F:mssql_backup'',N''.bak'',N''2011-10-05T11:45:01'',1
GO
…which looks reasonable.
It was showing ‘Success’
My mistake was that I had entered .bak rather than just bak as the ‘File extension’. The ‘.’ is not needed. Presumably it was looking for files called ‘whatever..bak’
Sqlserver Management Studio
I spent a couple of lunchtimes going through Sqlserver Management Studio’s ‘Object Explorer’ panel, typing up all the different elements. This might seem like an odd thing to do, but I thought it might be useful for the following reasons:
- as a reference. A searchable list of where everything is
- as the beginnings of a checklist. Making a system wide change it might be handy to scan through this list and consider whether there’s an impact on each element
- to get me blogging again :)
Databases
System Databases
Database Snapshots
User Databases
Database Diagrams
Tables
Views
Synonyms
Programmability
Stored Procedures
Functions
Triggers
Assemblies
Types
Rules
Defaults
Plan Guides
Service Broker
Message Types
Contracts
Queues
Services
Routes
Remote ServiceBindings
Broker Priorities
Storage
Full Text Catalogs
Partition Schenes
Patition Functions
Full Text Stoplists
Security
Users
Roles
Schemas
Asymmetric Keys
Certificates
Symmetric Keys
Database Audit Specifications
Security
Logins
Server Roles
Credentials
Cryptographic Providers
Audits
Server Audit Specifications
Server Objects
Backup Devices
Endpoints
System Endpoints
Database Mirroring
Service Broker
SOAP
TSQL
Dedicated Admin Connection
TSQL Default TCP
TSQL Default VIA
TSQL Local Machine
TSQL Named Pipes
Database Mirroring
Service Broker
SOAP
TSQL
Linked Servers
Providers
Triggers
Replication
Local publications
Local subscriptions
Management
Data-tier Applications
Policy Management
Policies
System Policies
Conditions
System Conditions
Facets
Data Collection
Resource Governor
Resource Pools
System Resource Pools
Maintenance Plans
SQL Server Logs
Database Mail
Distributed Trnasaction Co-ordinator
Legacy
Database Maintenance Plans
Data Transformation Services
SQL Mail
SQL Server Agent
Jobs
Alerts
Operators
Proxies
Error Logs
Nid(dbnewid) hangs
I had to run nid (also known as dbnewid) on a database as part of a test refresh at the weekend. This changes the dbid of the database.
Out of sheer laziness I ran it from with sqlplus by using the ‘!’ host command feature.
Nid, quite understandablly doesn’t really like this - it hangs.
I ctrl-c’d it, exited to the OS and re-ran and it worked fine.
The 10g doc for nid is here: http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dbnewid.htm
Mucking about with analytic functions
I’ve never really used the analytic functions in anger, so consequently I don’t really have the skills at my fingertips. By way of re-learning them (using Expert One-on-One Oracle | Thomas Kyte | Apress) I’ve been playing about with a list of English Premiership scorers.
The table is:
SQL> desc goals
Name Null? Type
----------------------------------------- -------- ------------
DIVISION NOT NULL VARCHAR2(20)
END_DATE NOT NULL DATE
PLAYER NOT NULL VARCHAR2(40)
TEAM VARCHAR2(20)
GOALS NUMBER
The third highest scorer for each team, should you want to know that bit of information, is given by:
select *
from (select team, player, goals,
row_number() over (partition by team order by goals desc) ranking
from goals)
where ranking = 3
Output is:
TEAM PLAYER GOALS RANKING
---------------- --------------------- ----- -------
Arsenal Robin van Persie 7 3
Aston Villa Ashley Young 5 3
Birmingham Sebastian Larsson 4 3
Blackburn Morten Gamst Pedersen 3 3
Bolton Kevin Davies 5 3
Burnley David Nugent 6 3
Chelsea Florent Malouda 11 3
Everton Mikel Arteta 5 3
Fulham Damien Duff 6 3
Hull City Deiberson Geovanni 3 3
Liverpool Steven Gerrard 7 3
Man Utd Antonio Valencia 5 3
Manchester City Craig Bellamy 9 3
Portsmouth Nadir Belhadj 3 3
Stoke City Ricardo Fuller 3 3
Sunderland Fraizer Campbell 4 3
Tottenham Niko Kranjcar 6 3
West Ham Utd Guillermo Franco 4 3
Wigan Athletic Paul Scharner 4 3
Wolves Matthew Jarvis 3 3
To further develop this query to return a pivot table, you use a decode on the artificial ‘ranking’ field, as follows:
select team,
max(decode(ranking, 1, player, null)) golden_boot,
max(decode(ranking, 2, player, null)) silver_boot,
max(decode(ranking, 3, player, null)) bronze_boot
from
(select team, player, goals, row_number()
over (partition by team order by goals desc) ranking
from goals)
where ranking <= 3 group by team
This returns:
SQL> /
TEAM GOLDEN_BOOT SILVER_BOOT BRONZE_BOOT
---------------- ------------------- ------------------- -------------------
Arsenal Francesc Fabregas Andrey Arshavin Robin van Persie
Aston Villa Gabriel Agbonlahor John Carew Ashley Young
Birmingham Cameron Jerome Lee Bowyer Sebastian Larsson
Blackburn David Dunn Jason Roberts Morten Gamst Peders
Bolton Matthew Taylor Ivan Klasnic Kevin Davies
Burnley Steven Fletcher Graham Alexander David Nugent
Chelsea Didier Drogba Frank Lampard Florent Malouda
Everton Louis Saha Tim Cahill Mikel Arteta
Fulham Bobby Zamora Clinton Dempsey Damien Duff
Hull City Stephen Hunt Jimmy Bullard Deiberson Geovanni
Liverpool Fernando Torres Dirk Kuyt Steven Gerrard
Man Utd Wayne Rooney Dimitar Berbatov Antonio Valencia
Manchester City Carlos Tevez Emmanuel Adebayor Craig Bellamy
Portsmouth Aruna Dindane Frederic Piquionne Nadir Belhadj
Stoke City Matthew Etherington Tuncay Sanli Ricardo Fuller
Sunderland Darren Bent Kenwyne Jones Fraizer Campbell
Tottenham Jermain Defoe Peter Crouch Niko Kranjcar
West Ham Utd Carlton Cole Alessandro Diamanti Guillermo Franco
Wigan Athletic Hugo Rodallega Charles N'Zogbia Paul Scharner
Wolves Kevin Doyle Jody Craddock Matthew Jarvis
20 rows selected.