Skip to content

Instantly share code, notes, and snippets.

View Azure4Arjun's full-sized avatar
🏠
Working from home

Arjun Azure4Arjun

🏠
Working from home
View GitHub Profile
@ronascentes
ronascentes / killAllConnections.sql
Created January 11, 2020 21:42
Kill all the current connections of a SQL instance
DECLARE @session_id INT, @sql NVARCHAR (4000);
DECLARE database_curs CURSOR FAST_FORWARD FOR
SELECT c.session_id
FROM sys.dm_exec_connections AS c
JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id
WHERE c.session_id <> @@SPID AND s.is_user_process = 1;
OPEN database_curs;
FETCH NEXT FROM database_curs INTO @session_id;
WHILE (@@fetch_status <> -1)
BEGIN
@brazilnut2000
brazilnut2000 / SQL: convert extended events file into table.sql
Created May 26, 2017 19:09
Convert an Extended Events .xel file into a queryable table in SQL Server
-- convert all .xel files in a given folder to a single-column table
-- (alternatively specify an individual file explicitly)
select event_data = convert(xml, event_data)
into #eeTable
from sys.fn_xe_file_target_read_file(N'd:\killme\extended events\*.xel', null, null, null);
-- select from the table
select * from #eeTable
-- and click on a hyperlink value to see the structure of the xml
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'