Skip to content

Instantly share code, notes, and snippets.

View akorotkov's full-sized avatar

Alexander Korotkov akorotkov

  • Supabase
View GitHub Profile
import numpy as np
import faiss
import seaborn as sns
import pandas as pd
# seed RNG for reproducible result
np.random.seed(1234)
nlist = 30
@akorotkov
akorotkov / init.sql
Last active May 27, 2020 09:39
bloat_bench
CREATE TABLE test (
id integer primary key,
value1 float8 not null,
value2 float8 not null,
value3 float8 not null,
value4 float8 not null,
ts timestamp not null
);
CREATE INDEX test_value1_idx ON test (value1);
@akorotkov
akorotkov / fastpath_lock_collision.sql
Created February 2, 2020 02:43
Fastpath lock collision generator
CREATE OR REPLACE FUNCTION int4_to_bytea(int8) RETURNS bytea AS
$BODY$
SELECT set_byte(' '::bytea, 0, ($1 % 256)::int4) ||
set_byte(' '::bytea, 0, (($1 / 256) % 256)::int4) ||
set_byte(' '::bytea, 0, (($1 / 65536) % 256)::int4) ||
set_byte(' '::bytea, 0, (($1 / 16777216) % 256)::int4);
$BODY$
LANGUAGE sql;
CREATE OR REPLACE FUNCTION int2_to_bytea(int4) RETURNS bytea AS
@akorotkov
akorotkov / pg_graph
Created June 5, 2016 10:21
Draw psql output as iTerm2 v3 inline graph using matplotlib
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Draw psql output as iTerm2 v3 inline graph using matplotlib
# Author: Alexander Korotkov <a.korotkov@postgrespro.ru>
import sys
import re
import warnings
import matplotlib
matplotlib.use("Agg")
diff --git a/pg_stat_kcache.c b/pg_stat_kcache.c
index 63fb4ec..0328209 100644
--- a/pg_stat_kcache.c
+++ b/pg_stat_kcache.c
@@ -152,7 +152,7 @@ _PG_init(void)
* Define (or redefine) custom GUC variables.
*/
RequestAddinShmemSpace(pgsk_memsize());
- RequestAddinLWLocks(1);
+ RequestNamedLWLockTranche("pg_stat_kcache", 1);
@akorotkov
akorotkov / create_partman.sql
Created March 17, 2016 21:02
Partitioning benchmark
CREATE TABLE journal (
id SERIAL PRIMARY KEY,
dt TIMESTAMP NOT NULL,
level INTEGER,
msg TEXT
);
CREATE INDEX journal_dt_idx ON journal (dt);
SELECT create_parent('public.journal', 'dt', 'time', 'daily', NULL, 290, NULL, '2016-01-01');
INSERT INTO journal (dt, level, msg)
SELECT g, random()*6, md5(g::text)