n8n Workflow Automation
n8n workflow automation platform with PostgreSQL for workflow data persistence.
Overview
n8n is a fair-code workflow automation platform that emerged as a powerful self-hosted alternative to services like Zapier and Microsoft Power Automate. Built with a visual workflow designer, n8n enables users to create complex automation sequences connecting over 350 different services and applications without requiring extensive coding knowledge. The platform supports custom JavaScript nodes, webhook triggers, and advanced error handling, making it suitable for both simple task automation and sophisticated business process workflows.
This stack combines n8n with PostgreSQL to create a production-ready automation platform with persistent data storage. While n8n can operate with SQLite for development, PostgreSQL provides the ACID compliance, concurrent user support, and data integrity required for business-critical workflows. The PostgreSQL backend stores workflow definitions, execution history, credentials, and user data, ensuring that complex automation sequences remain reliable and auditable over time.
This configuration targets organizations and teams seeking workflow automation independence without recurring SaaS fees. DevOps teams can deploy internal automation workflows, marketing departments can orchestrate multi-channel campaigns, and data engineers can build ETL pipelines with visual interfaces. The self-hosted approach provides complete control over sensitive credentials and workflow logic while offering the scalability to handle thousands of workflow executions.
Key Features
- Visual workflow builder with drag-and-drop interface for creating complex automation sequences
- 350+ pre-built integrations including popular services like Slack, GitHub, Google Sheets, and AWS
- Custom JavaScript code nodes for advanced data transformation and business logic
- Webhook endpoints for triggering workflows from external applications and services
- Scheduled workflow execution with cron-like syntax and timezone support
- Comprehensive execution history with detailed logs stored in PostgreSQL
- Credential management system with encrypted storage and team sharing capabilities
- Error handling and retry mechanisms with exponential backoff and custom error workflows
Common Use Cases
- 1DevOps automation for deployment notifications, incident response, and infrastructure monitoring alerts
- 2Marketing automation workflows connecting CRM systems, email platforms, and social media management tools
- 3Data synchronization between business applications like syncing leads from web forms to CRM and project management tools
- 4E-commerce automation for order processing, inventory management, and customer communication workflows
- 5Content management workflows for publishing blog posts, social media updates, and documentation across multiple platforms
- 6IT service management automation for ticket routing, user provisioning, and system health monitoring
- 7Financial data processing including invoice generation, expense tracking, and automated reporting workflows
Prerequisites
- Docker and Docker Compose installed with support for health checks and depends_on conditions
- Minimum 768MB RAM available (256MB for PostgreSQL, 512MB for n8n workflow execution)
- Port 5678 available for n8n web interface access
- Basic understanding of workflow concepts and API integrations for building automation sequences
- Environment variable configuration for database credentials and authentication settings
- SSL/TLS certificate if exposing n8n to external webhook triggers over HTTPS
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 n8n: 3 image: n8nio/n8n:latest4 container_name: n8n5 environment: 6 - N8N_HOST=${N8N_HOST}7 - N8N_PORT=56788 - N8N_PROTOCOL=http9 - NODE_ENV=production10 - WEBHOOK_URL=${WEBHOOK_URL}11 - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}12 - DB_TYPE=postgresdb13 - DB_POSTGRESDB_HOST=postgres14 - DB_POSTGRESDB_PORT=543215 - DB_POSTGRESDB_DATABASE=n8n16 - DB_POSTGRESDB_USER=${POSTGRES_USER}17 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}18 - N8N_BASIC_AUTH_ACTIVE=true19 - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}20 - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}21 ports: 22 - "5678:5678"23 volumes: 24 - n8n_data:/home/node/.n8n25 depends_on: 26 postgres: 27 condition: service_healthy28 networks: 29 - n8n-network3031 postgres: 32 image: postgres:16-alpine33 container_name: n8n-db34 environment: 35 - POSTGRES_USER=${POSTGRES_USER}36 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}37 - POSTGRES_DB=n8n38 volumes: 39 - postgres_data:/var/lib/postgresql/data40 healthcheck: 41 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d n8n"]42 interval: 10s43 timeout: 5s44 retries: 545 networks: 46 - n8n-network4748volumes: 49 n8n_data: 50 postgres_data: 5152networks: 53 n8n-network: 54 driver: bridge.env Template
.env
1# n8n Workflow Automation2N8N_HOST=localhost3WEBHOOK_URL=http://localhost:56784GENERIC_TIMEZONE=UTC5POSTGRES_USER=n8n6POSTGRES_PASSWORD=n8n_password7N8N_BASIC_AUTH_USER=admin8N8N_BASIC_AUTH_PASSWORD=changemeUsage Notes
- 1Editor at http://localhost:5678
- 2400+ integrations available
- 3Self-hosted Zapier alternative
- 4Supports webhooks and schedules
- 5Create custom nodes with JavaScript
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
n8n
n8n:
image: n8nio/n8n:latest
container_name: n8n
environment:
- N8N_HOST=${N8N_HOST}
- N8N_PORT=5678
- N8N_PROTOCOL=http
- NODE_ENV=production
- WEBHOOK_URL=${WEBHOOK_URL}
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
- N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
ports:
- "5678:5678"
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
networks:
- n8n-network
postgres
postgres:
image: postgres:16-alpine
container_name: n8n-db
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=n8n
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test:
- CMD-SHELL
- pg_isready -U ${POSTGRES_USER} -d n8n
interval: 10s
timeout: 5s
retries: 5
networks:
- n8n-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 n8n:5 image: n8nio/n8n:latest6 container_name: n8n7 environment:8 - N8N_HOST=${N8N_HOST}9 - N8N_PORT=567810 - N8N_PROTOCOL=http11 - NODE_ENV=production12 - WEBHOOK_URL=${WEBHOOK_URL}13 - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}14 - DB_TYPE=postgresdb15 - DB_POSTGRESDB_HOST=postgres16 - DB_POSTGRESDB_PORT=543217 - DB_POSTGRESDB_DATABASE=n8n18 - DB_POSTGRESDB_USER=${POSTGRES_USER}19 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}20 - N8N_BASIC_AUTH_ACTIVE=true21 - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}22 - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}23 ports:24 - "5678:5678"25 volumes:26 - n8n_data:/home/node/.n8n27 depends_on:28 postgres:29 condition: service_healthy30 networks:31 - n8n-network3233 postgres:34 image: postgres:16-alpine35 container_name: n8n-db36 environment:37 - POSTGRES_USER=${POSTGRES_USER}38 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}39 - POSTGRES_DB=n8n40 volumes:41 - postgres_data:/var/lib/postgresql/data42 healthcheck:43 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d n8n"]44 interval: 10s45 timeout: 5s46 retries: 547 networks:48 - n8n-network4950volumes:51 n8n_data:52 postgres_data:5354networks:55 n8n-network:56 driver: bridge57EOF5859# 2. Create the .env file60cat > .env << 'EOF'61# n8n Workflow Automation62N8N_HOST=localhost63WEBHOOK_URL=http://localhost:567864GENERIC_TIMEZONE=UTC65POSTGRES_USER=n8n66POSTGRES_PASSWORD=n8n_password67N8N_BASIC_AUTH_USER=admin68N8N_BASIC_AUTH_PASSWORD=changeme69EOF7071# 3. Start the services72docker compose up -d7374# 4. View logs75docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/n8n-workflow-automation/run | bashTroubleshooting
- n8n container fails to start with database connection error: Verify PostgreSQL container is healthy and environment variables DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD match POSTGRES_USER and POSTGRES_PASSWORD
- Workflow executions fail with 'Workflow could not be started' error: Check n8n container logs for memory issues and increase Docker memory allocation if workflows involve large data processing
- Webhooks return 404 or timeout errors: Ensure WEBHOOK_URL environment variable matches your external domain and that firewall rules allow inbound connections to port 5678
- PostgreSQL container exits with permission denied errors: Verify the postgres_data volume has correct ownership or delete the volume to reinitialize with proper permissions
- n8n interface shows 'Cannot connect to database' after restart: Wait for PostgreSQL health check to pass or check if database initialization completed by examining postgres container logs
- Custom nodes fail to load with JavaScript execution errors: Verify NODE_ENV is set to production and check that custom node dependencies are properly installed in the n8n container
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
n8npostgres
Tags
#n8n#automation#workflow#integration#zapier-alternative
Category
Productivity & CollaborationAd Space
Shortcuts: C CopyF FavoriteD Download