Skip to content

Instantly share code, notes, and snippets.

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

Sebastian Webber sebawebber

🏠
Working from home
View GitHub Profile
@sebawebber
sebawebber / ssh-forward-clipboard.md
Created February 7, 2017 18:54 — forked from dergachev/ssh-forward-clipboard.md
Forward your clipboard via SSH reverse tunnels

Exposing your clipboard over SSH

I frequently administer remote servers over SSH, and need to copy data to my clipboard. If the text I want to copy all fits on one screen, then I simply select it with my mouse and press CMD-C, which asks relies on m y terminal emulator (xterm2) to throw it to the clipboard.

This isn't practical for larger texts, like when I want to copy the whole contents of a file.

If I had been editing large-file.txt locally, I could easily copy its contents by using the pbcopy command:

@sebawebber
sebawebber / base_backup.sh
Last active December 23, 2016 16:57
pg_basebackup for slave
## postgres=# create user replicator replication password 'teste';
pg_basebackup -U replicator -h 192.168.100.100 -D /var/lib/pgsql/9.3/data --write-recovery-conf --xlog-method=stream --progress --verbose --checkpoint=fast
@sebawebber
sebawebber / .vimrc
Created November 24, 2016 12:57
vimrc for customers
:set bg=dark
:set nu
:set ic
:set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
@sebawebber
sebawebber / 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
@sebawebber
sebawebber / 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,
@sebawebber
sebawebber / 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;
@sebawebber
sebawebber / 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') }}"
@sebawebber
sebawebber / 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() {