How can I get the size in bytes of a bound d1 database in a worker?

For Workers & Pages, what is the name of the domain?

General

What is the issue or error you’re encountering

I want to get the size of the bound d1 database in the worker.

What steps have you taken to resolve the issue?

I have tried the following query

SELECT page_count * page_size as database_size
FROM pragma_page_count(), pragma_page_size();

This results in not authorized: SQLITE_AUTH

Should be databaseSizeBytes :thinking:

Haven’t tried yet and not quite sure if that’s available already.

I figured this out. The database size is available on the D1Response object meta data from the workers api as the size_after property. Return objects · Cloudflare D1 docs. This looks like it is a little simpler to wire up than the GraphQL api’s, at least for my use case. Thanks for your help.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.