[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eThis API supports first-generation runtimes and can be used when upgrading to corresponding second-generation runtimes, with a migration guide available for the App Engine Python 3 runtime.\u003c/p\u003e\n"],["\u003cp\u003eNDB, utilizing both Datastore and memcache, prioritizes memcache for read operations, so edits made directly in the Google Cloud console may not be immediately reflected in the application unless memcache is purged or changes are written via NDB.\u003c/p\u003e\n"],["\u003cp\u003eThe metadata query API in \u003ccode\u003egoogle.appengine.ext.ndb.metadata\u003c/code\u003e provides functions like \u003ccode\u003eget_namespaces\u003c/code\u003e, \u003ccode\u003eget_kinds\u003c/code\u003e, \u003ccode\u003eget_properties_of_kind\u003c/code\u003e, and \u003ccode\u003eget_representations_of_kind\u003c/code\u003e to retrieve general information about Datastore usage.\u003c/p\u003e\n"],["\u003cp\u003eDatastore statistics, accessible through the Google Cloud console and programmatically using the \u003ccode\u003egoogle.appengine.ext.ndb.stats\u003c/code\u003e package, offer insights into data storage, entity counts, and space used by property values.\u003c/p\u003e\n"],["\u003cp\u003eDatastore's statistics system progressively drops statistics entities in a specific order, starting with the most granular (per-namespace, per-kind, and per-property) to maintain reasonable storage and update overhead.\u003c/p\u003e\n"]]],[],null,["# NDB Administration\n\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| python3\n|\n| /services/access). If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nThere are tools and APIs to make it easier to administer an application's stored\ndata.\n\nGoogle Cloud console\n--------------------\n\nWhen using the [Google Cloud console](https://console.cloud.google.com/), remember that NDB is implemented by\nmeans of Datastore *and* memcache. When NDB \"reads\" a value, it\nchecks memcache first; it only reads from Datastore if it\ndoesn't find the value in memcache.\n\nThus, if you use the Google Cloud console to edit an entity in\nDatastore, the application might still use the \"old\" value if\nthat value is in memcache. You might work around this by purging memcache. This\nis rather disruptive, however; if you need to tweak values \"by hand\" often, you\nmight want to set up a UI for this in your application that writes values via\nthe NDB client library; writing via NDB keeps Datastore and\nmemcache in sync.\n\nMetadata queries\n----------------\n\nNDB supports a metadata query API. This allows an application to get some\ngeneral information about its use of Datastore. This API is in\nthe [`google.appengine.ext.ndb.metadata`](/appengine/docs/legacy/standard/python/ndb/metadata)\nmodule. It has functions:\n\n- `get_namespaces(`\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None, `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of namespace names\n- `get_kinds(`\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None, `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of kind names\n- `get_properties_of_kind(`\u003cvar translate=\"no\"\u003ekind\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None,\n `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a list of property names for the given *kind* name\n- `get_representations_of_kind(`\u003cvar translate=\"no\"\u003ekind\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003estart\u003c/var\u003e`=None,\n `\u003cvar translate=\"no\"\u003eend\u003c/var\u003e`=None)`: return a dict mapping property names for the given kind name to lists of representation names such as 'STRING', 'BOOLEAN' or 'INT64'.\n\nThese functions have optional *start* and *end* arguments that can be used to\nrestrict the query to a certain range. Here, *start* is inclusive and *end* is\nexclusive. Both default to `None`. For example, to get all namespaces starting\nwith a lowercase letter you could call `get_namespaces('a', chr(ord('z') + 1))`.\nAll of these except `get_namespaces()` are implicitly restricted to the current\nnamespace. Metadata gets and queries are [billed in the same way as\nDatastore gets and queries](/appengine/docs/pricing).\n\nStatistics queries\n------------------\n\nDatastore maintains statistics about the data stored for an\napplication, such as how many entities there are of a given kind, or how much\nspace is used by property values of a given type. You can view these statistics\nin the Google Cloud console, in the\n[Dashboard](https://console.cloud.google.com/datastore/stats) page.\n\nYou can also access these values programmatically within the application by\nquerying for specially named entities using the Datastore API.\nEach statistic is accessible as an entity whose kind name begins and ends with\ntwo underscores. For example, each app has exactly one entity of the kind\n`__Stat_Total__` that represents statistics about all of the entities in\nDatastore in total. Each statistic entity has the following\nproperties:\n\n- `count`, the number of items considered by the statistic (a long integer)\n- `bytes`, the total size of the items for this statistic (a long integer)\n- `timestamp`, the time of the most recent update to the statistic (a date-time value)\n\nSome statistic kinds also have additional properties, listed below.\n\nAn application can use model classes provided by the package\n`google.appengine.ext.ndb.stats` to access statistic entities. \n\n from google.appengine.ext.ndb import stats\n\n global_stat = stats.GlobalStat.query().get()\n print 'Total bytes stored: %d' % global_stat.bytes\n print 'Total entities stored: %d' % global_stat.count\n\nWhen the statistics system creates new statistic entities, it does not delete\nthe old ones right away. The best way to get a consistent view of the\nstatistics is to query for the\n`GlobalStat`\n\nentity with the most recent\n`timestamp`, then use that timestamp value as a filter when fetching other\nstatistic entities.\n\nThe statistic entities are included in the calculated statistic values.\nStatistic entities take up space relative to the number of unique kinds and\nproperty names used by the application.\n\nThe statistics system will also create statistics specific to each\n[namespace](/appengine/docs/legacy/standard/python/multitenancy)\nNote that if an application does not use Datastore namespaces\nthen namespace specific statistics will not be created. Namespace specific stats\nare found in the namespace that they're specific to. The kind names for\nnamespace specific stats are prefixed with `__Stat_Ns_` and have the same\ncorresponding suffix as application wide statistics kinds.\n\nApplications with thousands of namespaces, kinds, or property names require a\nvery large number of statistics entities. To keep the overhead of storing and\nupdating the statistics reasonable, Datastore progressively\ndrops statistics entities, in the following order:\n\n- per-namespace, per-kind, and per-property statistics: `__Stat_Ns_PropertyName_Kind__`, `__Stat_Ns_PropertyType_PropertyName_Kind__`\n- per-kind and per-property statistics: `__Stat_PropertyName_Kind__`, `__Stat_PropertyType_PropertyName_Kind__`\n- per-namespace and per-kind statistics: `__Stat_Ns_Kind__`, `__Stat_Ns_Kind_IsRootEntity__`, `__Stat_Ns_Kind_NotRootEntity__`, `__Stat_Ns_PropertyType_Kind__`\n- per-kind statistics: `__Stat_Kind__`, `__Stat_Kind_IsRootEntity__`, `__Stat_Kind_NotRootEntity__`, `__Stat_PropertyType_Kind__`\n- per-namespace statistics: `__Stat_Namespace__`, `__Stat_Ns_Kind_CompositeIndex__`, `__Stat_Ns_PropertyType__`, `__Stat_Ns_Total__`\n\nThe summary statistics entities (`__Stat_Kind_CompositeIndex__`,\n`__Stat_PropertyType__`, `__Stat_Total__`) are never dropped.\n\nThe complete list of available statistics is as follows:\n\nSome statistics refer to Datastore property value types by\nname, as strings. These names are as follows:\n\n- `\"Blob\"`\n- `\"BlobKey\"`\n- `\"Boolean\"`\n- `\"Category\"`\n- `\"Date/Time\"`\n- `\"Email\"`\n- `\"Float\"`\n- `\"GeoPt\"`\n- `\"IM\"`\n- `\"Integer\"`\n- `\"Key\"`\n- `\"Link\"`\n- `\"NULL\"`\n- `\"PhoneNumber\"`\n- `\"PostalAddress\"`\n- `\"Rating\"`\n- `\"ShortBlob\"`\n- `\"String\"`\n- `\"Text\"`\n- `\"User\"`\n\n| **Note:** `__Stat_Namespace__` entities contain the same information found in `__Stat_Ns_Total__` records. `__Stat_Namespace__` entities are stored in the empty namespace and contain a `subject_namespace` field describing the namespace to which they belong. `__Stat_Ns_Total__` records are stored in the namespace to which they refer, and thus do not contain a `subject_namespace` field. Hence, a query on kind `__Stat_Namespace__` (from the empty string namespace) ordered descending by `bytes` will list the namespaces that consume the largest storage first. Because queries across namespaces are not possible, any query for `__Stat_Ns_Total__` entities will only ever produce at most a single record."]]