Skip to content

Instantly share code, notes, and snippets.

View matthew-n's full-sized avatar

Matt N. matthew-n

  • Houston, Tx
View GitHub Profile
#!/bin/bash
#set -x
#set -e
page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
phys_memory_kb=$[ $phys_pages * $page_size / 1024 ]
kb_pct=$[ 1024 / 100]
@matthew-n
matthew-n / pg_changefee.md
Created May 2, 2018 16:20
idea for implementing changefeeds in postgresql

Overview

table -> after trigger (U/I/D) -> eval quals -> write out (old_ctid, new_ctid, table_name, timestamp) to stg client process collects from stg table only one table_name selecting old_ctid and new_ctid for each

@matthew-n
matthew-n / db_disk_test.sh
Created May 2, 2018 16:23
disk benchmark for database with fio
#!/bin/bash
set -x
set -e
sec_list="seq-read seq-write random-read random-write active-db"
rw_rate_list="75 80 85 90"
io_thread_list="1 4 8 16 24"
for class in $sec_list; do
for ratio in $rw_rate_list; do
@matthew-n
matthew-n / blkdev_max.fio
Last active December 28, 2020 21:59
Linux syth postgres io workload
[global]
ioengine=libaio
direct=1
invalidate=1
verify=0
ramp_time=2s
randrepeat=0
time_based
runtime=5m
filesize=2G
@matthew-n
matthew-n / Makefile
Created July 21, 2019 21:20 — forked from mpneuried/Makefile
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)
DROP TABLE IF EXISTS pgbench_generic_log;
CREATE TABLE pgbench_generic_log (
mtime timestamptz not null default now(),
action char not null check (action in ('I', 'U', 'D')),
username text not null,
table_name text not null,
row_data jsonb not null
);
CREATE INDEX ON pgbench_generic_log USING brin (mtime);
@matthew-n
matthew-n / mssql_hosts_ipaddr.sql
Last active March 23, 2024 19:57
fun with IP Addresses in MSSQL
CREATE FUNCTION dbo.udf_ipv4_format (@addr binary(16) )
RETURNS varchar(20) with SCHEMABINDING AS
BEGIN
return IIF(SUBSTRING(@addr,0,8)=0,
CONCAT(
CAST(SUBSTRING(@addr,13,1) AS INT),'.',
CAST(SUBSTRING(@addr,14,1) AS INT),'.',
CAST(SUBSTRING(@addr,15,1) AS INT),'.',
CAST(SUBSTRING(@addr,16,1) AS INT)
),NULL)
@matthew-n
matthew-n / better_sp_helpdb.sql
Last active January 21, 2021 15:22
dmv based alternative to sp_helpdb
/* original code from: http://davebland.com/a-faster-alternative-to-sp_helpdb */
DECLARE @t1 DATETIME;
DECLARE @t2 DATETIME;
SET @t1 = GETDATE();
CREATE TABLE #DBSize
(
DatabaseName VARCHAR(200),
CREATE TABLE ##sample_set (
sample_set_id INT NOT NULL IDENTITY(1,1),
[database_id] INT NOT NULL,
[database_name] NVARCHAR(128) NOT NULL,
[table_id] INT NOT NULL,
[table_name] NVARCHAR(128) NOT NULL,
[column_id] INT NOT NULL,
[column_name] NVARCHAR(128) NOT NULL,
[stats_id] INT NULL,
[status_name] NVARCHAR(128) NULL,
@matthew-n
matthew-n / readme.md
Last active January 20, 2021 18:57
ozar_toolkit_setup

Setting up for minimal user (non-dba) permissions

One-time steps

USE master;
GO

CREATE CERTIFICATE diagnostics_cert
 ENCRYPTION BY PASSWORD = '5OClockSomewhere'