Description
I've been playing around with the idea of "plugins", extendible "things" we can inject at any point in the client/server lifecycle to do stuff. A few ideas I've prototyped so far:
table_access
: block queries made against configured tables; Postgres permissions only allow so much, e.g. we can't block access to the system catalog without breaking the database.intercept
: capture a client query and return a fake result instead of going to the Postgres server; not entirely sure how this can be used, but seemed like a fun idea to play around with.query_logger
: log all queries to stdout, great for debugging applicationsprewarmer
: run a query on server startup to perform some kind of task that will pre-warm the connection for the client.
These are not prescriptive in any way, and only serve to illustrate the use case behind plugins. PgBouncer had a patch that allowed query rewriting 1, we could introduce that as a plugin as well.
Another interesting discussion topic is how to load/configure these plugins. The way it's done now is plugins are part of the code and are turned on and configured via pgcat.toml. This is not really a plugin system though, since real plugins have to extend the existing code base & be completely optional. Another use case is for projects to add functionality to pgcat that they may not want open sourced (yet, or ever) without having to fork. A plugin could be a great way for someone to introduce a functionality that's specific to their organization/project and dynamically load it, without worrying about maintaining a fork and git conflicts down the line.
What would be great to get out of this RFC is:
- Some kind of interface for plugins, so they can be loaded and used in different parts of the client/server lifecycle, e.g. pre-query, after-query, pre-connect, after-connect, etc. So we need to define a lifecycle "policy" and allow to inject the plugin at any of those points.
- A way to dynamically (or statically) load the plugins at either compile time or runtime, whichever is best from a safety, performance and ergonomic perspectives.
- Anything missing from above.