googleapis / java-spanner-jdbc

Apache License 2.0
61 stars 48 forks source link

Get the size of the database #634

Open MikielAgutu opened 2 years ago

MikielAgutu commented 2 years ago

Is your feature request related to a problem? Please describe. I'd like to be able to determine the size of a Spanner database.

Describe the solution you'd like Some kind of API in the JDBC driver that returns the size of the database.

Describe alternatives you've considered We've tried querying the information schema to get the list of tables, then trying to figure out the data usage of each field in every table. However this is not performant, and error prone.

Additional context n/a

olavloite commented 2 years ago

The difficult part of implementing this is that the gRPC API does not include any method that returns the size of a database. The Database message for example does not include a size property: https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.database.v1#database

As far as I can tell, the only way of getting this for the JDBC driver would be to query the instance/storage/used_bytes metric in Cloud Monitoring, but that would only be possible when the Cloud Monitoring API is enabled and accessible for the credentials that are used for the JDBC driver.