The pg_stat_activity view shows the executing queries in AnalyticDB for PostgreSQL. Each row contains a server process and its associated session and query. Unless the stats_command_string parameter is set to disable data collection, this information is collected from the current query. This information is visible only to superusers and the user to which the reported process belongs.

The maximum length of the string in the current_query column can be set by using the pgstat_track_activity_query_size parameter.

Column Type Description
datid oid The OID of the database, which can be obtained from the pg_database view.
datname name The name of the database.
pid integer The ID of the process.
sess_id integer The ID of the session.
usesysid oid The ID of the role, which can be obtained from the pg_authid view.
usename name The name of the role.
current_query text The query that is executed in the process.
waiting boolean Indicates whether the process is waiting for a lock. Valid values: true and false.
query_start timestamptz The time when the query starts to be executed.
backend_start timestamptz The start time of the backend process.
client_addr inet The IP address of the client.
client_port integer The port number of the client.
applicaton_name text The name of the application on the client.
xact_start timestamptz The start time of the transaction.
waiting_reason text The reason why the process is waiting for a lock.

You can execute the following statement to find the queries that were initiated by the odps_in user within the last 30 minutes but have not been completed:

select * from pg_stat_activity where xact_start < now() - interval '30 min' and waiting='f' and usename='odps_in';