I have a table like this which stores file operation logs on a computer:
CREATE TABLE tbl_logs_file_ops(
log_id bigserial primary key,
username VARCHAR(255),
computer VARCHAR(255),
activity VARCHAR(255),
is_directory bool,
event_type VARCHAR(255),
src text,
dst text,
event_time timestamp(6));
And I run the following query on it to retrieve the names of the files that are the top 10 most used:
SELECT src, COUNT(src)
FROM tbl_logs_file_ops
GROUP BY src
ORDER BY COUNT(src) DESC
NULLS LAST
LIMIT 10
When I execute this query from pgadmin4 which is running on the same local network as the server where the database is located, it takes about 3 seconds. When I execute the query through an API which is deployed on the same server as the database, it takes about a minute. I initially thought this was a problem with the API but then I executed the same query on the server using psql and it's same.
I've tried disabling ssl from the postgresql.conf file like some other posts were suggesting but nothing changed.