From 9d77fac4a4a5da1aae9e20ec1d542dac5630a796 Mon Sep 17 00:00:00 2001 From: Maksym Buz Date: Mon, 30 Mar 2026 19:40:32 +0000 Subject: [PATCH] refactor(procedures): rename init script and revert monitoring view --- ARCHITECTURE.md | 2 +- postgresql/docker/run_test_env.sh | 4 ++-- .../{00_partitions_init.sql => 00_schema_create.sql} | 0 postgresql/procedures/03_monitoring_view.sql | 3 ++- postgresql/procedures/README.md | 7 +++++-- 5 files changed, 10 insertions(+), 6 deletions(-) rename postgresql/procedures/{00_partitions_init.sql => 00_schema_create.sql} (100%) diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 1b0c19d..86c0167 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -21,7 +21,7 @@ This ensures that the partitioning scripts will work flawlessly, even in custom The solution is divided into a series of SQL scripts that must be executed sequentially to set up the environment. -### 1. `00_partitions_init.sql` +### 1. `00_schema_create.sql` * **Purpose:** Initializes the foundation for the partitioning system. * **Actions:** * Creates the isolated `partitions` schema to keep everything separate from Zabbix's own structure. diff --git a/postgresql/docker/run_test_env.sh b/postgresql/docker/run_test_env.sh index b1d5f2b..d225144 100755 --- a/postgresql/docker/run_test_env.sh +++ b/postgresql/docker/run_test_env.sh @@ -67,8 +67,8 @@ if [[ -f "$SQL_DIR/schema.sql" ]]; then cp "$SQL_DIR/schema.sql" ./init_scripts/01_00_schema.sql # 1.1 Partitioning Infrastructure - if [[ -f "../procedures/00_partitions_init.sql" ]]; then - cp "../procedures/00_partitions_init.sql" ./init_scripts/01_10_partitions_init.sql + if [[ -f "../procedures/00_schema_create.sql" ]]; then + cp "../procedures/00_schema_create.sql" ./init_scripts/01_10_schema_create.sql fi if [[ -f "../procedures/01_maintenance.sql" ]]; then cp "../procedures/01_maintenance.sql" ./init_scripts/01_30_maintenance.sql diff --git a/postgresql/procedures/00_partitions_init.sql b/postgresql/procedures/00_schema_create.sql similarity index 100% rename from postgresql/procedures/00_partitions_init.sql rename to postgresql/procedures/00_schema_create.sql diff --git a/postgresql/procedures/03_monitoring_view.sql b/postgresql/procedures/03_monitoring_view.sql index 7b123bb..15c06a0 100644 --- a/postgresql/procedures/03_monitoring_view.sql +++ b/postgresql/procedures/03_monitoring_view.sql @@ -2,7 +2,8 @@ -- Creates a view to monitor partition status and sizes. -- ============================================================================ -CREATE OR REPLACE VIEW partitions.monitoring AS +DROP VIEW IF EXISTS partitions.monitoring; +CREATE VIEW partitions.monitoring AS SELECT parent.relname AS parent_table, c.table_name, diff --git a/postgresql/procedures/README.md b/postgresql/procedures/README.md index 00f9932..da4724e 100644 --- a/postgresql/procedures/README.md +++ b/postgresql/procedures/README.md @@ -55,7 +55,7 @@ If you are deploying Zabbix on a fresh database instance (like AWS RDS) rather t ## Installation The installation is performed by executing the SQL procedures in the following order: -1. Initialize schema (`00_partitions_init.sql`). +1. Initialize schema (`00_schema_create.sql`). 2. Install maintenance procedures (`01_maintenance.sql`). 3. Enable partitioning on tables (`02_enable_partitioning.sql`). 4. Install monitoring views (`03_monitoring_view.sql`). @@ -70,7 +70,7 @@ DB_HOST="localhost" # Or your RDS endpoint DB_NAME="zabbix" DB_USER="zabbix" -for script in 00_partitions_init.sql 01_maintenance.sql 02_enable_partitioning.sql 03_monitoring_view.sql; do +for script in 00_schema_create.sql 01_maintenance.sql 02_enable_partitioning.sql 03_monitoring_view.sql; do echo "Applying $script..." psql -h $DB_HOST -U $DB_USER -d $DB_NAME -f "$script" done @@ -247,6 +247,9 @@ GRANT USAGE ON SCHEMA partitions TO zbx_monitor; GRANT SELECT ON partitions.monitoring TO zbx_monitor; ``` +> [!NOTE] +> If you ever apply updates to `03_monitoring_view.sql`, you should run the script as the `zabbix` database user (the original creator of the view). The script drops and recreates the view, so running it as `zabbix` ensures the view retains its ownership and preserves existing `GRANT` permissions for read-only users. + ## Implementation Details ### `auditlog` Table