pgfs is a FUSE based filesystem which is backed by a postgres table, with a bytea field as the file. The filesystem is configured with a simple toml file:

mountpoint = "/home/paul/pgfs"

[database]

database = "127.0.0.1/pgfstest"
user = "user"
pass = "pass"

[filestest]

table_name = "files"
data_type = "bytea"
id_field = "id"
length_field = "length"
data_field = "file"
created_date_field = "created"
modified_date_field = "modified"
data_query = "select id, name,  octet_length(file) as length, created, modified from files"
readonly = false

if you then create a table files:

create table files (
    id serial primary key,
    name varchar,
    created timestamp default now(),
    modified timestamp,
    file bytea
);

Running pgfs with the specified config will present you with a filesystem at /home/paul/pgfs which contains a single folder “files”. Inside that folder, there will be one file per record in the files table. You can modify files, add them (creates a new record), or delete them. It’s not very fast (FUSE uses 4k writes and postgres isn’t optimised for seeking inside a bytea field), but it works. On my linux box, vim works on text files just fine, and drag and drop, renaming, thumbnails, copy & paste etc all work fine in nautilus.

I built this mostly for fun (to see if I could get it to work), but for some small projects I store files as bytea fields for convenience so it’s useful.

I plan to add a few niceties, one which would make it a lot more useful would be to allow paths to show up as links, so if you don’t store bytea files (which I wouldn’t typically do either), but store paths to files outside the database, you can have a filesystem created with those links in. Presenting a table as a delimited text file you can edit as a file would also be neat.

The code is on Github, and it’s published to crates.io, so you can install with

cargo install pgfs

I wrote most of this code back in 2021, but am trying to tidy up and publish a few utilities I’ve created over the years in the coming months.

Thanks for reading