Auditing BigQuery User Query Counts
Your BigQuery project has several users. For audit purposes, you need to see how many queries each user ran in the last month. What should you do?
Community Insight
The question tests the distinction between querying operational metadata for immediate data access versus using centralized audit logs for compliance and historical auditing.
This page clarifies how to audit BigQuery usage by identifying the correct method to count queries per user over a specific period, establishing that Cloud Audit Logging is the standard solution.
Many learners choose Option B because INFORMATION_SCHEMA.JOBS views are excellent for real-time monitoring, but they often lack the retention and security guarantees required for formal audit trails compared to Cloud Audit Logs.
Community Discussion (135 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Cloud Audit Logging (Option D) is the definitive tool for auditing administrative and data access activities in Google Cloud. BigQuery automatically sends audit logs to Cloud Logging, allowing you to filter for specific query operations and aggregate counts by user identity over time. This approach provides a secure, immutable record suitable for compliance.Why the Other Options Are Wrong
Option A relies on Data Studio, which is a visualization layer dependent on underlying data sources; it does not inherently provide an audit log mechanism. Option B suggests querying the JOBS table directly; while INFORMATION_SCHEMA.JOBS_BY_USER is useful for current or recent job visibility, it is not designed as a long-term audit trail and may be subject to retention limits. Option C involves command-line tools likebq ls and bq show, which are interactive and not scalable for monthly aggregation across many users.Community Comment Notes
The community was split between Option B and D. Several commenters argued that INFORMATION_SCHEMA is 'more efficient' for getting query counts, noting that it is a built-in feature for monitoring. However, others pointed out that Cloud Audit Logs are specifically designed for 'audit purposes' and provide a broader view of activity including permissions and system events, making D the more robust answer for compliance scenarios.Official Reference
Exam Strategy
When a question specifies 'audit purposes' or 'compliance', prioritize solutions that involve centralized logging (like Cloud Audit Logs or Stackdriver) over direct database queries, as audit logs are immutable and retained for longer periods.
Frequently Asked Questions
Why is INFORMATION_SCHEMA.JOBS_BY_USER not the best choice for auditing?
While useful for monitoring, INFORMATION_SCHEMA tables are not retained as long as audit logs and are not considered an immutable audit trail for compliance.
Can I use bq ls to count monthly queries per user?
No, bq ls lists jobs interactively and is not practical for aggregating historical data across multiple users and months programmatically.
Related Analysis
Practice All PCA Questions
Access 81 questions with complete answers and detailed explanations.
View Full PCA Practice Test →
region-eu.INFORMATION_SCHEMA.JOBS WHERE creation_time BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 45 DAY) AND CURRENT_TIMESTAMP() AND job_type = 'QUERY' group by user_email, CAST(creation_time as DATE)