Recently I came to a new challenge to understand a new ERP system and the tables involved when different business functions are taking place. I need to find the tables involved by each function. For example, if we have a vehicle purchase, we need to identify table that this function has inserted/updated data.
In SQL Server we had the SQL Server profiler, so we could start recording, perform the action and then stop the recording. All activities were listed and with some simple or complex filters we could find out those tables.
*Note than I am not interested into SQL Execution plan where tables shown are involved into a single query, but instead to a group of functions/queries/tables.
Is there any similar tool in PostgreSQL?
2
Answers
So I did a quick research and I developed a quick solution using PostgreSQL internal tables. Maybe is not has graphical representation with table visualizer and start or stop capabilities but, it does the job.
First create a new table, to store some metadata:
Then execute a function of operation to stamp access statistics before and after the business workflow:
Then execute a function of operation to track the statistic changes between iterations of start and stop (before and after) workflow.
To call the operate and track:
The outcome of the last functions if there are inserts, updates or deletes:
There is no easy way to do this. You could create a test database and proceed as follows for each function:
revoke all privileges on all tables
run a function call
look at the permission denied error you get and grant the required privilege
repeat until the function runs as desired