Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@systemist
systemist / README.md
Last active December 1, 2022 23:00
Count how many times sets of columns are used to filter PostgreSQL queries via `pg_stat_statements`

These scripts can be used to figure out how often different sets of column combinations are used to filter queries in PostgreSQL. It's most useful for getting a high-level view in order to design and refactor indexes (e.g. if a certain set of columns is rarely used to filter queries, it's possible using index-merging instead of composite indexes would improve overall performance).

Usage

  • For each server in your database cluster, using credentials that can read pg_stat_statements.queryid (which is usually just superusers), download the contents of pg_stat_statements as CSV. This should be done separately for the primary and the replicas because pg_stat_statements tracks queries locally:
psql --csv -c 'SELECT * FROM pg_stat_statements' $DATABASE_URL > pg_stat_statements/$DATABASE_NAME.csv
class Example
define_method(:call) do
yield if block_given?
end
end
-- http://www.hammerspoon.org/docs/hs.hotkey.html
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
RSpec.describe "Using a table for multiple examples" do
def self.define_data_table(name, table_doc)
fields, *records = *table_doc.lines.map { |l| l.split('|').map(&:strip).reject(&:empty?) }
define_singleton_method(name) { records.map { |r| Hash[fields.map(&:to_sym).zip(r)] } }
end
define_data_table(:users, <<~USERS)
| name | email | twitter |
| Aslak | aslak@cucumber.io | @aslak_hellesoy |
| Julien | julien@cucumber.io | @jbpros |
1.1 Notes
1.1 Assignments
#!/bin/sh
# Check for Homebrew,
# Install if we don't have it
if test ! $(which brew); then
echo "Installing homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
echo "Setting up XCode"
import Ember from 'ember';
export default Ember.Route.extend({
'things-store': Ember.inject.service('things-store'),
model() {
console.log('model', this.get('things-store.things').length);
this.get('things-store').fetch();
console.log('post', this.get('things-store.things').length);
return this.get('things-store');
},

Account

{
  "name": "Account Name",
  "starting_balance": 354745, // Number in pennies
  "starting_balance_date": "2015-03-15",

  "current_balance": 269439 // Number in pennies
  "current_balance_date": "2015-07-03",
import ForecastCollection from './models';
let forecasts = new ForecastCollection();
var Store = _.extend({}, Backbone.Events, {
initialize() {
this.listenTo(forecasts, 'add remove change', () => this.trigger('change'));
},
getForecasts() {