Skip to content

Instantly share code, notes, and snippets.

View fabriziomello's full-sized avatar
💭
Idle in transaction

Fabrízio de Royes Mello fabriziomello

💭
Idle in transaction
View GitHub Profile
@fabriziomello
fabriziomello / array_remove.sql
Last active February 24, 2016 22:18
Hacking PostgreSQL: exemplo array_remove(anyarray, anyarray) em PL/SQL
CREATE OR REPLACE FUNCTION array_remove (anyarray, anyarray) RETURNS anyarray
AS $$
SELECT array(
SELECT e
FROM unnest($1) AS s(e)
WHERE NOT e = ANY($2)
);
$$
LANGUAGE sql;
@fabriziomello
fabriziomello / gist:c3cfcee97e9c2945aa5e
Created January 8, 2016 02:15
ALTER TABLE ... SET LOGGED, SET TABLESPACE ...
fabrizio=# \db+
List of tablespaces
Name | Owner | Location | Access privileges | Options | Size | Description
------------+----------+----------+-------------------+---------+--------+-------------
pg_default | fabrizio | | | | 27 MB |
pg_global | fabrizio | | | | 496 kB |
(2 rows)
fabrizio=# create tablespace tb1 location '/tmp/tablespace';
CREATE TABLESPACE
#!/bin/bash
#
# O pgbadger no modo incremental gera um indice (arquivos .bin)
# para fazer o parser do log, e não possui um mecanismo interno
# de limpeza de arquivos que não estão mais em uso.
#
# Este script efetua a limpeza dos .bin obsoletos, ou seja,
# aqueles que são de dias anteriores aos correspondentes a
# semana corrente.