Rok Damjanić Technical Documentation & Blog

website·Indexed 31 days ago

https://rokdamjanic.com

A collection of technical solutions, configuration guides, and blog posts covering PostgreSQL (streaming replication, Patroni clusters, PAM authentication, and pg-ldap-sync), Proxmox, RHEL/AlmaLinux disk management, Ansible automation for ZSH, and various Linux system optimizations including OpenSCAP audits and Fail2Ban notifications.

Tokens
25.4K
Snippets
157
Records
176
Agent score
53%

What's inside Rok Damjanić Documentation

  1. Overview of PostgreSQL Foreign Data Wrappers (FDW)

    Foreign Data Wrappers (FDW) implement the SQL/MED (Management of External Data) standard, allowing PostgreSQL to access external data sources using a consistent SQL interface. This enables developers to query remote PostgreSQL databases, join local and remote tables in a single query, and create federated database architectures without requiring ETL processes.
  2. Overview of pg-ldap-sync

    pg-ldap-sync is a Ruby-based tool used to automatically synchronize LDAP/Active Directory users and groups to PostgreSQL roles. It maintains group memberships, supports custom role options and filtering, and can be scheduled as a task for continuous synchronization.
  3. PostgreSQL HA Cluster Architecture Overview

    The high-availability cluster consists of three nodes, each running Patroni, PostgreSQL, and etcd. Patroni manages the PostgreSQL instances and handles automatic failover. etcd serves as the distributed consensus store for cluster state. HAProxy is used for load balancing across the nodes, and Watchdog is employed to prevent split-brain scenarios.
  4. Prerequisites for creating a Proxmox ZFS mirror

    Before attempting to create a ZFS mirror for the Proxmox system disk, ensure the following conditions are met:

    • Proxmox VE is installed on a single NVMe drive.
    • A second NVMe drive is available, equal to or larger than the first.
    • The system is using UEFI boot mode (verify by running proxmox-boot-tool status).
    • You have root access to the Proxmox host.

    Warning: This process modifies disk partitions. Ensure all data is backed up before proceeding.

    proxmox-boot-tool status
  5. Install Pgpool-II for PostgreSQL Load Balancing

    Install Pgpool-II to provide connection pooling, load balancing, and automatic failover for a PostgreSQL cluster.
    # Add PostgreSQL repository
    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
    
    # Import repository key
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    
    # Move key to proper location
    sudo mv /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/psql.gpg
    
    # Update and install
    sudo apt-get update
    sudo apt-get install -y pgpool2 libpgpool2 postgresql-15-pgpool2
  6. Verify ZSH and Oh-My-Zsh installation

    After running the playbook, verify the installation by checking the active shell, the existence of the Oh-My-Zsh directory, and the presence of installed plugins and themes.
    # Verify shell path
    echo $SHELL
    which zsh
    
    # Check Oh-My-Zsh directory
    ls -la ~/.oh-my-zsh
    
    # Verify plugins (e.g., zsh-autosuggestions, zsh-syntax-highlighting)
    ls ~/.oh-my-zsh/custom/plugins/
    
    # Verify theme (e.g., powerlevel10k)
    ls ~/.oh-my-zsh/custom/themes/
  7. Retrieve the full Webex Room ID using a bot token

    You must use the full room ID (not just the short UUID) for the bot to post messages. Use the bot's access token to list available rooms and identify the correct ID.
    curl -sS https://webexapis.com/v1/rooms \
      -H "Authorization: Bearer YOUR_BOT_TOKEN" | python3 -m json.tool
  8. Implement partitioning with foreign tables

    PostgreSQL allows using foreign tables as partitions within a partitioned table. This enables a hybrid setup where some data is stored locally and some is retrieved from a remote server.
    -- Create partitioned table
    CREATE TABLE all_data (
        id INTEGER,
        region TEXT,
        data TEXT
    ) PARTITION BY LIST (region);
    
    -- Local partition
    CREATE TABLE data_local PARTITION OF all_data
    FOR VALUES IN ('local');
    
    -- Foreign table partition
    CREATE FOREIGN TABLE data_remote PARTITION OF all_data
    FOR VALUES IN ('remote')
    SERVER remote_server;
  9. Remap keyboard keys in X11 using xmodmap

    Use xmodmap to change keyboard key symbols or keycodes in X11. You can use xev to find the specific keysym or keycode for a key. Changes can be made permanent by adding commands to .bashrc or creating a ~/.Xmodmap file.
    # Remap Super_L key to type "µ"
    xmodmap -e 'keysym Super_L = mu mu mu'
    
    # Remap F8 (keycode 74) to KP_0 and Shift+F8 to KP_Equal
    xmodmap -e "keycode 74 = KP_0 KP_Equal"
    
    # Clear Mod4 modifiers
    xmodmap -e 'clear Mod4'

    To make permanent via ~/.Xmodmap file:

    keysym Super_L = mu mu mu clear Mod4

  10. Secure sensitive data with Ansible Vault

    Use Ansible Vault to encrypt sensitive variables (like passwords) in a separate file and reference that file in the playbook using vars_files.
    # Create encrypted file
    ansible-vault create secrets.yml
    
    # Run playbook with vault password prompt
    ansible-playbook -i hosts.ini zsh-playbook.yml --ask-vault-pass

    In playbook:

    vars_files:

    • secrets.yml
  11. Verify PostgreSQL installation and data after upgrade

    After performing a PostgreSQL upgrade, use the following commands to verify the version, list databases, test connectivity, and check installed extensions.
    # Verify PostgreSQL version
    sudo -iu postgres psql -c "SELECT version();"
    
    # List all databases
    sudo -iu postgres psql -l
    
    # Test connection to a specific database
    psql -h localhost -U myuser -d mydb
    
    # Check available extensions
    psql -c "SELECT * FROM pg_available_extensions ORDER BY name;"
    
    # Monitor logs for the new version (example for v18)
    sudo tail -f /var/lib/pgsql/18/data/log/postgresql-*.log
  12. Create Foreign Tables manually

    You can explicitly define the structure of a foreign table to map it to a specific table on the remote server.
    CREATE FOREIGN TABLE public.nov_indeks (
        id INTEGER,
        naziv VARCHAR(255),
        vrednost NUMERIC(10,2),
        datum DATE
    )
    SERVER nov_indeks_fdw
    OPTIONS (
        schema_name 'public',
        table_name 'indeks',
        updatable 'false' -- Optional: set to 'false' for read-only
    );