Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Pau Pérez Fabregat sauloperez

I may be slow to respond.
View GitHub Profile
sauloperez / dalyed_job_checks.rb
Created Oct 25, 2017
Snippets to check Delayed Job data
View dalyed_job_checks.rb
# Failed
Delayed::Job.where('failed_at IS NOT NULL')
# Active
Delayed::Job.where('failed_at IS NULL AND locked_by IS NOT NULL')
# Queued
Delayed::Job.where('failed_at IS NULL AND locked_by IS NULL')
# Destroy
sauloperez / gist:c789684fbcdcabbccfca000e27b42293
Created Dec 27, 2018
Silence deprecation warnings in Rails
View gist:c789684fbcdcabbccfca000e27b42293
ActiveSupport::Deprecation.silenced = true
# At the bottom of add /etc/postgresql/9.5/main/postgresql.conf
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
sudo systemctl restart postgresql
sudo su postgres
CREATE extension pg_stat_statements;
sauloperez / bundle_update_output.log
Created Mar 12, 2019
Bundle update output for Spree 2.1
View bundle_update_output.log
Bundler could not find compatible versions for gem "actionpack":
In Gemfile:
rails (~> 4.0.0) was resolved to 4.0.0, which depends on
actionpack (= 4.0.0)
simple_form was resolved to 2.0.2, which depends on
actionpack (~> 3.0)
Bundler could not find compatible versions for gem "activerecord":
In Gemfile:
View Postgres_tips.txt
SELECT datname, usename, query FROM pg_stat_activity; \watch
View sloq_query_log.txt
Like most databases, Postgres has a built-in slow query log feature that automatically logs queries to the main Postgres log file if they take over a certain amount of time and it's really easy to set up.
In your main postgresql.conf file (which is often somewhere like /etc/postgresql/9.6/main/postgresql.conf), either edit or add a line like so:
log_min_duration_statement = 1000
After restarting Postgres or reloading the config with SELECT pg_reload_conf();, this directive causes any queries that take over 1000 milliseconds (one second) to be logged.
(The location of the log file varies but is /var/log/postgresql/postgresql-9.6-main.log on my test setup, for instance.)
To deliberately run a long query for testing purposes:
sauloperez / restart.txt
Created Apr 19, 2019
Detect when postgres needs a restart
View restart.txt
On Wed, Oct 1, 2014 at 2:18 PM, Stuart Bishop <stuart(at)stuartbishop(dot)net>
> It is unnecessary maintaining a list of parameters which require a
> restart, as you can tell by looking at pg_settings.
> The way I do it is by comparing the contents of pg_settings with a
> snapshot I made just after (or just before) the server was last
sauloperez / order_management.sql
Created May 11, 2019
Order cycle management report in a single SQL query
View order_management.sql
select spree_line_items.order_id, spree_products.supplier_id, sum(spree_line_items.price * spree_line_items.quantity) AS amount
from spree_line_items
join spree_variants
on = spree_line_items.variant_id
join spree_products
on = spree_variants.product_id
join enterprises
View .devenv
sauloperez /
Last active Jun 5, 2019
database dump with compression
pg_dump -U ofn_user -h localhost openfoodnetwork -Fc -f /tmp/production_dump.sql
# openfoodnetwork@production18:~/apps/openfoodnetwork/current$ du -h /tmp/production*
# 320M /tmp/production_dump_with_compression.sql
# 1.2G /tmp/production_dump_without_compression.sql