lmrc-postgres 0.3.16

PostgreSQL management library for the LMRC Stack - comprehensive library for managing PostgreSQL installations on remote servers via SSH
Documentation
//! Basic PostgreSQL installation example
//!
//! This example demonstrates the simplest way to install and configure PostgreSQL
//! on a remote server.
//!
//! Usage:
//! ```bash
//! cargo run --example basic_install
//! ```

use lmrc_postgres::{PostgresConfig, PostgresManager};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize logging
    tracing_subscriber::fmt::init();

    // Build PostgreSQL configuration
    let config = PostgresConfig::builder()
        .version("15")
        .database_name("myapp")
        .username("myuser")
        .password("secure_password_123")
        .build()?;

    // Create manager
    // NOTE: Update these values for your environment
    let manager = PostgresManager::builder()
        .config(config)
        .server_ip("192.168.1.100") // Change to your server IP
        .ssh_user("root") // Change to your SSH user
        .ssh_password("your_ssh_password") // Or use .ssh_key_path()
        .build()?;

    println!("Starting PostgreSQL installation...");

    // Install and configure PostgreSQL (idempotent)
    manager.setup().await?;

    println!("PostgreSQL installed and configured successfully!");

    // Test the connection
    println!("Testing database connection...");
    manager.test_connection().await?;

    println!("✓ Connection test successful!");
    println!("PostgreSQL is ready to use!");

    Ok(())
}