How can I log queries for each (or specific) user in a separate file in PostgreSQL?

I have a database and I want to share it with multiple users who should be able to execute some queries, but I need to control them. I know I can enable all logs, but in this case, I will also log application user logs, which will contain millions.

+3


source to share


1 answer


The answer will completely depend on the platform you are using. You need a type of environment in which each request is executed and / or communicated along with the connection context.

For example, in NodeJS, if you are using node-postgres , you have access to an object client

along with every request made, and that object has all the connection details, including the username.



You will need to solve this problem for a specific database + development environment + database. Without these 3 variables, it is known that there can be no answer.

The only alternative is when the database is fully accessible through functions that add functionality to log every request detail against the current username. But for starters, this is not a very good architecture.

0


source







All Articles