Using PGFS with local file storage

PGFS supports the server's local native file system. Access is governed by the OS permissions of the Postgres process.

Configuring local file system access

You can manage how the PGFS interacts with your local data with the pgfs.allowed_local_fs_paths configuration setting.

By default, PGFS is only able to access files in /tmp/pgfs of the local filesystem. This setting is a security measure to prevent the extension from accessing files it shouldn't.

To allow PGFS to access files in other locations, add those locations to the pgfs.allowed_local_fs_paths GUC. This parameter accepts a colon-separated list of file system paths that PGFS is allowed to access.

Possible valuesDescription
'/tmp/pgfs'The default location for PGFS to access files.
'/tmp/pgfs:/tmp/other'PGFS is able to access files in both /tmp/pgfs and /tmp/other.
'/'PGFS is able to access all files on the system. This setting is not recommended.
''PGFS is not able to access any local files.

Use the Postgres SET command to change the setting. For example, to allow PGFS to access files in /tmp/pgfs and /tmp/other:

SET pgfs.allowed_local_fs_paths = '/tmp/pgfs:/tmp/other';

Configuring local storage

To register a local directory as a storage backend, use the file: prefix in the URL. This tells PGFS to interact with the server's native filesystem. Note that the PostgreSQL process must have the necessary OS-level read/write permissions for the specified path.

Syntax

SELECT pgfs.create_storage_location(
    'storage_location_name',
    'file:///path_to_directory',
    '{"create_dir": true | false}' --optional: default is false
);
  • Paths must always be absolute. For example, start at the root directory /. Together with the protocol prefix file://, this means your path will have three slashes as in the example below.

  • Any local path that you want to access must be listed in the pgfs.allowed_local_fs_paths configuration setting.

  • Make sure to end your path with a / as in the examples below. This is required for path concatenation and validation with AIDB volumes.

Examples

This example shows how to create a storage location with local file system storage:

SELECT pgfs.create_storage_location(
    'local_images',
    'file:///var/lib/edb/pipelines/images/'
       );

Could this page be better? Report a problem or suggest an addition!