Skip to content

Instantly share code, notes, and snippets.

View Winslett's full-sized avatar

Christopher Winslett Winslett

View GitHub Profile
@Winslett
Winslett / data.sql
Last active February 5, 2024 18:54
Data for Row Level Security
--
-- PostgreSQL database dump
--
--
-- Name: accounts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.accounts (
id BIGSERIAL PRIMARY KEY,
@Winslett
Winslett / _.txt
Last active January 4, 2024 21:07
Paths with a Difference
Path: /
@Winslett
Winslett / raw.sql
Last active August 9, 2023 00:15
data for lateral join
-- Create accounts table with ID, account_name, and a JSONB column for storing addresses
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
addresses JSONB
);
-- Create purchases table with account_id, created_at, and product_name columns
CREATE TABLE purchases (
purchase_id SERIAL PRIMARY KEY,
@Winslett
Winslett / data.sql
Last active July 20, 2023 21:03
SQL for PostgresFDW example
CREATE TABLE public.accounts (
id SERIAL PRIMARY KEY,
name character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
CREATE TABLE public.carbon_removal_projects (
id SERIAL PRIMARY KEY,
CREATE TABLE public.accounts (
id bigint NOT NULL,
name character varying,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
CREATE SEQUENCE public.accounts_id_seq
START WITH 1
@Winslett
Winslett / employees_dump.sql
Last active December 7, 2022 19:24
JSONB Example
--
CREATE TABLE public.employees (
id bigint NOT NULL,
first_name character varying,
last_name character varying,
start_date timestamp(6) without time zone,
job_title character varying,
salary integer,
manager_id character varying,
departments jsonb,
@Winslett
Winslett / 1-terminal-slow-queries.png
Last active May 16, 2022 14:24
Use SQL comments as a Stacktrace for database performance
1-terminal-slow-queries.png
@Winslett
Winslett / 1-programmer-bookshelf.png
Last active May 5, 2022 20:59
Demystifying Database Performance for Developers
1-programmer-bookshelf.png
@Winslett
Winslett / Blog.md
Last active June 7, 2022 15:42
Database Performance is all about costs

Stick with Simplicity to Cross the Database Financial Gap

TL;DR: keep your data-layer simple, you’ll need the agility it offers when budgets get stretched.

Over the past 12 years of helping people run databases for their businesses, I have discovered that there are only 2 financial phases in the lifecycle of a database:

  • Phase 1: Absolute costs are low, thus marginal costs do not matter.
  • Phase 2: Absolute costs are high, thus marginal costs are all that matter.

I'm calling this difference between Phase 1 and Phase 2 the "database financial gap."

SELECT
total_exec_time,
mean_exec_time AS avg_ms,
calls,
query
FROM pg_stat_statements
ORDER BY mean_exec_time DESC
LIMIT 10;