Skip to content

Conversation

@maschad
Copy link
Member

@maschad maschad commented May 7, 2025

More info is explained in

We will need a back up of records as well as going forward once fiat payments are integrated we will also need to store user stack related info for the foreseeable future, which means it will need to be archived at intervals to avoid deletion.

Also we will need backups for any db maintenance or migrations

This integrates https://github.com/pgpartman/pg_partman to manage archiving via s3

@maschad maschad self-assigned this May 7, 2025
@maschad maschad added enhancement New feature or request deployment dependencies Pull requests that update a dependency file labels May 7, 2025
@maschad maschad requested a review from Copilot May 7, 2025 23:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces database maintenance scripts utilizing pg_partman for archiving and partitioning along with configuration updates for S3 exports and monitoring. Key changes include new shell and SQL scripts for partition management, restoration from S3, and archiving operations, as well as updates to docker-compose, Ofelia, and Prometheus configuration for automated scheduling and monitoring.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/db-maintenance/run-maintenance.sh New bash script to install extensions, initialize partitioning, and run archival processes.
scripts/db-maintenance/restore-from-s3.sql SQL function to restore data from S3 with proper logging and error handling.
scripts/db-maintenance/init-partioning.sql SQL script to set up partitioning using pg_partman (note a possible naming typo).
scripts/db-maintenance/archive-partitions.sql SQL script that archives partitions to S3 and creates local backups.
scripts/db-maintenance/.env.example AWS S3 configuration sample file for database archiving.
prometheus.yml Added scrape configuration for monitoring the archival process.
ofelia.ini Added cron job configuration for monthly archival maintenance.
docker-compose.yaml Added postgres-maintenance and postgres-cron services for DB maintenance scheduling.

Comment on lines +56 to +61
p_template_table = > NULL,
p_retention = > retention_months || ' months',
p_retention_keep_table = > true,
p_start_partition = > partition_start,
p_premake = > 3,
p_automatic_maintenance = > 'on'
Copy link

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter assignment operator in the partman.create_parent call is incorrectly spaced; replace '= >' with '=>' to ensure proper SQL syntax.

Suggested change
p_template_table = > NULL,
p_retention = > retention_months || ' months',
p_retention_keep_table = > true,
p_start_partition = > partition_start,
p_premake = > 3,
p_automatic_maintenance = > 'on'
p_template_table => NULL,
p_retention => retention_months || ' months',
p_retention_keep_table => true,
p_start_partition => partition_start,
p_premake => 3,
p_automatic_maintenance => 'on'

Copilot uses AI. Check for mistakes.
psql -v ON_ERROR_STOP=1 -d "$POSTGRES_DB" -c "CREATE EXTENSION IF NOT EXISTS aws_s3;"

# Initialize the partitioning schema
psql -v ON_ERROR_STOP=1 -d "$POSTGRES_DB" -f /scripts/init-partitioning.sql
Copy link

Copilot AI May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Verify that the file name '/scripts/init-partitioning.sql' matches the intended naming; if the filename is meant to be 'init-partitioning.sql', consider correcting 'init-partioning.sql' for consistency.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file deployment enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants