Thiago, o Firebird
assim como em outros bancos possui tabelas internas para controles, através destas tabelas internas você consegue pegar as informações de conexões, transações e comandos executados, etc.
Utilize o seguinte select
para pegar a informação que deseja e muito mais.
select
A.MON$ATTACHMENT_ID as "Attachment ID",
A.MON$SERVER_PID as "Server PID",
A.MON$STATE as "State",
A.MON$ATTACHMENT_NAME as "Attachment Name",
A.MON$USER as "User",
A.MON$ROLE as "Role",
A.MON$REMOTE_PROTOCOL as "Remote Protocol",
A.MON$REMOTE_ADDRESS as "Remote Address",
A.MON$REMOTE_PID as "Remote PID",
CS.RDB$CHARACTER_SET_NAME as "Character Set",
A.MON$TIMESTAMP as "Established At",
A.MON$GARBAGE_COLLECTION as "Garbage Collection",
A.MON$REMOTE_PROCESS as "Remote Process",
A.MON$STAT_ID as "Statistics ID",
ST.MON$STATEMENT_ID as "Statement ID",
ST.MON$TRANSACTION_ID "Transaction ID",
case
when ST.MON$STATE = 0
then
'IDLE'
when ST.MON$STATE = 1
then
'ACTIVE'
end as "State",
ST.MON$TIMESTAMP "Started At",
ST.MON$SQL_TEXT "Statement Text",
R.MON$RECORD_SEQ_READS as "Non-indexed Reads",
R.MON$RECORD_IDX_READS as "Indexed Reads",
R.MON$RECORD_INSERTS as "Records Inserted",
R.MON$RECORD_UPDATES as "Records Updated",
R.MON$RECORD_DELETES as "Records Deleted",
R.MON$RECORD_BACKOUTS as "Records Backed Out",
R.MON$RECORD_PURGES as "Records Purged",
R.MON$RECORD_EXPUNGES as "Records Expunged",
IO.MON$PAGE_READS as "Page Reads",
IO.MON$PAGE_WRITES as "Page Writes",
IO.MON$PAGE_FETCHES as "Page Fetches",
IO.MON$PAGE_MARKS as "Page Marks"
from
MON$ATTACHMENTS A
join MON$STATEMENTS ST on ST.MON$ATTACHMENT_ID = A.MON$ATTACHMENT_ID
join RDB$CHARACTER_SETS CS on (A.MON$CHARACTER_SET_ID = CS.RDB$CHARACTER_SET_ID)
left join MON$RECORD_STATS R on (A.MON$STAT_ID = R.MON$STAT_ID)
left join MON$IO_STATS IO on (A.MON$STAT_ID = IO.MON$STAT_ID)
where
upper(ST.MON$SQL_TEXT) like upper(:PSQL) -- Comando SQL que deseja encontrar
and
ST.MON$STATE = 1 -- Para somente conexões ativas
No parâmetro do select
você pode informar um SQL completo ou apenas uma parte.
Exemplo: ST.MON$SQL_TEXT like '%USUARIO%'
ou ST.MON$SQL_TEXT like 'select * from usuario where id =1'
.
O campo "Remote Address" é o IP da conexão que executou.
Agora se você estiver usando a ferramenta IBExpert
você pode acessar o menu superior em Services > Database Monitoring, por lá consegue consultar essas informações e ainda derrubar uma determinada conexão.