[[["容易理解","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-05 (世界標準時間)。"],[],[],null,["# Accelerate database performance using disk cache\n\nSelect a documentation version: 15.12.0keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/configure-disk-cache)\n- [16.8.0](/alloydb/omni/16.8.0/docs/configure-disk-cache)\n- [16.3.0](/alloydb/omni/16.3.0/docs/configure-disk-cache)\n- [15.12.0](/alloydb/omni/15.12.0/docs/configure-disk-cache)\n- [15.7.1](/alloydb/omni/15.7.1/docs/configure-disk-cache)\n- [15.7.0](/alloydb/omni/15.7.0/docs/configure-disk-cache)\n\n\u003cbr /\u003e\n\nThis page describes how to provision, set up, and use disk caching on AlloyDB Omni to increase performance of your AlloyDB Omni installation.\n\n\u003cbr /\u003e\n\nIn addition to the standard PostgreSQL in-memory shared buffers, AlloyDB Omni disk cache enables storing buffers on fast storage such as solid-state drives (SSDs). Disk caching accelerates data retrieval in AlloyDB Omni installations with data directories located on slower storage.\n\nLike PostgreSQL shared buffers, AlloyDB Omni disk cache is non-persistent, which means cached data is lost on restart.\n\nBy default, AlloyDB Omni disk cache uses all storage reported by the file system. You can define the amount of storage reserved for caching data using the `omni_disk_cache_file_size` parameter.\n\nEnable the AlloyDB Omni disk cache\n----------------------------------\n\nTo enable disk cache for AlloyDB Omni in a container, follow these steps.\n\n### Provision disks and create a file system\n\nFor AlloyDB Omni disk cache, you create a file system on a disk or multiple disks and mount it inside a container with AlloyDB Omni. Additionally, you can use utilities like `mdadm` or `lvm` to pool capacity together using multiple disks and use any file system.\n\nThe following steps demonstrate using `lvm` and `ext4` on a Ubuntu Compute Engine instance using NVMe SSDs.\n\n1. Create a volume group from all available physical devices:\n\n ```bash\n nvme_prefix=\"\u003cvar translate=\"no\"\u003eSTORAGE_PREFIX\u003c/var\u003e\"\n nvme_list=$(ls \"$nvme_prefix\"*)\n sudo vgcreate VOLUME_GROUP ${nvme_list}\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eSTORAGE_PREFIX\u003c/var\u003e: the prefix of the target local disks path that are attached to a virtual machine using the nonvolatile memory express (NVMe) interface---for example, on Google Cloud, the NVMe device paths always start with `/dev/nvme0n`.\n - \u003cvar translate=\"no\"\u003eVOLUME_GROUP\u003c/var\u003e: the name of a volume group where your SSDs are combined---for example, `omni-disk-cache-volume`.\n2. To create a logical volume from the free capacity of the volume group from the preceding step, use the following command:\n\n ```bash\n sudo lvcreate -n LOGICAL_VOLUME -l 100%FREE VOLUME_GROUP\n ```\n\n Replace \u003cvar translate=\"no\"\u003eLOGICAL_VOLUME\u003c/var\u003e with the name of a logical volume that is treated as a partition by the LVM---for example, `omni_disk_cache_device`.\n3. Create the `ext4` file system on the logical volume. If needed, you can specify other `ext4` options subject to data safety. \n\n ```bash\n sudo mkfs.ext4 /dev/VOLUME_GROUP/LOGICAL_VOLUME\n ```\n4. To create a directory that serves as a mount point on the host machine and mount the file system, use the following command:\n\n ```bash\n sudo mkdir /OMNI_DISK_CACHE_DIRECTORY\n sudo mount /dev/VOLUME_GROUP/LOGICAL_VOLUME /OMNI_DISK_CACHE_DIRECTORY\n ```\n\n Replace \u003cvar translate=\"no\"\u003eOMNI_DISK_CACHE_DIRECTORY\u003c/var\u003e with the name of the directory or a path to the directory serving as a mount point---for example, `omni_disk_cache_directory`.\n\n### Mount the cache directory inside AlloyDB Omni\n\nBefore you enable disk cache for AlloyDB Omni running in a container, you must mount the cache directory inside AlloyDB Omni.\n\nFor information about installing AlloyDB Omni from a [Docker image](https://registry.hub.docker.com/r/google/alloydbomni) and customizing it, see [Customize your AlloyDB Omni installation](/alloydb/omni/15.12.0/docs/install).\n\nTo mount the \u003cvar translate=\"no\"\u003eOMNI_DISK_CACHE_DIRECTORY\u003c/var\u003e inside your Docker container running AlloyDB Omni, use the following command:\n\n### Docker\n\n```bash\n sudo docker run --name CONTAINER_NAME \n\n -e POSTGRES_PASSWORD=PASSWORD \n\n -e PGDATA=/var/lib/postgresql/data/pgdata \n\n -v DATA_DIR:/var/lib/postgresql/data \n\n -v /OMNI_DISK_CACHE_DIRECTORY:/CACHE_DIRECTORY_PATH_INSIDE_CONTAINER \n\n -d google/alloydbomni\n \n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e: the name to assign the new AlloyDB Omni container---for example, `my-omni`.\n- \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: the password for your PostgreSQL database root administrator.\n- \u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e: the file system path that you want AlloyDB Omni to use for its data directory.\n- \u003cvar translate=\"no\"\u003eCACHE_DIRECTORY_PATH_INSIDE_CONTAINER\u003c/var\u003e: the cache directory inside the AlloyDB Omni container that maps to the mount point on the host machine---for example, based on the value of the cache directory inside the container, either `/omni_disk_cache_directory`, similar to \u003cvar translate=\"no\"\u003eOMNI_DISK_CACHE_DIRECTORY\u003c/var\u003e, or `/disk/cache/inside/container`.\n\n### Podman\n\n```bash\n podman run --name CONTAINER_NAME \n\n -e POSTGRES_PASSWORD=PASSWORD \n\n -e PGDATA=/var/lib/postgresql/data/pgdata \n\n -v DATA_DIR:/var/lib/postgresql/data \n\n -v /OMNI_DISK_CACHE_DIRECTORY:/CACHE_DIRECTORY_PATH_INSIDE_CONTAINER \n\n -d docker.io/google/alloydbomni\n \n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e: the name to assign the new AlloyDB Omni container---for example, `my-omni`.\n- \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: the password for your PostgreSQL database root administrator.\n- \u003cvar translate=\"no\"\u003eCACHE_DIRECTORY_PATH_INSIDE_CONTAINER\u003c/var\u003e: the cache directory inside the AlloyDB Omni container that maps to the mount point on the host machine---for example, based on the value of the cache directory inside the container, either `/omni_disk_cache_directory`, similar to \u003cvar translate=\"no\"\u003eOMNI_DISK_CACHE_DIRECTORY\u003c/var\u003e, or `/disk/cache/inside/container`.\n\nTo grant full access permissions to the mounted \u003cvar translate=\"no\"\u003eOMNI_DISK_CACHE_DIRECTORY\u003c/var\u003e, use the following commands:\n\n### Docker\n\n```bash\n sudo docker exec -it CONTAINER_NAME chown postgres:postgres /CACHE_DIRECTORY_PATH_INSIDE_CONTAINER\n sudo docker exec -it CONTAINER_NAME chmod -R a+rw /CACHE_DIRECTORY_PATH_INSIDE_CONTAINER\n \n```\n\n### Podman\n\n```bash\n sudo podman exec -it CONTAINER_NAME chown postgres:postgres /CACHE_DIRECTORY_PATH_INSIDE_CONTAINER\n sudo podman exec -it CONTAINER_NAME chmod -R a+rw /CACHE_DIRECTORY_PATH_INSIDE_CONTAINER\n \n```\n\n### Enable the AlloyDB Omni disk cache\n\nTo enable AlloyDB Omni disk cache for your database, set the appropriate Grand Unified Configuration (GUC) parameters after you make sure that the mounted cache directory is accessible from inside the Docker container.\n\n1. To connect to the containerized AlloyDB Omni database as a superuser, use the following command:\n\n ### Docker\n\n ```bash\n sudo docker exec -it CONTAINER_NAME psql -h localhost -U postgres\n \n ```\n\n ### Podman\n\n ```bash\n sudo podman exec -it CONTAINER_NAME psql -h localhost -U postgres\n \n ```\n2. To set the value of the parameters, use the following commands inside the AlloyDB Omni database:\n\n ```sql\n alter system set omni_disk_cache_enabled=on;\n alter system set omni_disk_cache_directory='/\u003cvar translate=\"no\"\u003eCACHE_DIRECTORY_PATH_INSIDE_CONTAINER\u003c/var\u003e';\n \n ```\n3. By default, AlloyDB Omni uses all available space in the file system. You can override the default value using the `omni_disk_cache_file_size` parameter if needed.\n\n ```sql\n alter system set omni_disk_cache_file_size=SIZE_IN_MB;\n \n ```\n4. For the caching configuration parameters change to take effect, restart your running container with AlloyDB Omni:\n\n ### Docker\n\n ```bash\n sudo docker restart CONTAINER_NAME\n \n ```\n\n ### Podman\n\n ```bash\n sudo podman restart CONTAINER_NAME\n \n ```\n\n\u003cbr /\u003e\n\nVerify the disk cache configuration\n-----------------------------------\n\nAfter you enable the AlloyDB Omni disk cache, verify that the disk\ncache is accessed by monitoring read and write activity to the disks using\nutilities like `iotop` or `iostat`.\n\nAdditionally, you can check if the AlloyDB Omni disk cache is open.\n\nTo verify the disk cache configuration for AlloyDB Omni in a container,\nfollow these steps: \n\n### Docker\n\n sudo docker logs \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e 2\u003e&1 | grep \"opened omni disk cache\"\n\n### Podman\n\n sudo podman logs \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e 2\u003e&1 | grep \"opened omni disk cache\"\n\nIf your disk caching is configured correctly, the\n`Successfully opened omni disk cache ...` message displays in the logs.\n\nWhat's next\n-----------\n\n- [About automatic memory management](/alloydb/omni/15.12.0/docs/automatic-memory-management)\n- [About local SSD disks](/compute/docs/disks/local-ssd)\n- [Creating and starting a VM instance](/compute/docs/instances/create-start-instance)"]]