Skip to content

Instantly share code, notes, and snippets.

View mvikharev's full-sized avatar

Max Vikharev mvikharev

  • Zelenograd, Moscow, Russia
View GitHub Profile
1. pip install -r reqs.pip
2. server.py
3. open client.html in browser
4. redis-cli publish push '123456'
5. check browser console
@mvikharev
mvikharev / A Postgres Receipts
Last active January 3, 2017 16:21
Postgresql
A Postgres Receipts
SELECT relation,
total_size,
relation_size,
indexes_size,
count
FROM
(SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid) + COALESCE(partitions_info.total_size, 0)) AS "total_size",
pg_size_pretty(pg_relation_size(C.oid) + COALESCE(partitions_info.relation_size, 0)) AS "relation_size",
pg_size_pretty(pg_total_relation_size(C.oid) + COALESCE(partitions_info.total_size, 0) - pg_relation_size(C.oid) - COALESCE(partitions_info.relation_size, 0)) AS "indexes_size",
@mvikharev
mvikharev / bloat_view.sql
Last active January 3, 2017 16:21
pg_bloat.sql
CREATE OR REPLACE VIEW bloat AS
SELECT
schemaname, tablename, reltuples::bigint, relpages::bigint, otta,
ROUND(CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages/otta::numeric END,1) AS tbloat,
relpages::bigint - otta AS wastedpages,
bs*(sml.relpages-otta)::bigint AS wastedbytes,
pg_size_pretty((bs*(relpages-otta))::bigint) AS wastedsize,
iname, ituples::bigint, ipages::bigint, iotta,
ROUND(CASE WHEN iotta=0 OR ipages=0 THEN 0.0 ELSE ipages/iotta::numeric END,1) AS ibloat,
CASE WHEN ipages < iotta THEN 0 ELSE ipages::bigint - iotta END AS wastedipages,
@mvikharev
mvikharev / server_side_datatable.py
Created June 7, 2017 09:46 — forked from hammer/server_side_datatable.py
Implementation of a server-side DataTable (cf. http://datatables.net/release-datatables/examples/data_sources/server_side.html) using Flask, Flask-RESTful, and Psycopg. You should only have to edit source_database, source_table, and source_columns to make it work. Of course you'll probably want to edit the resource name and URL as well.
from string import Template
from distutils.util import strtobool
from flask import Flask, request
from flask.ext.restful import Api, Resource
import psycopg2
# Flask-RESTful Api object
app = Flask(__name__)
@mvikharev
mvikharev / README
Last active July 11, 2020 20:17
Postgresql 12 - out of mem
1. createdb test
2. ./schema.sh > schema.sql
3. ./data.sh > data.sql
4. psql test < schema.sql
5. psql test < data.sql
6. Reproduce the problem
SELECT id into agg
FROM "content"
WHERE "content"."id" IN