Just to see which tables qualify for autovacuum

Just to see which tables qualify for autovacuum at all, the following query may be used (based on http://www.postgresql.org/docs/current/static/routine-vacuuming.html). Note however, that the query does not look for table specific settings:

 SELECT psut.relname,
     to_char(psut.last_vacuum, 'YYYY-MM-DD HH24:MI') as last_vacuum,
     to_char(psut.last_autovacuum, 'YYYY-MM-DD HH24:MI') as last_autovacuum,
     to_char(pg_class.reltuples, '9G999G999G999') AS n_tup,
     to_char(psut.n_dead_tup, '9G999G999G999') AS dead_tup,
     to_char(CAST(current_setting('autovacuum_vacuum_threshold') AS bigint)
         + (CAST(current_setting('autovacuum_vacuum_scale_factor') AS numeric)
            * pg_class.reltuples), '9G999G999G999') AS av_threshold,
     CASE
         WHEN CAST(current_setting('autovacuum_vacuum_threshold') AS bigint)
             + (CAST(current_setting('autovacuum_vacuum_scale_factor') AS numeric)
                * pg_class.reltuples) < psut.n_dead_tup
         THEN '*'
         ELSE ''
     END AS expect_av
 FROM pg_stat_user_tables psut
     JOIN pg_class on psut.relid = pg_class.oid
 ORDER BY 1;

Como forçar a atualização de cache do DNS do Google

https://developers.google.com/speed/public-dns/cache

Ulalá!

Como instalar o php composer no Mac OSX Sierra

Dica rápida, caso você tenha problema semelhante ao abaixo quando tenta instalar o php composer no Mac OSX Sierra:

error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in composer-setup.php on line 770
PHP Warning: file_get_contents(): Failed to enable crypto in composer-setup.php on line 770

A solução é simples, você precisa baixar e instalar um certificado SSL no seu computador.

Faça o download do arquivo em algum diretório:
wget http://curl.haxx.se/ca/cacert.pem

Depois edite seu php.ini e inclua/descomente esta linha, apontando para o arquivo cacert.pem que você baixou.

openssl.cafile=/anywhere-you-like/cacert.pem

Boa sorte!

Permitir o SELINUX para algum programa em específico

Neste exemplo, vamos liberar as permissões que o nGinx precisa para funcionar.

Primeiramente, vamos listar as linhas negadas pelo selinux.

sudo cat /var/log/audit/audit.log | grep nginx | grep denied

Agora, vamos criar um arquivo .pp para ser carregado pelo SELINUX.

sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx 

sudo semodule -i mynginx.pp

Adicionar certificado TLS no Postfix

Create tls directory, set correct ownership/permissions and create a certificate file:

# mkdir /etc/postfix/tls
# chown root:postfix /etc/postfix/tls
# chmod u=rwx,go= /etc/postfix/tls
# cd /etc/postfix/tls
# openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650

Change /etc/postfix/main.cf accordingly:

# grep _tls /etc/postfix/main.cf
smtpd_tls_CAfile = /etc/postfix/tls/smtpd.pem
smtpd_tls_cert_file = /etc/postfix/tls/smtpd.pem
smtpd_tls_key_file = /etc/postfix/tls/smtpd.pem
smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache
smtpd_tls_security_level = may
smtpd_use_tls = yes
smtp_tls_security_level = may
smtp_tls_CAfile = /etc/postfix/tls/smtpd.pem
smtp_tls_cert_file = /etc/postfix/tls/smtpd.pem
smtp_tls_key_file = /etc/postfix/tls/smtpd.pem
smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache
smtp_use_tls = yes
smtpd_tls_received_header = yes
smtpd_tls_ask_ccert = yes
smtpd_tls_loglevel = 1
tls_random_source = dev:/dev/urandom

If smtpd_sasl_auth_enable = yes option is set in /etc/postfix/main.cf, make sure that saslauthd service is started.

Reload Postfix configuration:

# service postfix reload

Script para criar um swap de 2GB em arquivo

sudo install -o root -g root -m 0600 /dev/null /swapfile
dd if=/dev/zero of=/swapfile bs=1k count=2048k
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap auto 0 0" | sudo tee -a /etc/fstab
sudo sysctl -w vm.swappiness=10
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

godep: command not found

Se encontrar o erro

godep: command not found

Simplesmente faça isso:

step 1: $ export GOBIN=$GOPATH/bin

step 2: $ export PATH=$GOPATH:$GOBIN:$PATH

step 3: go get github.com/tools/godep

step 4: godep save -r

Como identificar tabelas e índices inchados no PostgreSQL?

Como? Com essa query:

SELECT
  current_database(), schemaname, tablename, /*reltuples::bigint, relpages::bigint, otta,*/
  ROUND((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::FLOAT/otta END)::NUMERIC,1) AS tbloat,
  CASE WHEN relpages < otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END AS wastedbytes,
  iname, /*ituples::bigint, ipages::bigint, iotta,*/
  ROUND((CASE WHEN iotta=0 OR ipages=0 THEN 0.0 ELSE ipages::FLOAT/iotta END)::NUMERIC,1) AS ibloat,
  CASE WHEN ipages < iotta THEN 0 ELSE bs*(ipages-iotta) END AS wastedibytes
FROM (
  SELECT
    schemaname, tablename, cc.reltuples, cc.relpages, bs,
    CEIL((cc.reltuples*((datahdr+ma-
      (CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::FLOAT)) AS otta,
    COALESCE(c2.relname,'?') AS iname, COALESCE(c2.reltuples,0) AS ituples, COALESCE(c2.relpages,0) AS ipages,
    COALESCE(CEIL((c2.reltuples*(datahdr-12))/(bs-20::FLOAT)),0) AS iotta -- very rough approximation, assumes all cols
  FROM (
    SELECT
      ma,bs,schemaname,tablename,
      (datawidth+(hdr+ma-(CASE WHEN hdr%ma=0 THEN ma ELSE hdr%ma END)))::NUMERIC AS datahdr,
      (maxfracsum*(nullhdr+ma-(CASE WHEN nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2
    FROM (
      SELECT
        schemaname, tablename, hdr, ma, bs,
        SUM((1-null_frac)*avg_width) AS datawidth,
        MAX(null_frac) AS maxfracsum,
        hdr+(
          SELECT 1+COUNT(*)/8
          FROM pg_stats s2
          WHERE null_frac<>0 AND s2.schemaname = s.schemaname AND s2.tablename = s.tablename
        ) AS nullhdr
      FROM pg_stats s, (
        SELECT
          (SELECT current_setting('block_size')::NUMERIC) AS bs,
          CASE WHEN SUBSTRING(v,12,3) IN ('8.0','8.1','8.2') THEN 27 ELSE 23 END AS hdr,
          CASE WHEN v ~ 'mingw32' THEN 8 ELSE 4 END AS ma
        FROM (SELECT version() AS v) AS foo
      ) AS constants
      GROUP BY 1,2,3,4,5
    ) AS foo
  ) AS rs
  JOIN pg_class cc ON cc.relname = rs.tablename
  JOIN pg_namespace nn ON cc.relnamespace = nn.oid AND nn.nspname = rs.schemaname AND nn.nspname <> 'information_schema'
  LEFT JOIN pg_index i ON indrelid = cc.oid
  LEFT JOIN pg_class c2 ON c2.oid = i.indexrelid
) AS sml
ORDER BY wastedbytes DESC

Converter vídeo x265/HEVC para x264

X265_CodecPorque converter um vídeo encodado em x265/HEVC para x264? O x265 é mais novo, o arquivo fica bem menor praticamente metade do tamanho de um x264. Bom, se você pretende assistir o vídeo em um Raspberry PI você vai precisar fazer isso, pois a CPU/GPU do Raspberry Pi não dá conta de tocar o x265.

Este simples script converte todos os x265 com extensão .mkv no diretório para x264. Enjoy!

INPUT="$1"
for i in *.mkv ; do
    ffmpeg -i "$i" -bsf:v h264_mp4toannexb -sn -map 0:0 -map 0:1 -vcodec libx264 "$i.ts"
    mv "$i.ts" "$i.mpg"
    sleep 3
done

Fonte: http://askubuntu.com/questions/707397/batch-convert-h-265-mkv-to-h-264-with-ffmpeg-to-make-files-compatible-for-re-enc

Como instalar o ffmpeg no Centos7

Neste post irei explicar como instalar o ffmpeg (e mais algumas coisas) no Centos7, usando repositórios não oficiais. Não garanto que eles estejam atualizados, use por conta e risco.

yum -y install epel-release
 yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
 yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

yum install -y gstreamer gstreamer1 gstreamer-ffmpeg gstreamer-plugins-good gstreamer-plugins-ugly
 yum install -y vlc smplayer ffmpeg HandBrake-{gui,cli}
 yum install -y libdvdcss gstreamer{,1}-plugins-ugly gstreamer-plugins-bad-nonfree gstreamer1-plugins-bad-freeworld

yum install -y http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
 yum install -y flash-plugin
 yum install -y icedtea-web

Pronto.

←Older