834-Adding-pg_cron-to-Postgres-Docker-Image #842

Merged
a22erigr merged 3 commits from 834-Adding-pg_cron-to-Postgres-Docker-Image into team_2_week_5 2026-05-08 11:15:25 +00:00
Collaborator

What's been done

Done on Windows 11
Added pg_cron to our postgres image. Uses citusdata's pg_cron git. Citusdata is the industry standard, and has been acquired by Microsoft. If we ever switch of using an Alpine image, this could be changed to not require its own Dockerfile.

  • /DockerCompose/postgres_dockerfile/Dockerfile
    • Created folder and new Dockerfile for our postgres image. Since we use an alpine build we have to create our custom postgres Dockerfile, since alpine uses APK instead of apt. All it does differently is that it adds the pg_cron extension to the shared libraries, meaning our sensors database can create it on startup.
  • /DockerCompose/compose.yaml
    • Postgres will now build the new dockerfile (above)
  • /DockerCompose/init_sql/01-sensors.sql
    • Now creates pg_cron extension (if it doesn't already exist)
  • /DockerCompose/init_sql/ 03-sensors-cron-jobs.sql
    • Created sql file that will house our scheduled cron jobs

How to check if it works

IMPORTANT
Make sure that you delete existing postgres image and volumes

  1. Rebuild all images (expect postgres build time to be longer than usual)
  2. Enter postgres container (either in docker desktop or enter using docker exec command in terminal)
  3. Enter sensors database using psql -U "database username" -d sensors (username found in .env)
  4. Run the following command: SELECT * FROM pg_extension WHERE extname = 'pg_cron';
    4.1. You should see one row containing pg_cron
  5. Run the following command: SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'cron';
    5.1. You should see cron
  6. If above commands gave the expected outputs, pg_cron is working correctly
  7. If not, please post outputs in review, as well as checking postgres container logs

I had some problems with the volumes, so if you have the time, prune docker. It should work with just removing volumes using docker compose down -v.

## What's been done Done on Windows 11 Added pg_cron to our postgres image. Uses citusdata's pg_cron git. Citusdata is the industry standard, and has been acquired by Microsoft. If we ever switch of using an Alpine image, this could be changed to not require its own Dockerfile. + /DockerCompose/postgres_dockerfile/Dockerfile + Created folder and new Dockerfile for our postgres image. Since we use an alpine build we have to create our custom postgres Dockerfile, since alpine uses APK instead of apt. All it does differently is that it adds the pg_cron extension to the shared libraries, meaning our sensors database can create it on startup. + /DockerCompose/compose.yaml + Postgres will now build the new dockerfile (above) + /DockerCompose/init_sql/01-sensors.sql + Now creates pg_cron extension (if it doesn't already exist) + /DockerCompose/init_sql/ 03-sensors-cron-jobs.sql + Created sql file that will house our scheduled cron jobs ## How to check if it works **IMPORTANT** Make sure that you delete existing postgres image and volumes 1. Rebuild all images (expect postgres build time to be longer than usual) 2. Enter postgres container (either in docker desktop or enter using docker exec command in terminal) 3. Enter sensors database using psql -U "database username" -d sensors (username found in .env) 4. Run the following command: SELECT * FROM pg_extension WHERE extname = 'pg_cron'; 4.1. You should see one row containing pg_cron 5. Run the following command: SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'cron'; 5.1. You should see cron 6. If above commands gave the expected outputs, pg_cron is working correctly 7. If not, please post outputs in review, as well as checking postgres container logs I had some problems with the volumes, so if you have the time, prune docker. It should work with just removing volumes using docker compose down -v.
Collaborator

Review on #842

Whats done

Tested on macOS

  • Rebuilt the containers with the new docker image
  • Verified that postgres container starts correctly
  • Verified that pg_cron extension exists in the sensors database
  • Verified that the cron schema is created correctly

Inspected following files

  • compose.yaml

    • Indentation/code styling
      • Follows standard
    • Naming convention
      • Follows standard
    • General code quality
      • No issues found
  • DockerCompose/postgres_dockerfile/Dockerfile

    • Indentation/code styling
      + Follows standard
      • Naming convention
        • Follows standard
      • Comments
        • Looks good
      • General code quality
        • pg_cron is installed and configured correctly
  • DockerCompose/init_sql/01-sensors.sql

    • Indentation/code styling
      + Follows standard
      • Naming convention
        • Follows standard
      • General code quality
        • Creates pg_cron extension correctly if it does not already exist
  • DockerCompose/init_sql/03-sensors_cron_jobs.sql

    • Indentation/code styling
      + Follows standard
      • Naming convention
        • Follows standard
      • General code quality
        • No issues found

What needs to be done

  • No issues found

Conclusion

  • Works as intended and the code is ready to be merged.
# Review on #842 ## Whats done ### Tested on macOS + Rebuilt the containers with the new docker image + Verified that postgres container starts correctly + Verified that pg_cron extension exists in the sensors database + Verified that the cron schema is created correctly ### Inspected following files + compose.yaml + Indentation/code styling + Follows standard + Naming convention + Follows standard + General code quality + No issues found + DockerCompose/postgres_dockerfile/Dockerfile + Indentation/code styling + Follows standard + Naming convention + Follows standard + Comments + Looks good + General code quality + pg_cron is installed and configured correctly + DockerCompose/init_sql/01-sensors.sql + Indentation/code styling + Follows standard + Naming convention + Follows standard + General code quality + Creates pg_cron extension correctly if it does not already exist + DockerCompose/init_sql/03-sensors_cron_jobs.sql + Indentation/code styling + Follows standard + Naming convention + Follows standard + General code quality + No issues found ## What needs to be done + No issues found ## Conclusion + Works as intended and the code is ready to be merged.
Collaborator
No description provided.
a22erigr merged commit 6849427e90 into team_2_week_5 2026-05-08 11:15:25 +00:00
a22erigr deleted branch 834-Adding-pg_cron-to-Postgres-Docker-Image 2026-05-11 18:20:27 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K!842
No description provided.