# PostgreSQL Database

Reliable database backend for applications.

## Overview

PostgreSQL is a powerful, open-source relational database system. In Changemaker Lite, it serves as the backend database for Listmonk and can be used by other applications requiring persistent data storage.

## Features

- ACID compliance
- Advanced SQL features
- JSON/JSONB support
- Full-text search
- Extensibility
- High performance
- Reliability and data integrity

## Access

- **Default Port**: 5432
- **Host**: `listmonk-db` (internal container name)
- **Database**: Set via `POSTGRES_DB` environment variable
- **Username**: Set via `POSTGRES_USER` environment variable
- **Password**: Set via `POSTGRES_PASSWORD` environment variable

## Configuration

### Environment Variables

- `POSTGRES_USER`: Database username
- `POSTGRES_PASSWORD`: Database password  
- `POSTGRES_DB`: Database name

### Health Checks

The PostgreSQL container includes health checks to ensure the database is ready before dependent services start.

### Data Persistence

Database data is stored in a Docker volume (`listmonk-data`) to ensure persistence across container restarts.

## Connecting to the Database

### From Host Machine

You can connect to PostgreSQL from your host machine using:

```bash
psql -h localhost -p 5432 -U [username] -d [database]
```

### From Other Containers

Other containers can connect using the internal hostname `listmonk-db` on port 5432.

## Backup and Restore

### Backup

```bash
docker exec listmonk-db pg_dump -U [username] [database] > backup.sql
```

### Restore

```bash
docker exec -i listmonk-db psql -U [username] [database] < backup.sql
```

## Monitoring

Monitor database health and performance through:
- Container logs: `docker logs listmonk-db`
- Database metrics and queries
- Connection monitoring

## Security Considerations

- Use strong passwords
- Regularly update PostgreSQL version
- Monitor access logs
- Implement regular backups
- Consider network isolation

## Official Documentation

For comprehensive PostgreSQL documentation:
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)
- [Docker PostgreSQL Image](https://hub.docker.com/_/postgres)
