How to use special characters in PostgreSQL password for Ledger
Last updated: February 21, 2025
When configuring the PostgreSQL connection string (POSTGRES_URI) for Ledger, you may encounter issues if your password contains special characters. This article explains how to properly format the connection string to avoid errors.
Problem
If your PostgreSQL password contains special characters, such as '#', you might receive an error similar to:
Error: failed to parse dsn: cannot parse `postgresql://ledger:xxxxxx@postgres:5432/ledger?sslmode=disable`: failed to parse as URL (invalid port ":password" after host)
exit status 1Solution
To resolve this issue, you need to percent-encode special characters in your password. Here's how to do it:
Identify special characters in your password that need encoding.
Replace these characters with their percent-encoded equivalents.
Use the encoded password in your POSTGRES_URI.
Common character encodings
Character Encoded value | |
# | %23 |
@ | %40 |
: | %3A |
/ | %2F |
Example
If your password is "password#", your POSTGRES_URI should look like this:
POSTGRES_URI: "postgresql://ledger:password#postgres:5432/ledger?sslmode=disable"Note
Remember to include the port number if it's not the default (5432). For example:
POSTGRES_URI: "postgresql://ledger:password%23postgres:5432/ledger?sslmode=disable"By properly encoding special characters in your password, you ensure that the URI parser interprets your connection string correctly, avoiding errors when deploying Ledger.