HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

check history along with dates for queries in Postgres

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgreshistorywithqueriesdatesforalongcheck

Problem

I am running PostgreSQL on my Linux terminal and If we do select pg_backend_pid(); it gives pid for specific session.

Below gives us only the last query executed

select pid,
       usename as username,
       datname as database_name,
       query,
       application_name,
       backend_start,
       state,
       state_change
from pg_stat_activity
where pid = 'your-pid';


but looks like this \s gives us all the history of query but not with dates. can we get dates along with them

and if we do save output to a filename where does it gets stored on Linux server?

\s filename


Kindly suggest if there are more specific way, actually I am looking for the queries executed on particular date.

Solution

PostgreSQL doesn't remember the times when queries are run.

If you need that information, set log_statement = 'all' and include %m in log_line_prefix. Then the queries and their time are written to the log file.

Context

StackExchange Database Administrators Q#280464, answer score: 5

Revisions (0)

No revisions yet.