Skip to content

Instantly share code, notes, and snippets.

View aei-tech's full-sized avatar
🏠
Working from home

Alex aei-tech

🏠
Working from home
View GitHub Profile
@aei-tech
aei-tech / huge_pages_pg_calc.sh
Last active February 15, 2025 23:18 — forked from AlexBaranowski/huge_pages_pg_calc.sh
Simple script to calculate huge pages for PostgreSQL. Please note that this is baseline and require further tunning.
#!/usr/bin/env bash
[ -z "$PGDATA" ] && echo "PGDATA is not defined!" && exit 1
[ ! -e "$PGDATA"/postmaster.pid ] && echo "Cannot find $PGDATA/postmaster.pid is PostgreSQL server running?" && exit 1
PG_PID=$(head -1 "$PGDATA"/postmaster.pid)
PG_MEM_U=$(grep ^VmPeak /proc/"$PG_PID"/status | awk '{print $3}')
HP_MEM_U=$(grep ^Hugepagesize /proc/meminfo | awk '{print $3}')
[ "$PG_MEM_U" != "$HP_MEM_U" ] && echo "The units differ please calculate the Huge Pages manually" && exit 1
PG_MEM=$(grep ^VmPeak /proc/"$PG_PID"/status | awk '{print $2}')
HP_MEM=$(grep ^Hugepagesize /proc/meminfo | awk '{print $2}')
@aei-tech
aei-tech / change_db_owner.sh
Last active December 8, 2024 21:01 — forked from gingerlime/change_db_owner.sh
Postgresql - Changing ownership on all tables
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script set ownership for all table, sequence and views for a given database
Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto
@aei-tech
aei-tech / pg_backup_all.sh
Last active February 15, 2025 23:19
pg_dump_backup_all.sh
#!/usr/bin/env bash
# Location to place backups.
BACKUP_DIR="/var/lib/pgsql/backup_dir/"
NIGHTLY_DIR="/var/backups/databases/latest/"
# String to append to the name of the backup files
BACKUP_DATE=$(date +%d-%m-%Y)
# Numbers of days you want to keep copie of your databases