Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database: minimize PostgreSQL logs for Django backend #5056

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Aug 9, 2021

Fixes #5055

For the Django backend, we are recording the current version of the
database schema manually in our own DbSetting table. We use this to
determine whether the database schema version is compatible with that of
the code that is installed.

Since the way the version and generation of the schema are stored change
over the years, we had to rely on a try-except method to determine which
way was the case. The original try was for the original way of v0.x of
aiida-core, and if that failed we would fall back to the modern method
of storing the info introduced in aiida-core==1.0. However, each time
the except was hit, meaning a programming error was encountered in the
PostgreSQL statement, a number of warning are logged to PostgreSQL. Not
only can they appear in stdout if no log file has been configed for the
PostgreSQL server (can be the case for conda installations) the log file
will also accumulate these necessary logs, which are produced everytime
the database version is checked, i.e., when a profile is loaded, which
is often.

It might not be trivial to get completely rid of these errors being
logged but we can invert the try-except logic. Assuming that the
majority of users are now on v1.0 or above, they would always be hitting
the except. By first checking for the schema-style of v1.0 instead, only
users of v0.x will be getting the logs, which should be negligible.

@sphuber sphuber requested a review from giovannipizzi August 9, 2021 08:31
@sphuber
Copy link
Contributor Author

sphuber commented Aug 9, 2021

Would be good to try and merge this soon so I can also include this in the v1.6.5 backport release that is planned for tomorrow.

@sphuber sphuber force-pushed the fix/5055/postgresql-schema-check-logs branch from f1d8b77 to 0413555 Compare August 9, 2021 08:55
For the Django backend, we are recording the current version of the
database schema manually in our own `DbSetting` table. We use this to
determine whether the database schema version is compatible with that of
the code that is installed.

Since the way the version and generation of the schema are stored change
over the years, we had to rely on a try-except method to determine which
way was the case. The original try was for the original way of v0.x of
`aiida-core`, and if that failed we would fall back to the modern method
of storing the info introduced in `aiida-core==1.0`. However, each time
the except was hit, meaning a programming error was encountered in the
PostgreSQL statement, a number of warning are logged to PostgreSQL. Not
only can they appear in stdout if no log file has been configed for the
PostgreSQL server (can be the case for conda installations) the log file
will also accumulate these necessary logs, which are produced everytime
the database version is checked, i.e., when a profile is loaded, which
is often.

It might not be trivial to get completely rid of these errors being
logged but we can invert the try-except logic. Assuming that the
majority of users are now on v1.0 or above, they would always be hitting
the except. By first checking for the schema-style of v1.0 instead, only
users of v0.x will be getting the logs, which should be negligible.
@codecov
Copy link

codecov bot commented Aug 9, 2021

Codecov Report

Merging #5056 (8b20f1f) into develop (d92045a) will decrease coverage by 0.02%.
The diff coverage is 57.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5056      +/-   ##
===========================================
- Coverage    80.23%   80.22%   -0.01%     
===========================================
  Files          515      515              
  Lines        36757    36757              
===========================================
- Hits         29490    29485       -5     
- Misses        7267     7272       +5     
Flag Coverage Δ
django 74.71% <57.15%> (-0.01%) ⬇️
sqlalchemy 73.62% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/backends/djsite/manager.py 85.40% <57.15%> (-4.49%) ⬇️
aiida/transports/plugins/local.py 81.41% <0.00%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d92045a...8b20f1f. Read the comment docs.

Copy link
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix!

@sphuber sphuber merged commit 9285245 into aiidateam:develop Aug 9, 2021
@sphuber sphuber deleted the fix/5055/postgresql-schema-check-logs branch August 9, 2021 13:07
sphuber added a commit that referenced this pull request Aug 9, 2021
For the Django backend, we are recording the current version of the
database schema manually in our own `DbSetting` table. We use this to
determine whether the database schema version is compatible with that of
the code that is installed.

Since the way the version and generation of the schema are stored change
over the years, we had to rely on a try-except method to determine which
way was the case. The original try was for the original way of v0.x of
`aiida-core`, and if that failed we would fall back to the modern method
of storing the info introduced in `aiida-core==1.0`. However, each time
the except was hit, meaning a programming error was encountered in the
PostgreSQL statement, a number of warning are logged to PostgreSQL. Not
only can they appear in stdout if no log file has been configured for the
PostgreSQL server (can be the case for conda installations) the log file
will also accumulate these necessary logs, which are produced every time
the database version is checked, i.e., when a profile is loaded, which
is often.

It might not be trivial to get completely rid of these errors being
logged but we can invert the try-except logic. Assuming that the
majority of users are now on v1.0 or above, they would always be hitting
the except. By first checking for the schema-style of v1.0 instead, only
users of v0.x will be getting the logs, which should be negligible.

Cherry-pick: 9285245
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid PSQL errors being logged at every start of AiiDA
2 participants