{"id":16561246,"url":"https://github.com/blckbx/lnd_postgres","last_synced_at":"2025-10-28T23:30:32.380Z","repository":{"id":43769519,"uuid":"484692520","full_name":"blckbx/lnd_postgres","owner":"blckbx","description":"⚡ Guide: How to setup LND with PostgreSQL DB","archived":false,"fork":false,"pushed_at":"2023-11-09T16:24:35.000Z","size":48,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-01T19:02:07.060Z","etag":null,"topics":["lightning","lnd","postgres","postgresql"],"latest_commit_sha":null,"homepage":"https://blckbx.github.io/lnd_postgres","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blckbx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-23T08:39:13.000Z","updated_at":"2024-10-24T07:03:06.000Z","dependencies_parsed_at":"2023-11-09T17:43:14.372Z","dependency_job_id":null,"html_url":"https://github.com/blckbx/lnd_postgres","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blckbx%2Flnd_postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blckbx%2Flnd_postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blckbx%2Flnd_postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blckbx%2Flnd_postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blckbx","download_url":"https://codeload.github.com/blckbx/lnd_postgres/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238737842,"owners_count":19522263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["lightning","lnd","postgres","postgresql"],"created_at":"2024-10-11T20:32:15.106Z","updated_at":"2025-10-28T23:30:27.064Z","avatar_url":"https://github.com/blckbx.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚡ Guide: How to setup LND with PostgreSQL\n\n\n## 📄 Prelude and Objective\n\nA short guide on how to setup and configure a **_new_** lightning node using LND with recently released PostgreSQL support as database backend. The  approach was done by creating a new lightning node. To date, backend data migrations are still being developed. A brief write-up for PostgreSQL support was released by Lightning Labs here: [postgres.md](https://github.com/lightningnetwork/lnd/blob/master/docs/postgres.md). Nevertheless it lacks important parts which this guide wants to cover step by step.\n\n## 📜 Table of Content\n\n- [Preconditions](#-preconditions)\n- [Install and setup PostgreSQL](#-install-and-setup-postgresql)\n- [Configure LND](#-configure-lnd)\n- [Upgrade PostgreSQL](#-upgrade-postgresql)\n- [Addendum](#-addendum)\n\n\n## 🔎 Preconditions\n\nThe guide is based on the following setup and components. It may be different for Umbrel / Raspiblitz / MyNode installations as it was established on a bolt / bare metal setup running Ubuntu.\n\n- OS: Ubuntu 22.04\n- Setup: bare metal / [bolt setup](https://raspibolt.org/)\n- Lightning Implementation: [lnd-0.14.3-beta +](https://github.com/lightningnetwork/lnd/releases/tag/v0.14.3-beta)\n- Database Backend: PostgreSQL 14.2 or latest version in ubuntu's repository\n- **node state: new node without funds and channels (⚠)**\n\nIt's important to emphasize that this setup is built as a new lightning node without existing funds or channels. As said, data migrations between different backends (bbolt, postgres, etcd) are not yet supported (as of v0.14.3).\n\n## 🛠 Install and setup PostgreSQL\n\nInstallation process of LND is omitted in this guide as this is widely described on the internet. So I assume a valid installation here and continue to setup the backend:\n\n```sh\n# Install postgresql-14 \n$ sudo apt install postgresql-14\n\n# Configure postgresql to your needs (port, datadir, logging, etc.) or use default values.\n$ sudo nano /etc/postgresql/14/main/postgresql.conf\n\n# Setup postgres user\n$ sudo -i -u postgres\n$ psql\n\npostgres=# \\password\n# Enter password and take note of it!\n\n# Quit PSQL\n\\q\n```\n\nCreate user and database for LND:\n\n```sh\n# As postgres user\n$ sudo -i -u postgres\n\n# Create user 'lnd' and set a password\n$ createuser --createdb --pwprompt lnd\n# Enter password and take note of it!\n\n# Create database 'lndb' \n$ createdb -O lnd lndb\n\n# Exit user postgres\n$ exit\n```\n\n## 🛠 Configure LND\n\nConfigure your `lnd.conf`:\n\n```sh\n$ sudo nano /home/lnd/.lnd/lnd.conf\n```\n\nEdit and add your postgresql config and credentials, like so: `postgresql://\u003cuser\u003e:\u003cpw\u003e@\u003cip\u003e:\u003cport\u003e/\u003cdb\u003e`\n\n```ini\n[db]\ndb.backend=postgres\n\n[postgres]\ndb.postgres.dsn=postgresql://lnd:password@127.0.0.1:5432/lndb?sslmode=disable\ndb.postgres.timeout=0\n```\n\nAdd postgres as a requirement to LND's systemd service:\n```sh\n[Unit]\nDescription=...\nRequires=postgresql@.service bitcoind.service\nAfter=postgresql@.service bitcoind.service\n```\n\nIf everything went fine, you can see this in the `lnd.log`:\n```\n[INF] LTND: Opening the main database, this might take a few minutes...\n[INF] LTND: Using remote postgres database! Creating graph and channel state DB instances\n```\n\n## ♻ Upgrade PostgreSQL\n  \nUpgrading PostgreSQL should be easy using Postgres' own tool `pg_upgrade`. Install and setup next version in parallel. Upgrade to new datadir, dry-run before doing the command (`--check` = dry-run) from v13 to v14:\n\n```\n/usr/lib/postgresql/14/bin/pg_upgrade \\\n  --old-datadir=/var/lib/postgresql/13/main \\\n  --new-datadir=/var/lib/postgresql/14/main \\\n  --old-bindir=/usr/lib/postgresql/13/bin \\\n  --new-bindir=/usr/lib/postgresql/14/bin \\\n  --old-options '-c config_file=/etc/postgresql/13/main/postgresql.conf' \\\n  --new-options '-c config_file=/etc/postgresql/14/main/postgresql.conf' \\\n  --check\n```\nFor more details on this topic, see link in addendum part below. \n\n## ✴ Addendum\n  \n- [System optimization for Postgres](https://pgtune.leopard.in.ua)\n- [Upgrading PostgreSQL 13 to 14](https://www.kostolansky.sk/posts/upgrading-to-postgresql-14/)\n- [Advanced setup with replication (two instances)](https://github.com/gabridome/docs/blob/master/c-lightning_with_postgresql_reliability.md)\n- [Future data migration between backends](https://github.com/lightningnetwork/lnd/blob/7702c90503abf88011e3d436f52926f2a5aa32a7/docs/data-migration.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblckbx%2Flnd_postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblckbx%2Flnd_postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblckbx%2Flnd_postgres/lists"}