首页 > 解决方案 > 如何获取 postgres 游标的执行时间(python)

问题描述

我想在得到结果后获取光标的执行时间,基本上需要在 postgres sql 中执行查询,并在我的日志中记录在 postgres sql server 端执行查询所花费的时间。

试图实现这样的事情:

import psycopg2
import pandas as pd

conn = psycopg2.connect(host="localhost",database="shrek", user="postgres", password="apple")
print(conn)
cur = conn.cursor()
abc =cur.execute('select id from company')
result = cur.fetchone()
print(result[0])
print(cur.fetchtime())-------> i want to print the execution time

标签: pythonpostgresqlpsycopg2

解决方案


推荐阅读