lmrc_postgres/lib.rs
1//! # PostgreSQL Manager
2//!
3//! A comprehensive library for managing PostgreSQL installations on remote servers via SSH.
4//!
5//! ## Features
6//!
7//! - **Builder Pattern API**: Fluent, type-safe configuration
8//! - **Idempotent Operations**: Safe to run multiple times
9//! - **Diff Detection**: Track configuration changes
10//! - **Full Lifecycle**: Install, configure, update, and uninstall
11//! - **SSH-based**: Uses ssh-manager for secure remote operations
12//! - **Error Handling**: Comprehensive error types with context
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use lmrc_postgres::{PostgresConfig, PostgresManager};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! // Build PostgreSQL configuration
22//! let config = PostgresConfig::builder()
23//! .version("15")
24//! .database_name("myapp")
25//! .username("myuser")
26//! .password("secure_password")
27//! .listen_addresses("0.0.0.0/0")
28//! .port(5432)
29//! .max_connections(100)
30//! .shared_buffers("256MB")
31//! .build()?;
32//!
33//! // Create manager and connect
34//! let manager = PostgresManager::builder()
35//! .config(config)
36//! .server_ip("192.168.1.100")
37//! .ssh_user("root")
38//! .build()?;
39//!
40//! // Install and configure PostgreSQL
41//! manager.install().await?;
42//! manager.configure().await?;
43//!
44//! // Test the connection
45//! manager.test_connection().await?;
46//!
47//! Ok(())
48//! }
49//! ```
50//!
51//! ## Examples
52//!
53//! ### Install with custom configuration
54//!
55//! ```rust,no_run
56//! # use lmrc_postgres::{PostgresConfig, PostgresManager};
57//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
58//! let config = PostgresConfig::builder()
59//! .version("15")
60//! .database_name("production_db")
61//! .username("app_user")
62//! .password("strong_password")
63//! .listen_addresses("10.0.0.0/8")
64//! .port(5432)
65//! .max_connections(200)
66//! .shared_buffers("512MB")
67//! .effective_cache_size("2GB")
68//! .build()?;
69//!
70//! let manager = PostgresManager::builder()
71//! .config(config)
72//! .server_ip("10.0.1.50")
73//! .ssh_user("admin")
74//! .build()?;
75//!
76//! manager.setup().await?;
77//! # Ok(())
78//! # }
79//! ```
80//!
81//! ### Detect configuration changes
82//!
83//! ```rust,no_run
84//! # use lmrc_postgres::{PostgresConfig, PostgresManager};
85//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
86//! # let manager = PostgresManager::builder()
87//! # .config(PostgresConfig::builder().version("15").build()?)
88//! # .server_ip("192.168.1.100")
89//! # .build()?;
90//! let diff = manager.diff().await?;
91//!
92//! if diff.has_changes() {
93//! println!("Configuration changes detected:");
94//! for change in diff.changes() {
95//! println!(" - {}", change);
96//! }
97//!
98//! // Apply changes
99//! manager.apply_diff(&diff).await?;
100//! }
101//! # Ok(())
102//! # }
103//! ```
104
105pub mod backup;
106pub mod config;
107pub mod diff;
108pub mod error;
109pub mod install;
110pub mod manager;
111pub mod operations;
112pub mod user_db_management;
113pub mod validation;
114
115pub use backup::{
116 ConfigBackup, PgHbaDiff, PgHbaRule, backup_config, cleanup_old_backups, diff_pg_hba_rules,
117 list_backups, parse_pg_hba_rules, read_pg_hba, restore_backup, rollback_config,
118};
119pub use config::{PostgresConfig, PostgresConfigBuilder};
120pub use diff::{ConfigChange, ConfigDiff};
121pub use error::{Error, Result};
122pub use install::{
123 InstallationStep, Platform, SystemInfo, SystemRequirements, check_requirements,
124 check_version_available, detect_platform, get_system_info, upgrade, verify_installation,
125};
126pub use manager::{PostgresManager, PostgresManagerBuilder};
127pub use user_db_management::{
128 DatabaseInfo, Privilege, UserInfo, create_database_with_options, create_role,
129 create_user_with_options, database_exists, drop_database, drop_user, grant_privileges,
130 grant_role, list_databases, list_users, revoke_privileges, revoke_role, update_user_password,
131 user_exists,
132};
133pub use validation::{
134 WorkloadType, auto_tune, check_conflicting_settings, parse_memory_size, validate_cidr,
135 validate_comprehensive, validate_listen_addresses, validate_memory_size,
136 validate_resource_limits,
137};
138
139// Re-export ssh-manager for convenience
140pub use lmrc_ssh::{AuthMethod, CommandOutput, SshClient};