Skip to content

Instantly share code, notes, and snippets.

View genslein's full-sized avatar

Gabriel Enslein genslein

View GitHub Profile
@genslein
genslein / psql_table_and_index_cache_hits.sql
Created February 10, 2018 01:16
Postgres Table and Index cache hits and percentages
with
all_tables as
(
SELECT *
FROM (
SELECT 'all'::text as table_name,
sum( (coalesce(heap_blks_read,0) + coalesce(idx_blks_read,0) + coalesce(toast_blks_read,0) + coalesce(tidx_blks_read,0)) ) as from_disk,
sum( (coalesce(heap_blks_hit,0) + coalesce(idx_blks_hit,0) + coalesce(toast_blks_hit,0) + coalesce(tidx_blks_hit,0)) ) as from_cache
FROM pg_statio_all_tables --> change to pg_statio_USER_tables if you want to check only user tables (excluding postgres's own tables)
) a
@genslein
genslein / vacuum_stats_all_tables.sql
Last active February 1, 2022 17:42
Get more robust autovacuum stas
WITH table_opts AS (
SELECT
pg_class.oid, relname, nspname, array_to_string(reloptions, '') AS relopts
FROM
pg_class INNER JOIN pg_namespace ns ON relnamespace = ns.oid
), vacuum_settings AS (
SELECT
oid, relname, nspname,
CASE
WHEN relopts LIKE '%autovacuum_vacuum_threshold%'
@genslein
genslein / postgis_brin.sql
Last active January 3, 2019 20:54
Postgis 2.3.0 to 2.4.x upgrade operator bugfix
-- Remediation from dictated changeset
-- https://github.com/postgis/postgis/commit/f49d42880f2aad1e23daaf5930fb66ec359a11a2#diff-821927f099d6d61ff6b9fc149d7bc071R289
-- Availability: 2.3.0
CREATE OR REPLACE FUNCTION contains_2d(box2df, geometry)
RETURNS boolean
AS '/usr/lib/postgresql/9.6/lib/postgis-2.4.so','gserialized_contains_box2df_geom_2d'
LANGUAGE 'c' IMMUTABLE STRICT;
-- Availability: 2.3.0
CREATE OR REPLACE FUNCTION is_contained_2d(box2df, geometry)
@genslein
genslein / PgCon_2019_Learnings.md
Created June 6, 2019 15:32
PgCon 2019 learnings

PgCon 2019 Learnings

Pluggable storage in PG 12

  • Table Access Method (AM) definable
  • Opens doors for Columnar storage, UNDO capabilities
  • Multiple Tuple types: minimal, virtual and heap
  • Aims to solve the chronic Bloat problem modern workloads face regularly
  • Not Supported: WAL, non-heap catalogs

nbtree Architecture for PG 12

@genslein
genslein / pgextwlist_docker commands
Last active November 7, 2019 20:21
docker testing pgextwlist oid collision issue
# Start stock xenial
docker run -it ubuntu:xenial bash
# Prepare image
apt-get update -y \
&& apt-get install -y vim software-properties-common wget apt-transport-https
add-apt-repository -y "deb https://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
@genslein
genslein / README.md
Last active June 4, 2020 14:44 — forked from a-barbieri/README.md
NextJS sitemap generator with dynamic URL

NextJS sitemap generator

Install

The current setup has been tested on Next Js 7.0.0.

You need to install Axios.

$ npm install axios
@genslein
genslein / configure_and_query_s3.py
Created August 24, 2020 15:16
s3 bucket query and stats
import boto3
resource = boto3.resource(
's3',
aws_access_key_id = 'my_access_key',
aws_secret_access_key = 'my_secret_key',
endpoint_url = 'http://s3.target.endpoint.minio-compatible.com',
)
bucket = resource.Bucket('my_test_bucket')
@genslein
genslein / permute.c
Created September 10, 2020 00:36
permute c function for ruby, separated out for history and learning
/*
* Compute permutations of +r+ elements of the set <code>[0..n-1]</code>.
*
* When we have a complete permutation of array indices, copy the values
* at those indices into a new array and yield that array.
*
* n: the size of the set
* r: the number of elements in each permutation
* p: the array (of size r) that we're filling in
* used: an array of booleans: whether a given index is already used

GitHub Infrastructure Engineer Questionnaire

Thanks again for applying to the Infrastructure Engineer job at GitHub! The purpose of this gist is to get a better sense of your technical skills and overall communication style. Take as much time as you need to answer these questions.

Section 1

Engineers at GitHub communicate primarily in written form, via GitHub Issues and Pull Requests. We expect our engineers to communicate clearly and effectively; they should be able to concisely express both their ideas as well as complex technological concepts.

Please answer the following questions in as much detail as you feel comfortable with. The questions are purposefully open-ended, and we hope you take the opportunity to show us your familiarity with various technologies, tools, and techniques. Limit each answer to half a page if possible; walls of text are not required, and you'll have a chance to discuss your answers in further detail during a phone interview if we move forward in the process. Finally, feel

@genslein
genslein / main.go
Created January 5, 2022 16:46 — forked from denisbrodbeck/main.go
How to generate secure random strings in golang with crypto/rand.
// License: MIT
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
// GenerateRandomASCIIString returns a securely generated random ASCII string.