Skip to content

Instantly share code, notes, and snippets.

View sebastianwebber's full-sized avatar
🏠
Working from home

Sebastian Webber sebastianwebber

🏠
Working from home
View GitHub Profile
@sebastianwebber
sebastianwebber / top-indexes-pgsql-lld.sql
Created November 10, 2016 13:10
Lista os indices para uso do LLD no zabbix
-- Based on https://wiki.postgresql.org/wiki/Disk_Usage
---- To use on zabbix for LLD
---- Sorted to the greatest size to the lowest size
WITH index_stats AS (
SELECT
pg_class.oid,
nspname AS table_schema,
relname AS index_NAME,
pg_total_relation_size(pg_class.oid) AS total_bytes
@sebastianwebber
sebastianwebber / top-tables-pgsql-lld.sql
Last active November 10, 2016 13:24
Lista as tabelas para ser usada no lld do zabbix
-- Based on https://wiki.postgresql.org/wiki/Disk_Usage
---- To use on zabbix for LLD
---- Sorted to the greatest size to the lowest size
WITH table_stats AS (
SELECT
pg_class.oid,
nspname AS table_schema,
relname AS TABLE_NAME,
pg_class.reltuples AS row_estimate,
@sebastianwebber
sebastianwebber / pgagent-next-jobs.sql
Created November 4, 2016 21:26
List PGAgent next jobs
SELECT
pga_job.jobname as job_name,
pga_jobstep.jstdbname as database_name,
pgagent.pga_next_schedule(
pga_schedule.jscid,
pga_schedule.jscstart,
pga_schedule.jscend,
pga_schedule.jscminutes,
pga_schedule.jschours,
pga_schedule.jscweekdays,
-- Found on: http://techxploration.blogspot.com.br/2012/06/script-to-get-oracle-database-size.html
SET SERVEROUTPUT ON
Declare
ddf Number:= 0;
dtf Number:= 0;
log_bytes Number:= 0;
total Number:= 0;
@sebastianwebber
sebastianwebber / apply-tuning.sh
Created November 2, 2016 21:41
a script to apply pgconfig using the api (useful for a ansible role/task)
#!/bin/bash
PGCONFIG_URL="https://api.pgconfig.org/v1/tuning/get-config"
DEFAULT_FORMAT="alter_system"
ENVIRONMENT="{{ postgresql_default_profile }}"
PG_VERSION="{{ postgresql_version }}"
TOTAL_RAM=$(({{ ansible_memtotal_mb }} /1024))
ADMIN_USER="postgres"
USE_RESTORE_TUNING="{{ apply_restore_tuning | default('NO') }}"
@sebastianwebber
sebastianwebber / fn_busca_valor_bloco.sql
Last active October 19, 2016 12:31
exemplo de função `SQL`
-- based on http://pastebin.com/igga50QK
CREATE OR REPLACE FUNCTION fn_busca_valor_bloco_sql(p_blccodigo INTEGER, p_itemcodigo INTEGER, p_cadastro BIGINT)
RETURNS TEXT AS
$BODY$
SELECT
CASE WHEN lsicodigo IS NULL THEN lsidescricao ELSE itmconteudo END
FROM tbblocoitem
LEFT JOIN tblistaitem using(blccodigo ,itemcodigo ,lsicodigo)
WHERE tbblocoitem.blccodigo = p_blccodigo
#!/bin/bash
## check_dump.sh
### Verifica a integridade do backup, convertendo ele do tipo diretório para SQL Plain
### Procura por arquivos .tar no diretório `DUMP_DIR`, extrai eles no `TEMP_DIR` e efetua o teste
## Baseado na idéia do @fabriziomello
#########
function show_usage() {
@sebastianwebber
sebastianwebber / guia.md
Last active May 16, 2017 18:23
Guia pra facilitar da vida de quem lê as suas consultas

Guia pra facilitar da vida de quem lê as suas consultas

Consulta original

SELECT e.ID_USUARIO, u.NOME_COMPLETO USUARIO, e.ID_USUARIO_SOLICITANTE , us.NOME_COMPLETO USUARIO_SOLICITANTE, e.DATA_EMPRESTIMO DATA_EMPRESTIMO, e.DATA_DEVOLUCAO DATA_DEVOLUCAO,
         e.STATUS STATUS, l.TITULO
         FROM emprestimo e
         INNER JOIN usuario u ON e.ID_USUARIO = u.ID
         INNER JOIN usuario us ON e.ID_USUARIO_SOLICITANTE = us.ID
- set_fact:
events_session: |+
events {
worker_connections {{ total_fpm_pools * max_phpfpm_server_per_pool }};
use epoll;
multi_accept on;
}
@sebastianwebber
sebastianwebber / wal_prefetch.sh
Last active December 30, 2016 15:21
wal_prefetch.sh: Script pra agilizar a cópia do `restore_command`, trazendo vários arquivos de cada vez
#!/bin/bash
# Ideia original do @matheusoliveira
# $1 é %f, $2 é %p
## IMPORTANTE: Lembrar de configurar o `archive_cleanup_command` no `recovery.conf` pra
## chamar o pg_archivecleanup e apontar pro ${CACHE_DIR}
## exemplo:
### restore_command = '/opt/resources/wal_prefetch.sh %f %p'
### archive_cleanup_command = '/usr/pgsql-9.3/bin/pg_archivecleanup /slave/wal-cache %r'