This is a custom Home Assistant add-on that provides:
- β PostgreSQL 17 database
- β Built-in pgvector extension (latest version)
- β Automatic creation of user, database, and extension
- β Optional auto-backup on startup
- β Optional GPG-encrypted backups for secure storage
Designed for use with custom integrations that need vector embedding storage, machine learning metadata, or general PostgreSQL access inside Home Assistant OS (HAOS).
- Runs PostgreSQL 17 inside a secure HAOS-compatible container
- Automatically creates:
- User:
ha_user - Database:
ha_db - Extension:
pgvector
- User:
- Configurable password via add-on UI
- Optional GPG-encrypted backups to
/backupor/share
postgres_pgvector/
βββ Dockerfile # Builds PostgreSQL 17 + pgvector
βββ config.json # HA add-on metadata and options
βββ run.sh # Startup logic and setup automation
βββ postgresql.conf # Listens on all interfaces, socket to /tmp
βββ pg_hba.conf # Password (trust/md5) auth config
The installation of this add-on is pretty straightforward and not different in comparison to installing any other Home Assistant add-on.
-
Click the Home Assistant My button below to add the reposistory to your Assistant instance.
-
Refresh the add-on store to see the add-on and select it.
-
Click the "Install" button to install the add-on.
After installing, go to the Configuration tab and set:
ha_user_password: "<your-secure-password>" # Required, must change from default
auto_backup: true # Optional
backup_encrypt: true # Optional
gpg_recipient: "you@example.com" # Required if encryption is onβ Important: Make sure to start/restart the add-on after changing the password.
In your custom integration:
from sqlalchemy import create_engine
engine = create_engine(
"postgresql+psycopg2://ha_user:<password>@localhost:5432/ha_db"
)To store vector data:
CREATE TABLE embeddings (
id SERIAL PRIMARY KEY,
label TEXT,
embedding VECTOR(512)
);Querying with cosine similarity:
SELECT label
FROM embeddings
ORDER BY embedding <-> '[0.1, 0.2, ...]'
LIMIT 5;To encrypt backups using GPG:
- Set
backup_encrypt: true - Set
gpg_recipientto an imported public key (must be in container or volume) - Add your GPG key via the Terminal add-on:
Encrypted backups will be saved as
gpg --import /path/to/public.key
.sql.gpgfiles in/backup.
- The last 5 backups are kept
- Older ones are automatically deleted on startup
- β Add-on wonβt start: Make sure
ha_user_passwordis not the default. - β Port not exposed: Confirm
"host_network": trueis above"ports": { "5432/tcp": 5432 }. - β TCP connections refused: Ensure
listen_addresses = '*'inpostgresql.confandpg_hba.confallowshost all all 0.0.0.0/0 trust.
MIT License. See LICENSE for details.
PRs and issues are welcome! You can extend this to support:
- Remote database restore
- Scheduled backups
- Multiple database/user support