nqdev/postgres-pgagent

docker pull nqdev/postgres-pgagent:latest

Đây là container PostgreSQL tùy chỉnh với pgAgent và HTTP extension, được phát triển bởi NQDEV team. Container này tích hợp đầy đủ các tính năng để quản lý job scheduling và HTTP requests trực tiếp từ PostgreSQL.

🚀 Khởi động nhanh

# START: docker-compose up -d --build --force-recreate --remove-orphans
# STOP: docker-compose down -v
docker-compose up -d --build --force-recreate --remove-orphans

🧱 Thành phần & Tính năng

Core Components

  • PostgreSQL 17.5: Database engine chính với timezone Vietnam (Asia/Ho_Chi_Minh)

  • pgAgent: Hệ thống job scheduling cho PostgreSQL

  • HTTP Extension: Cho phép thực hiện HTTP requests từ PostgreSQL

  • Multi-stage Build: Tối ưu kích thước image với builder pattern

Tính năng đặc biệt

  • Tự động khởi tạo extensions (pgagent, http)

  • Error handling với trap mechanism trong shell scripts

  • Custom initialization scripts với logging chi tiết

  • Wait-for-it utility để đảm bảo database sẵn sàng

  • Data checksums mặc định cho integrity checking

  • Resource limits (CPU: 80%, RAM: 3.2G)

📦 Build & Deployment

Build với version tùy chỉnh

Docker Compose (Khuyến nghị)

Standalone Docker

🗂️ Cấu trúc Container

Thư mục chính

Library locations

  • HTTP Extension: /usr/lib/postgresql/17/lib/http.so

  • pgAgent: Installed via system packages

  • PostgreSQL Server Dev: /usr/include/postgresql/

🧪 Sử dụng Extensions

HTTP Extension

pgAgent Job Scheduling

⚙️ Biến môi trường

Biến
Mặc định
Mô tả

POSTGRES_USER

superuser

Username cho PostgreSQL

POSTGRES_PASSWORD

superuser

Password (bắt buộc)

POSTGRES_DB

postgresdb

Database name mặc định

POSTGRES_HOST_AUTH_METHOD

trust

Phương thức xác thực

POSTGRES_PORT

5432

Port PostgreSQL

POSTGRES_INITDB_ARGS

--data-checksums

Tham số initdb

TZ

Asia/Ho_Chi_Minh

Timezone

🔧 Scripts & Automation

Initialization Flow

  1. 00-init-custom.sh: Thực thi custom SQL scripts với error handling

  2. 01-docker-entrypoint.sh: Main PostgreSQL entrypoint với extended features

  3. 02-docker-ensure-initdb.sh: Đảm bảo database được khởi tạo đúng cách

Error Handling Features

  • Global error trapping với set -Eeo pipefail

  • Detailed logging cho mọi bước initialization

  • Graceful error messages với line number tracking

Wait-for-it Utility

🔍 Health Checks & Monitoring

Kiểm tra trạng thái

Performance Monitoring

📋 Volumes & Data Management

Backup Strategy

🔒 Security Notes

  • Host Auth Method: Mặc định trust cho development, khuyến nghị scram-sha-256 cho production

  • Network Security: Container isolated với custom DNS servers

  • Resource Limits: CPU 80%, Memory 3.2G để tránh system overload

  • Data Checksums: Enabled mặc định cho data integrity

🚀 Production Deployment

Docker Compose Override

📜 License

Distributed under the MIT License. See LICENSE for more information.

👨‍💻 Maintainer

NQDEV Team

Last updated

Was this helpful?