Emit error if pg_ivm is not in session/shared_preload_libraries#120
Emit error if pg_ivm is not in session/shared_preload_libraries#120adamguo0 wants to merge 9 commits intosraoss:mainfrom
Conversation
|
Thank you for your proposal. |
|
Thanks for taking a look! I looked and could not find an equivalent to If I understand correctly, |
|
If we have to allow user to load the module by session_preload_libraries, that check may be useful. However, I don't feel the necessity and requiring to use shared_preload_libraries seems simple solution with lesser code-maintenance cost. |
|
Hmm I think allowing users to load pg_ivm in session_preload_libraries can be quite helpful since it does not require them to restart Postgres in order to use pg_ivm. I will look for a cleaner solution here |
|
Hi @yugo-n, I agree that the WARNINGs are somewhat overkill and required a lot of extra C code to implement. I decided to remove the WARNINGs and just keep the ERRORs in the SQL installation scripts. This significantly reduces the size of this change. Hope you can take another look, thanks! |
|
I'm sorry for late reply. |
IMO this is a good thing, since after all pg_ivm requires users to set session_preload_libraries or shared_preload_libraries in order to use the extension properly. Otherwise, I can see users missing that warning in the documentation and making a mistake in their deployment, which may result in an inconsistent I think it's a fairly common requirement, e.g. pgaudit. pg_stat_statements uses a slightly different approach where _PG_init doesn't check for shared_preload_libraries but each function checks separately. |
However, even if we check it at installation, the configuration can be changed afterward and we don't prevent it completely.
I prefer this approach to checking in a installation/update script if we would save careless users. |
|
I think making |
|
Hi @yugo-n, what if we provide an explicit |
|
What about other callback functions registered by RegisterXactCallback etc. in Pg_init ? |
|
The PG_init function is called once Postgres calls the IMMV trigger functions. I did a quick test where pg_ivm is not preloaded, and the xact/subxact callbacks are still triggered. So currently I think only the object access hook requires SPL (though there may be further requirements in the future). |
|
I have been looking at the patch series posted here, at the request of Adam, and I have to say that the "warnings" branch posted is an incremental mess, TBH. The patch is not organized, and the tests are IMO bloated. And nothing proposed in the patch set is actually doing something about the fact that the restriction about session_preload_libraries and shared_preload_libraries should be enforced when a backend starts. For example, taking a diff with a rebased "warnings" branch and branch "main" at 96fdf6f: The only restriction you have put in place results in a weird state, where one would only detect the problem when running in CREATE EXTENSION. This does not take care of the problem where the extension is created, and the server is restarted. The moral of the story is that you have to include a restriction of some kind in _PG_init(), which is the path that backends take, or you will never be able to make the drops safe as the library needs to be loaded. Side note 1: there is no need for pg_ivm--1.10.sql, only the upgrade scripts are OK so that's one duplication less. So, Nagata-san, I'd suggest to make things depend on shared_preload_libraries with a simple check in _PG_init(), like pgaudit, and call it a day. I don't see an express need for tests. |
re #119
Since pg_ivm registers hooks and transaction callbacks, it needs to be loaded in session_preload_libraries or shared_preload_libraries. However, even if pg_ivm is not preloaded, a user can still use the extension like normal. The hooks will just be silently ignored, which can cause the metadata table to go out of sync.
This PR throws an error if the user tries to
CREATE EXTENSION pg_ivmbut pg_ivm is not in the preload libraries. It also emits warnings when the pg_ivm SQL functions or triggers are used but pg_ivm is not in preload libraries.A new SQL test file is added for this functionality.