How to Recreate n8n Database
This guide explains how to completely reset an n8n instance to a fresh state by recreating its PostgreSQL database. This procedure removes all data (workflows, credentials, users, execution history) and resets the service as if it were newly installed, without requiring full reinstallation of the n8n service itself.
Before you begin, ensure you have:
- SSH access to the server running the n8n instance
- Administrative privileges (sudo access)
- Database credentials from the n8n configuration
⚠️ WARNING: This procedure will permanently delete ALL n8n data including workflows, credentials, users, and execution history.
First, stop the n8n service to prevent it from accessing the database during recreation:
sudo systemctl stop n8n
sudo systemctl status n8n # Verify it's stopped
Locate the database configuration in the n8n environment file:
cat /home/webapp/.n8n/.env
Look for these database configuration variables:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=n8n
DB_USER=n8n
DB_PASSWORD=your_database_password
DB_SCHEMA=public
Note down these values as you’ll need them for the database operations.
Connect to PostgreSQL as the postgres superuser:
sudo -u postgres psqlList databases:
\l Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges -----------+----------+----------+-----------------+---------+---------+------------+-----------+----------------------- n8n | n8n | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =Tc/n8n +Drop the existing n8n database:
DROP DATABASE n8n;Recreate the empty database:
CREATE DATABASE n8n OWNER n8n;Grant necessary privileges:
GRANT ALL PRIVILEGES ON DATABASE n8n TO n8n;Exit PostgreSQL:
\q
Remove n8n’s local configuration files to ensure a clean start:
# Remove the config file (will be recreated on startup)
rm -f /home/webapp/.n8n/config
# Optional: Remove logs if you want a completely clean slate
rm -f /home/webapp/.n8n/*.log
Start the n8n service. It will automatically initialize the empty database with the default schema:
sudo systemctl start n8n
sudo systemctl status n8n # Check that it's running correctly
Check service logs to ensure successful startup:
sudo journalctl -u n8n -n 50 -fLook for messages indicating successful database connection and schema creation.
Access the n8n web interface and verify it shows the initial setup screen for creating the first admin user.
After the database recreation, you’ll need to:
- Access the n8n web interface (typically at the server’s IP address or configured domain)
- Create the first admin user through the setup wizard
- Configure basic settings as needed for your environment
This procedure provides a clean reset of your n8n instance by:
- Stopping the n8n service
- Dropping and recreating the PostgreSQL database
- Cleaning configuration files
- Restarting the service for fresh initialization
The result is an n8n instance in the same state as a fresh installation, ready for initial setup and configuration.
