self hosting
n8n Postgres Setup: Environment Variables, Permissions, and Queue Mode Readiness
Self-hosted n8n uses SQLite by default, but you can configure Postgres with database environment variables for more production-oriented deployments.
Independent third-party notes. n8n is a trademark of its owner and is referenced only for compatibility and troubleshooting context.
Quick Answer
Self-hosted n8n uses SQLite by default, but you can configure Postgres with database environment variables for more production-oriented deployments.
Problem Pattern
The user wants to move beyond default SQLite or prepare for queue mode and needs a checklist for database settings and operational risk.
Key Facts
- Default database
- Self-hosted n8n uses SQLite unless configured otherwise.
- Postgres enablement
- Set DB_TYPE=postgresdb and the DB_POSTGRESDB_* variables.
- Postgres version
- n8n supports actively maintained PostgresDB versions.
- Permissions
- The n8n database user needs permissions to create and modify schemas and tables.
Recommended Steps
- Create a Postgres database and user for n8n.
- Grant the user enough permissions for n8n to manage its tables.
- Set DB_TYPE=postgresdb.
- Set host, port, database, user, password, and schema variables.
- Start n8n and confirm it connects to Postgres.
Verification
- n8n starts without database connection errors.
- New workflows and credentials persist in Postgres.
- Database logs show successful n8n connections.
Warnings
- Back up SQLite data before migrating an existing instance.
- Do not expose Postgres publicly without network and credential controls.
Best For
- Production-oriented self-hosted deployments.
- Instances preparing for queue mode.
- Teams that want explicit database backup and monitoring workflows.
Not For
- Quick local tests where SQLite is enough.
- Users who cannot administer database credentials, backups, and network access.
- Queue-mode deployments that still plan to use SQLite.
Common Mistakes
- Setting DB_TYPE but missing one of the Postgres connection variables.
- Using a database user with unclear or excessive permissions.
- Migrating without a backup of the current SQLite database.
- Exposing Postgres publicly when only n8n should reach it.
Examples
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=postgres
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=n8n
DB_POSTGRESDB_PASSWORD=change-me
DB_POSTGRESDB_SCHEMA=public Database reachable from n8n container: yes
User can create and modify tables: yes
Backups configured: yes
Restore tested: yes
Network access restricted: yes FAQ
Does n8n require Postgres?
No. Self-hosted n8n can use SQLite by default, but Postgres is usually a better fit for production and queue-mode planning.
Can I switch from SQLite to Postgres later?
Yes, but treat it as a migration. Back up the existing database and test the migration path before changing production.
Should Postgres be on the same VPS?
It can be for small deployments, but production setups should consider backup, monitoring, resource isolation, and access controls.