Vauxoo / odoo

Fork of Odoo (formerly OpenERP). [This project is not publically mantained just born for internal usage with some little patches] go to official repository on github.com/odoo/odoo
https://www.odoo.com
Other
9 stars 9 forks source link

sql_db: Add odoo pid to connection in application_name #475

Open moylop260 opened 2 years ago

moylop260 commented 2 years ago

Backport from

It helps to debug queries executed in postgresql from Odoo in order to know where they were called

Enabling the postgresql logs with the following log_line_prefix

log_line_prefix='%t [%p]: [%l-1] db=%d,user=%u,client=%h,app=%a '

You will see the following output in the postgresql.log:

... UTC [394452]: [371-1] db=odoo,user=odoo,client=127.0.0.1,app=odoo-740755 LOG:  00000: duration: 0.074 ms  statement: SELECT 1

Notice app=odoo-740755 it is the odoo pid that executed the query and the postgresql PID ... UTC [394452]:

Then you will be able to match the odoo.log and postgresql.log using the PIDs

740755 DEBUG odoo odoo.sql_db.connection: ConnectionPool(used=1/count=2/max=64) Create new connection backend PID 394452
740755 INFO odoo odoo.addons: Running SELECT 1

Notice the Odoo PID 740755 INFO and the postgresql PID backend pid 394452

Note: It will require enable the sub-logger

It will helps to debug what process is executing each query in the database or if a postgressql PID is showing a error log related to connection (not even from a query)

e.g. The livechat stuck and you don't know what happen but you can see the postgresql.log the following message for the same PostgreSQL backend_pid related to longpolling odoo pid

[394452]: [371-2] db=odoo,user=odoo,client=127.0.0.1,app=odoo-740755 LOG:  XX00: Could not receive data from client: Connection time out

Signed-off-by: Moises Lopez - https://www.vauxoo.com/ moylop260@vauxoo.com

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:

-- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr