---
title: Index files in PostgreSQL
project: OpenFiles
version: 1.0
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/openfiles/1-0/guides/postgresql/
updated: 2026-11-19T07:45:42.832Z
---

# Index files in PostgreSQL

> Keep a table of all uploaded files in PostgreSQL in addition to the files on disk.

OpenFiles always keeps the files on disk. If you also connect a PostgreSQL database, it writes a row for every upload into a table, and **List of files** reads the list from that table. Use it when you want to query your files with SQL.

## Connect a database

**1.** Create an empty PostgreSQL database for OpenFiles.

**2.** In the OpenFiles folder, install the PostgreSQL driver:

```bash
npm install querybuilderpg
```

**3.** Add the connection to the `config` file:

```text
database              : postgres://user:password@localhost:5432/openfiles
```

**4.** Restart OpenFiles.

On start, OpenFiles creates the table `tbl_file` if it does not exist.

## What changes

- Every upload adds a row with the file ID, storage (`db`), name, extension, type, size, width, height, upload date and the name of the token that uploaded it (`createdby`).
- Renaming and removing a file in [List of files](../browse-files/) also changes or deletes its row.
- **List of files** shows only the files in the table. Files uploaded before you connected the database stay on disk and keep their links, but they do not appear in the list.

To go back, remove the `database` line and restart OpenFiles.
