Shoulder.dev Logo Shoulder.dev

How do I add a Postgres database to the codebase? - docker/genai-stack

Adding a Postgres Database to the genai-stack Codebase

This documentation outlines the process of adding a Postgres database to the genai-stack codebase.

1. Dockerfile Modifications

  1. Create a new Dockerfile:

    • This new Dockerfile will be used to build an image with Postgres installed.
  2. Install Postgres:

    • Add the following lines to the Dockerfile to install Postgres.
    FROM postgres:14.4-alpine
    COPY ./postgres.conf /etc/postgresql/14/main/postgresql.conf
    COPY ./pg_hba.conf /etc/postgresql/14/main/pg_hba.conf
    COPY ./init.sql /docker-entrypoint-initdb.d/init.sql
    
  3. Create the PostgreSQL configuration files:

    • postgres.conf: This file is used to configure Postgres.
    # Configuration for PostgreSQL
    # This file is intended to be included from the main configuration file
    # using 'include "postgres.conf"'.  It is not intended to be used directly.
    
    # Log the connection attempts
    log_connections = on
    
    # Log the disconnect attempts
    log_disconnections = on
    
    # Log the startup and shutdown process
    log_startup = on
    log_shutdown = on
    
    # Log the activity on each database
    log_statement = 'all'
    
    # Log the queries that take longer than 100ms
    log_min_duration_statement = 100
    
    # Log the queries that consume more than 10MB of memory
    log_min_duration_statement = 100
    
    # Log the queries that consume more than 10MB of disk
    log_min_duration_statement = 100
    
    # Log the queries that cause a lock conflict
    log_lock_waits = on
    
    # Log the queries that cause a deadlock
    log_deadlocks = on
    
    # Log the queries that cause a timeout
    log_timeouts = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollbacks = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commits = on
    
    # Log the queries that cause a transaction abort
    log_transaction_aborts = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit = on
    
    # Log the queries that cause a transaction rollback
    log_transaction_rollback = on
    
    # Log the queries that cause a transaction abort
    log_transaction_abort = on
    
    # Log the queries that cause a transaction idle
    log_transaction_idle = on
    
    # Log the queries that cause a transaction active
    log_transaction_active = on
    
    # Log the queries that cause a transaction finish
    log_transaction_finish = on
    
    # Log the queries that cause a transaction start
    log_transaction_start = on
    
    # Log the queries that cause a transaction commit
    log_transaction_commit