Full n8n workflow canvas.
This detailed guide provides everything you need to set up and use the n8n Tweet Management Workflow with PostgreSQL, a robust automation tool for managing tweets. Designed for social media managers, developers, and automation enthusiasts, this workflow streamlines tweet scheduling and storage with intuitive forms and PostgreSQL integration. The guide covers standalone and containerized setups, an optional backup system, usage instructions, and troubleshooting tips to ensure a smooth experience.
The n8n Tweet Management Workflow with PostgreSQL offers:
This workflow is ideal for automating repetitive tasks, maintaining data consistency, and creating a reliable tweet archive.
tweets_table
containing:
id
(integer, primary key), tweet_date
(date), parent_tweet_id
(integer), text
(text)This section provides multiple installation options to accommodate your environment.
Ideal for users running n8n directly on their machine without containers.
node --version
npm --version
npm install n8n -g
n8n start
http://localhost:5678
.tweet_db
):
CREATE DATABASE tweet_db;
tweets_table
:
CREATE TABLE tweets_table (
id INTEGER PRIMARY KEY,
tweet_date DATE,
parent_tweet_id INTEGER,
text TEXT
);
Uses Docker for a portable, isolated environment, suitable for production or testing.
docker --version
docker-compose.yml
file:
version: '3'
services:
n8n:
image: n8nio/n8n:latest
ports:
- '5678:5678'
volumes:
- n8n_data:/home/node/.n8n
environment:
- N8N_HOST=localhost
- N8N_PORT=5678
postgres:
image: postgres:14
environment:
- POSTGRES_DB=tweet_db
- POSTGRES_USER=your_user
- POSTGRES_PASSWORD=your_secure_password
volumes:
- postgres_data:/var/lib/postgresql/data
ports:
- '5432:5432'
volumes:
n8n_data:
postgres_data:
docker-compose up -d
http://localhost:5678
.docker exec -it <postgres_container_name> psql -U your_user -d tweet_db
tweets_table
:
CREATE TABLE tweets_table (
id INTEGER PRIMARY KEY,
tweet_date DATE,
parent_tweet_id INTEGER,
text TEXT
);
This setup includes n8n, PostgreSQL, and a backup service for data protection. Replace placeholders with your values.
version: '3.8'
services:
postgres:
image: postgres:latest
container_name: postgres
restart: unless-stopped
environment:
POSTGRES_USER: your_user
POSTGRES_PASSWORD: your_secure_password
POSTGRES_DB: tweet_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- n8n-network
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
environment:
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: postgres
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: tweet_db
DB_POSTGRESDB_USER: your_user
DB_POSTGRESDB_PASSWORD: your_secure_password
N8N_HOST: localhost
N8N_PORT: 5678
WEBHOOK_URL: http://localhost:5678/
ports:
- '5678:5678'
depends_on:
- postgres
volumes:
- n8n_data:/home/node/.n8n
- /path/to/your/desktop:/desktop
networks:
- n8n-network
backup:
image: ubuntu
container_name: backup
volumes:
- postgres_data:/data/postgres
- n8n_data:/data/n8n
- /path/to/backup/folder:/backup
entrypoint: /backup/backup.sh
networks:
- n8n-network
volumes:
postgres_data:
n8n_data:
networks:
n8n-network:
Steps:
docker-compose.yml
./path/to/your/desktop
with a local folder for file access in the n8n container./path/to/backup/folder
with a local directory for backups.backup.sh
script in the backup folder: (Bonus)
#!/bin/bash
BACKUP_DIR="/backup"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
N8N_BACKUP_FILE="n8n_backup_$TIMESTAMP.tar"
tar -cvf "$BACKUP_DIR/$N8N_BACKUP_FILE" /data/n8n
POSTGRES_BACKUP_FILE="postgres_backup_$TIMESTAMP.tar"
tar -cvf "$BACKUP_DIR/$POSTGRES_BACKUP_FILE" /data/postgres
cd "$BACKUP_DIR"
ls -1 n8n_backup_*.tar | sort -r | tail -n +3 | xargs -r rm -f
ls -1 postgres_backup_*.tar | sort -r | tail -n +3 | xargs -r rm -f
chmod +x /path/to/backup/folder/backup.sh
docker-compose up -d
.tar
files.
Screenshot: Docker Compose terminal showing n8n, PostgreSQL, and backup services running.
http://localhost:5678
.workflow.json
from your purchase package.
Screenshot: n8n import/export menu with workflow.json
selected for import.
postgres
(Docker) or localhost
(standalone)tweet_db
your_user
your_secure_password
5432
Execute a SQL query
and Insert_row_to_Tweet_table
nodes.
Screenshot: PostgreSQL credentials configured in n8n with correct host, database, user, password, and port.
The backup system ensures your data is safe and recoverable.
Backups protect against:
The backup service uses an Ubuntu container to:
/data/n8n
directory (workflows, credentials) to a .tar
file (e.g., n8n_backup_20250708_152700.tar
)./data/postgres
directory (database files) to a .tar
file (e.g., postgres_backup_20250708_152700.tar
).backup.sh
to add a loop (e.g., while true; do ...; sleep 86400; done
for daily).Backups are stored in the folder mapped to /path/to/backup/folder
. Monitor storage to avoid disk issues.
To restore:
docker-compose down
tar -xvf /path/to/backup/folder/postgres_backup_20250708_152700.tar -C /tmp/postgres_restore
docker cp /tmp/postgres_restore/. <postgres_container_name>:/var/lib/postgresql/data
tar -xvf /path/to/backup/folder/n8n_backup_20250708_152700.tar -C /tmp/n8n_restore
docker cp /tmp/n8n_restore/. <n8n_container_name>:/home/node/.n8n
docker-compose up -d
This screenshot shows the backup folder with .tar
files, confirming successful creation of n8n and PostgreSQL backups.
first_input
, retry date
):
2025-07-08
)first_input
, Retry_Parent_Tweet_ID
):
1
for reply to tweet ID 1)0
for standalone tweet0
Tweet_Form
):
first_input
node’s webhook URL.tweets_table
:
SELECT * FROM tweets_table ORDER BY id DESC LIMIT 1;
This screenshot shows the first_input
form in a browser, confirming the fields for entering date and parent tweet index.
Screenshot of the Tweet Form in a browser. Submitting saves the tweet to the database.
first_input
form in browser.tweets_table
in pgAdmin/psql..tar
files.workflow.json
.backup.sh
is executable, folder is writable.