Skip to content

Instantly share code, notes, and snippets.

@viewpnt
viewpnt / docker-compose-backup.sh
Created June 13, 2024 19:49 — forked from pirate/docker-compose-backup.sh
Backup a docker-compose project, including all images, named and unnamed volumes, container filesystems, config, logs, and databases.
#!/usr/bin/env bash
### Bash Environment Setup
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
# set -o xtrace
set -o errexit
set -o errtrace
set -o nounset
set -o pipefail
@viewpnt
viewpnt / postgres_queries_and_commands.sql
Created January 7, 2024 22:17 — forked from indigoviolet/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@viewpnt
viewpnt / utils.sql
Created January 7, 2024 21:20 — forked from parallelo3301/utils.sql
PostgreSQL utils
-- v5
----------------------------------------------------------- basic instance info
-- show db version
SELECT version();
-- uptime
SELECT pg_postmaster_start_time();
-- show connections
@viewpnt
viewpnt / postgres_recovery.md
Created December 8, 2022 02:17 — forked from supix/postgres_recovery.md
Postgres error: Missing chunk 0 for toast value in pg_toast

The problem

In some cases, it is possible that PostgreSQL tables get corrupted. This can happen in case of hardware failures (e.g. hard disk drives with write-back cache enabled, RAID controllers with faulty/worn out battery backup, etc.), as clearly reported in this wiki page. Furthermore, it can happen in case of incorrect setup, as well.

One of the symptoms of such corruptions is the following message:

ERROR: missing chunk number 0 for toast value 123456 in pg_toast_45678

This almost surely indicates that a corrupted chunk is present within a table file. But there is a good way to get rid of it.

@viewpnt
viewpnt / centos_php_fpm_coredumps.md
Created August 25, 2020 14:18 — forked from mkubenka/centos_php_fpm_coredumps.md
How to enable CentOS PHP-FPM coredumps.

CentOS PHP-FPM coredumps

https://wiki.archlinux.org/index.php/Core_dump

Enabling core dumps for PHP-FPM on CentOS 7 require several steps.

Set the rlimit_core directive in /etc/php-fpm.d/pool.conf and /etc/php-fpm.conf to unlimited:

rlimit_core = unlimited
@viewpnt
viewpnt / 01-curl.go
Created June 9, 2020 06:34 — forked from jmoiron/01-curl.go
io.Reader & io.Writer fun
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func init() {
@viewpnt
viewpnt / StreamToString.go
Created May 29, 2020 17:33 — forked from tejainece/StreamToString.go
Golang: io.Reader stream to string or byte slice
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)
@viewpnt
viewpnt / SSHA512_gen.py
Created May 15, 2020 03:10 — forked from JayBeavers/SSHA512_gen.py
Create a salted SHA512 password hash for use with Dovecot, updated for python 3
#!/usr/bin/python
import os
import hashlib
import getpass
import base64
password1 = None
password2 = None
@viewpnt
viewpnt / SSHA512_gen.py
Created May 15, 2020 03:10 — forked from garrettreid/SSHA512_gen.py
Create a salted SHA512 password hash for use with Dovecot
#!/usr/bin/python
import os
import hashlib
import getpass
import base64
password1 = None
password2 = None