Skip to content

Instantly share code, notes, and snippets.

View jberkus's full-sized avatar
💭
At work on workdays at least

Josh Berkus jberkus

💭
At work on workdays at least
View GitHub Profile
root@dev-postgres:/var/lib/postgresql/pg_repack# make
make[1]: Entering directory `/var/lib/postgresql/pg_repack/bin'
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -I/usr/include/mit-krb5 -fPIC -pie -DLINUX_OOM_SCORE_ADJ=0 -fno-omit-frame-pointer -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g pg_repack.o pgut/pgut.o pgut/pgut-fe.o -L/usr/lib/x86_64-linux-gnu -lpq -L/usr/lib/x86_64-linux-gnu -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -L/usr/lib/mit-krb5 -L/usr/lib/x86_64-linux-gnu/mit-krb5 -L/usr/lib/x86_64-linux-gnu -Wl,--as-needed -lpgport -lpgcommon -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -ledit -lcrypt -ldl -lm -o pg_repack
/usr/bin/ld: cannot find -ledit
collect2: ld returned 1 exit status
make[1]: *** [pg_repack] Error 1
@jberkus
jberkus / cspace.txt
Created October 16, 2015 02:18 — forked from atman9/cspace.txt
Explain for query taking over 25mins to complete.
SELECT
h2.name AS "objectcsid",
cc.objectnumber,
h1.name AS "mediacsid",
mc.description,
bc.name,
mc.creator creatorRefname,
REGEXP_REPLACE(mc.creator, '^.*\)''(.*)''$', '\1') AS "creator",
mc.blobcsid,
mc.copyrightstatement,
# docker compose file for running a 3-node PostgreSQL cluster
# with etcd as the SIS
etcd:
image: quay.io/coreos/etcd
ports:
- "2379"
- "2380"
- "4001"
@jberkus
jberkus / gist:3950d8348e2ddb00070c
Last active January 13, 2018 06:52
New needed indexes query, temp version
WITH
write_adjust AS (
-- change the below to 1.0 if pg_stats goes back to
-- the creation of the database
SELECT 0.0 AS adjustment
),
index_usage AS (
SELECT sut.relid,
current_database() AS database,
sut.schemaname::text as schema_name,
@jberkus
jberkus / gist:43a74b63921aa58f90c8
Last active September 4, 2015 05:10
Simple stupid function to do python-style dict string replacement.
-- function for doing dictionary-style replacement of varaibles
-- in a SQL string. variables are marked in the text with ${var}
-- and replaced using a json dictionary
create or replace function replace_vars ( somestring text,
vars JSON )
returns text
language plpgsql
immutable
as
@jberkus
jberkus / gist:a4457d40a758f7eca1e8
Created August 11, 2015 23:33
fake clickstream data generator
#!/user/bin/env python
import psycopg2
import datetime
import random
import time
import sys
def randuser():
return (int(random.random() * 100) + 1)
@jberkus
jberkus / gist:132a2be7096b1953d72b
Created July 27, 2015 22:39
Sample script to pull a stream of San Francisco tweets and push them into PipelineDB
from TwitterAPI import TwitterAPI
import psycopg2
from psycopg2.extras import Json
CONSUMER_KEY = 'Get'
CONSUMER_SECRET = 'your'
ACCESS_TOKEN_KEY = 'own'
ACCESS_TOKEN_SECRET = 'API key'
api = TwitterAPI(CONSUMER_KEY,
benchcall = "{bdir}/{pgb} -T {ttime} -c {clients} -j {jobs} -s {scale} -r -n {scriptfiles} -p {port} -U {user} -h {host} {dbname} > {results}.results".format(bdir=abench,pgb=pgbench,ttime=numsec,clients=numclients,jobs=numthreads,scale=numrows,scriptfiles=filelist,dbname=db,results=abench,port=dbport,user=dbuser,host=dbhost)
@jberkus
jberkus / gist:81ad58603c2697bdd8fb
Last active August 29, 2015 14:17
SQL circular quartiles function
create type numeric_quartiles_plus as (
min float,
q05 float,
q10 float,
q25 float,
q50 float,
q75 float,
q90 float,
q95 float,
max float,
@jberkus
jberkus / gist:f076ab4e680a3a509313
Created March 28, 2015 18:13
pl/python circular quartiles function
create type numeric_quartiles_plus as (
min float,
q05 float,
q10 float,
q25 float,
q50 float,
q75 float,
q90 float,
q95 float,
max float,