Skip to content

Instantly share code, notes, and snippets.

View shamil614's full-sized avatar

scott hamilton shamil614

View GitHub Profile
@portnov
portnov / query.sql
Created May 27, 2024 12:51
postgres_exporter stat_statements query
explain (analyze, buffers)
SELECT
pg_get_userbyid(userid) as user,
pg_database.datname,
pg_stat_statements.queryid,
pg_stat_statements.calls as calls_total,
pg_stat_statements.total_exec_time / 1000.0 as seconds_total,
pg_stat_statements.rows as rows_total,
pg_stat_statements.blk_read_time / 1000.0 as block_read_seconds_total,
pg_stat_statements.blk_write_time / 1000.0 as block_write_seconds_total
@Weiyuan-Lane
Weiyuan-Lane / mean_query_check.sql
Created May 16, 2021 13:00
pg_stat_statement mean query
SELECT
pg_stat_statements.query as query,
round(pg_stat_statements.total_exec_time::numeric, 2) AS total_time,
pg_stat_statements.calls,
round(pg_stat_statements.mean_exec_time::numeric, 2) AS mean,
round((100 * pg_stat_statements.total_exec_time /
sum(pg_stat_statements.total_exec_time::numeric) OVER ())::numeric, 2) AS percentage_cpu,
round((100 * pg_stat_statements.calls /
sum(pg_stat_statements.calls::numeric) OVER ())::numeric, 2) AS percentage_calls,
pg_user.usename as username,
@tahoemph
tahoemph / postres_system.sql
Created December 21, 2020 15:25
Collection of useful postgres queries both found and made
-- table + index sizes
SELECT
table_name,
pg_size_pretty(table_size) AS table_size,
pg_size_pretty(indexes_size) AS indexes_size,
pg_size_pretty(total_size) AS total_size
FROM (
SELECT
table_name,
pg_table_size(table_name) AS table_size,
@jweyrich
jweyrich / pgsql_performance.sql
Created July 8, 2020 14:04
PostgreSQL performance troubleshooting
psql -h <host> -U <user> -W -d postgres
SELECT * from pg_stat_activity;
SELECT * from pg_stat_database;
# Queries running during >5 minutes
SELECT
pid,
datname,
query,
@aanari
aanari / install_pg11_al2.sh
Last active May 9, 2023 14:00
Install Postgres 11 on Amazon Linux 2
sudo yum update
sudo amazon-linux-extras enable postgresql11
sudo yum install postgresql postgresql-devel
@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active November 12, 2024 21:47
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@sukima
sukima / Makefile
Last active October 2, 2024 13:23
Makefile for compiling PlantUML diagrams
# Makefile for PlantUML
# Author: Devin Weaver (@sukima) <[email protected]>
# GistID: 52eacde54bf7861b19ee66a07b864583
#
# This handles SVGs PNGs and ASCII outputs.
# It handles included files with the .iuml extension: !include foo.iuml
# All diagrams have the .uml extension and reside in the diagrams directory
# All output is saved to the output directory
#
# make svg - (default) build all diagrams as SVGs
@brianshumate
brianshumate / docker-macos-terraform.md
Last active November 14, 2024 11:35
The Simplest Terraform with Docker on macOS

If you'd like to experiment with Terraform on macOS locally, a great provider for doing so is the Docker provider. You can get set up in a few simple steps, like so:

1. Install Docker

Install Docker for Mac if you have not already.