Database Environment Variables

Ever wondered how to make your self-hosted n8n setup not just functional but optimized and secure? Well, buckle up, because we’re diving into the world of database configuration using environment variables. And trust me, this isn’t just another tech tutorial. It’s your ticket to making your n8n instance run like a well-oiled machine. So, whether you’re a seasoned pro or just starting out, you’re in the right place. Let’s get into it.

Understanding Environment Variables for Database Configuration in n8n

So, what’s the deal with environment variables? Simply put, they’re your secret weapon for configuring databases in n8n without hardcoding sensitive info into your app. This means you can switch up your database settings on the fly without touching your codebase. Pretty cool, right?

Here’s the kicker: n8n supports both SQLite and PostgreSQL. By default, it rolls with SQLite, but if you’re looking to step up your game, PostgreSQL’s got you covered. And with environment variables, setting up either one is a breeze.

Configuring SQLite with Environment Variables

Let’s start with SQLite, the default choice for n8n. It’s simple, it’s efficient, and with the right environment variables, you can tweak it to perfection. Here are the key variables you need to know:

  • DB_TYPE/_FILE: This one’s crucial. It tells n8n which database to use. For SQLite, you’ll set this to ‘sqlite’.
  • DB_SQLITE_POOL_SIZE: Wanna control how SQLite handles connections? This variable’s your go-to. It’s set to 0 by default, but you can adjust it based on your needs.
  • DB_SQLITE_VACUUM_ON_STARTUP: Ever heard of database bloat? This variable helps keep your SQLite database lean and mean by running a vacuum operation on startup.

Now, here’s a pro tip: you can add ‘_FILE’ to any of these variables to load their values from a separate file. It’s a neat way to keep your config clean and secure.

Setting Up PostgreSQL with Environment Variables

Alright, let’s level up to PostgreSQL. It’s a bit more complex, but don’t worry, we’ve got you covered. Here are the environment variables you’ll need to get PostgreSQL humming along with your n8n instance:

  • DB_POSTGRESDB_DATABASE/_FILE: Name your database. It’s ‘n8n’ by default, but feel free to get creative.
  • DB_POSTGRESDB_HOST/_FILE: Where’s your PostgreSQL server chilling? Set this to ‘localhost’ or your server’s IP.
  • DB_POSTGRESDB_PORT/_FILE: Default’s 5432, but you can change it if you’re feeling wild.
  • DB_POSTGRESDB_USER/_FILE: Who’s got the keys to the castle? Set your PostgreSQL user here.
  • DB_POSTGRESDB_PASSWORD/_FILE: Keep it safe. This is where you set your password.
  • DB_POSTGRESDB_POOL_SIZE/_FILE: Control those connections. Default’s 2, but you can scale up.
  • DB_POSTGRESDB_CONNECTION_TIMEOUT/_FILE: How long should n8n wait to connect? It’s 20000ms by default.
  • DB_POSTGRESDB_SCHEMA/_FILE: ‘public’ by default, but you can switch it up.
  • DB_POSTGRESDB_SSL_ENABLED/_FILE: Wanna add an extra layer of security? Enable SSL here.
  • DB_POSTGRESDB_SSL_CA/_FILE, DB_POSTGRESDB_SSL_CERT/_FILE, DB_POSTGRESDB_SSL_KEY/_FILE: These are for your SSL certificates and keys. Keep ’em secure.
  • DB_POSTGRESDB_SSL_REJECT_UNAUTHORIZED/_FILE: Should n8n reject unauthorized SSL connections? It’s true by default, but you can flip it if needed.

See? Not so scary, right? With these environment variables, you can fine-tune your PostgreSQL setup to fit your needs like a glove.

Why Use Environment Variables?

Wondering why you should bother with environment variables? Here’s why: they keep your sensitive info out of your codebase, making it easier to manage different environments (like dev, staging, and prod) without changing your code. Plus, they make your setup more flexible and secure. It’s a win-win.

Final Thoughts

So, there you have it. Configuring your database with environment variables in n8n isn’t just about getting things to work. It’s about making your setup optimized, secure, and flexible. Whether you’re sticking with SQLite or stepping up to PostgreSQL, these variables are your key to a smoother, more efficient n8n experience.

Ready to take your n8n game to the next level? Dive into our other resources and start optimizing your setup today. Trust me, your future self will thank you.

Share it :

Sign up for a free n8n cloud account

Other glossary

Emelia Trigger Node

Discover how to integrate the Emelia Trigger node into your n8n workflows with technical guides and examples for cold-emailing.

SEO

Learn essential SEO strategies to enhance your website’s visibility and drive free, high-quality organic traffic from search engines.

Wekan Credentials

Learn how to use Wekan credentials in n8n for seamless workflow automation. Set up basic auth with your Wekan username, password, and URL.

AI Agent Node

Explore AI Agent node integration in n8n. Learn about six LangChain agents, tools, and resources for workflow automation.

Server Setups

Explore server setups with Docker Compose, Kubernetes, and other platforms. Get started with n8n’s configuration guides.

Merge

Learn to use n8n’s Merge node to combine data from multiple streams with various modes like Append, Combine, and SQL Query.

Ad

Bạn cần đồng hành và cùng bạn phát triển Kinh doanh

Liên hệ ngay tới Luân và chúng tôi sẽ hỗ trợ Quý khách kết nối tới các chuyên gia am hiểu lĩnh vực của bạn nhất nhé! 🔥