Skip to content

Commit

Permalink
Merge pull request #125 from EyeSeeTea/feature/enable-postgres-query-…
Browse files Browse the repository at this point in the history
…logs

Enable postgres logs
  • Loading branch information
ifoche authored Nov 21, 2024
2 parents 3c479b3 + 0a84385 commit caea3cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,15 @@ Create a dockerized d2-docker:
$ bash build-docker-container.sh
```

## Debug SQL queries

By default, d2-docker logs all SQL queries executed (one file per weekday). Example:

```
$ db_container="d2-docker-docker-eyeseetea-com-samaritans-40-4-0-sp-cpr-test-db-1"
$ docker exec -it "$db_container" tail -f /var/lib/postgresql/data/log/queries-Thu.log
```

### API Server

Start Flask server in development mode:
Expand Down
3 changes: 3 additions & 0 deletions src/d2_docker/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def setup(parser):
parser.add_argument("--deploy-path", type=str, help="Set Tomcat context.path")
parser.add_argument("--java-opts", type=str, help="Set Tomcat JAVA_OPTS")
parser.add_argument("--postgis-version", type=str, help="Set PostGIS database version")
parser.add_argument("--enable-postgres-queries-logging", action="store_true",
help="Enable Postgres queries logging")


def run(args):
Expand Down Expand Up @@ -110,6 +112,7 @@ def start(args):
dhis_conf=args.dhis_conf,
java_opts=args.java_opts,
postgis_version=args.postgis_version,
enable_postgres_queries_logging=args.enable_postgres_queries_logging,
)

if args.detach:
Expand Down
2 changes: 1 addition & 1 deletion src/d2_docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ services:
POSTGRES_DB: dhis2
POSTGRES_USER: dhis
POSTGRES_PASSWORD: dhis
command: "postgres -c max_locks_per_transaction=100 -c max_connections=250 -c shared_buffers=3200MB -c work_mem=24MB -c maintenance_work_mem=1024MB -c effective_cache_size=8000MB -c checkpoint_completion_target=0.8 -c synchronous_commit=off -c wal_writer_delay=10000ms -c random_page_cost=1.1 -c max_locks_per_transaction=100 -c temp_buffers=16MB -c track_activity_query_size=8192 -c jit=off"
command: "postgres -c max_locks_per_transaction=100 -c max_connections=250 -c shared_buffers=3200MB -c work_mem=24MB -c maintenance_work_mem=1024MB -c effective_cache_size=8000MB -c checkpoint_completion_target=0.8 -c synchronous_commit=off -c wal_writer_delay=10000ms -c random_page_cost=1.1 -c max_locks_per_transaction=100 -c temp_buffers=16MB -c track_activity_query_size=8192 -c jit=off ${PSQL_ENABLE_QUERY_LOGS--c logging_collector=on -c log_statement=all -c log_filename=queries-%a.log}"
restart: unless-stopped
ports:
- "${DB_PORT}"
Expand Down
2 changes: 2 additions & 0 deletions src/d2_docker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def run_docker_compose(
dhis2_auth=None,
tomcat_server=None,
postgis_version=None,
enable_postgres_queries_logging=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -294,6 +295,7 @@ def run_docker_compose(
("DB_PORT", ("{}:5432".format(db_port) if db_port else "0:1000")),
# Add ROOT_PATH from environment (required when run inside a docker)
("ROOT_PATH", ROOT_PATH),
("PSQL_ENABLE_QUERY_LOGS", "") if not enable_postgres_queries_logging else None,
]
env = dict((k, v) for (k, v) in [pair for pair in env_pairs if pair] if v is not None)

Expand Down

0 comments on commit caea3cb

Please sign in to comment.