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
WITH btree_index_atts AS (
SELECT nspname, relname, reltuples, relpages, indrelid, relam,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
FROM pg_index
JOIN pg_class ON pg_class.oid=pg_index.indexrelid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN pg_am ON pg_class.relam = pg_am.oid
WHERE pg_am.amname = 'btree'
),
@jberkus
jberkus / gist:9815260
Created March 27, 2014 18:54
Flexible Freeze outline
Specification:
BASIC VERSION
Config File:
Series of time windows for "low traffic" points.
e.g. "Sunday 1am-4am"
Postgres connection info for 1 database
vacuum settings
min_freeze threshold (default 1,000,000)
@jberkus
jberkus / xlog_numeric_location.sql
Last active February 20, 2016 20:30
Determine Most Caught-up Standby
-- For documentation on these functions, please see blog post at:
-- http://www.databasesoup.com/2012/10/determining-furthest-ahead-replica.html
-- determines current xlog location as a monotonically increasing numeric.
CREATE OR REPLACE FUNCTION xlog_location_numeric(vcloc text default NULL)
RETURNS numeric
LANGUAGE plpgsql
as $f$
DECLARE cloc text;
floc text[];
@jberkus
jberkus / gist:3296689
Created August 8, 2012 17:08
Crash jump
breakpad=# select date_trunc('day', date_processed), count(*) from reports where date_processed between '2012-08-01' and '2012-08-08' group by 1 order by 1;
date_trunc | count
------------------------+--------
2012-08-01 00:00:00+00 | 481349
2012-08-02 00:00:00+00 | 483259
2012-08-03 00:00:00+00 | 480551
2012-08-04 00:00:00+00 | 423422
2012-08-05 00:00:00+00 | 429353
2012-08-06 00:00:00+00 | 508709
2012-08-07 00:00:00+00 | 909945