lmrc-postgres 0.3.16

PostgreSQL management library for the LMRC Stack - comprehensive library for managing PostgreSQL installations on remote servers via SSH
Documentation
//! # PostgreSQL Manager
//!
//! A comprehensive library for managing PostgreSQL installations on remote servers via SSH.
//!
//! ## Features
//!
//! - **Builder Pattern API**: Fluent, type-safe configuration
//! - **Idempotent Operations**: Safe to run multiple times
//! - **Diff Detection**: Track configuration changes
//! - **Full Lifecycle**: Install, configure, update, and uninstall
//! - **SSH-based**: Uses ssh-manager for secure remote operations
//! - **Error Handling**: Comprehensive error types with context
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use lmrc_postgres::{PostgresConfig, PostgresManager};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Build PostgreSQL configuration
//!     let config = PostgresConfig::builder()
//!         .version("15")
//!         .database_name("myapp")
//!         .username("myuser")
//!         .password("secure_password")
//!         .listen_addresses("0.0.0.0/0")
//!         .port(5432)
//!         .max_connections(100)
//!         .shared_buffers("256MB")
//!         .build()?;
//!
//!     // Create manager and connect
//!     let manager = PostgresManager::builder()
//!         .config(config)
//!         .server_ip("192.168.1.100")
//!         .ssh_user("root")
//!         .build()?;
//!
//!     // Install and configure PostgreSQL
//!     manager.install().await?;
//!     manager.configure().await?;
//!
//!     // Test the connection
//!     manager.test_connection().await?;
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Examples
//!
//! ### Install with custom configuration
//!
//! ```rust,no_run
//! # use lmrc_postgres::{PostgresConfig, PostgresManager};
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let config = PostgresConfig::builder()
//!     .version("15")
//!     .database_name("production_db")
//!     .username("app_user")
//!     .password("strong_password")
//!     .listen_addresses("10.0.0.0/8")
//!     .port(5432)
//!     .max_connections(200)
//!     .shared_buffers("512MB")
//!     .effective_cache_size("2GB")
//!     .build()?;
//!
//! let manager = PostgresManager::builder()
//!     .config(config)
//!     .server_ip("10.0.1.50")
//!     .ssh_user("admin")
//!     .build()?;
//!
//! manager.setup().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Detect configuration changes
//!
//! ```rust,no_run
//! # use lmrc_postgres::{PostgresConfig, PostgresManager};
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! # let manager = PostgresManager::builder()
//! #     .config(PostgresConfig::builder().version("15").build()?)
//! #     .server_ip("192.168.1.100")
//! #     .build()?;
//! let diff = manager.diff().await?;
//!
//! if diff.has_changes() {
//!     println!("Configuration changes detected:");
//!     for change in diff.changes() {
//!         println!("  - {}", change);
//!     }
//!
//!     // Apply changes
//!     manager.apply_diff(&diff).await?;
//! }
//! # Ok(())
//! # }
//! ```

pub mod adapter;
pub mod backup;
pub mod config;
pub mod diff;
pub mod error;
pub mod install;
pub mod manager;
pub mod operations;
pub mod user_db_management;
pub mod validation;

pub use adapter::PostgresAdapter;
pub use backup::{
    ConfigBackup, PgHbaDiff, PgHbaRule, backup_config, cleanup_old_backups, diff_pg_hba_rules,
    list_backups, parse_pg_hba_rules, read_pg_hba, restore_backup, rollback_config,
};
pub use config::{PostgresConfig, PostgresConfigBuilder};
pub use diff::{ConfigChange, ConfigDiff};
pub use error::{Error, Result};
pub use install::{
    InstallationStep, Platform, SystemInfo, SystemRequirements, check_requirements,
    check_version_available, detect_platform, get_system_info, upgrade, verify_installation,
};
pub use manager::{PostgresManager, PostgresManagerBuilder};
pub use user_db_management::{
    DatabaseInfo, Privilege, UserInfo, create_database_with_options, create_role,
    create_user_with_options, database_exists, drop_database, drop_user, grant_privileges,
    grant_role, list_databases, list_users, revoke_privileges, revoke_role, update_user_password,
    user_exists,
};
pub use validation::{
    WorkloadType, auto_tune, check_conflicting_settings, parse_memory_size, validate_cidr,
    validate_comprehensive, validate_listen_addresses, validate_memory_size,
    validate_resource_limits,
};

// Re-export ssh-manager for convenience
pub use lmrc_ssh::{AuthMethod, CommandOutput, SshClient};