Google Professional Cloud Database Engineer Question 195
Select 2Google Cloud PlatformYou are managing a Cloud SQL database running PostgreSQL, and you notice that query performance has degraded over time. Upon investigation, you suspect table fragmentation is impacting performance. Which of the following steps should you take to assess and address table fragmentation?
- A
Use the
pg_stat_user_tablessystem view to check thedead_tuplescolumn for a high count. - B
Run the
ANALYZEcommand to immediately reduce fragmentation in the affected table. - C
Use the
pgstattupleextension to calculate the live tuple percentage and evaluate table bloat. - D
Check the size of indexes with the
pg_indexes_size()function to identify fragmentation issues. - E
Run the
VACUUM FULLcommand to rebuild the table and remove fragmentation.
Show answer and explanation
Correct answers: A, C
Explanation
Table fragmentation in PostgreSQL can result in degraded query performance due to an increase in dead tuples and bloat. To assess fragmentation, you should monitor the dead_tuples column in the pg_stat_user_tables system view and use tools like the pgstattuple extension to calculate the live tuple percentage and table bloat. These methods allow you to determine whether fragmentation is an issue before taking corrective actions such as VACUUM FULL or ANALYZE.
- A. Correct.
Correct: The
pg_stat_user_tablesview provides information about dead tuples in a table, which is a strong indicator of table fragmentation. A high count of dead tuples suggests the need for action. - B. Incorrect.
Incorrect: The
ANALYZEcommand collects statistics for the query planner but does not reduce fragmentation or address dead tuples. - C. Correct.
Correct: The
pgstattupleextension can be used to assess table fragmentation by calculating the percentage of live tuples and identifying table bloat. - D. Incorrect.
Incorrect: The
pg_indexes_size()function measures the size of indexes but does not directly relate to assessing table fragmentation. - E. Incorrect.
Incorrect: While
VACUUM FULLcan reduce table fragmentation, this is an action step, not a method for assessing fragmentation.