xk6-sql
xk6-sql copied to clipboard
PostgreSQL connection string special character issues
Hi I'm having an issue connecting to a PostgreSQL SB where the password contains special characters.
if my password is abc#123, and I create a connection string like:
postgres://myusername:abc%[email protected]/mydb
where # is escaped to be %23 as required by PostgreSQL. I get the following error when I try to connect:
const db = sql.open('postgres', 'postgres://myusername:abc%[email protected]/mydb');
ERRO[0005] GoError: parse "postgres://myusername:abc%!?(MISSING)[email protected]/mydb": invalid port ":abc%!"(MISSING) after host
How should can I connect to PostgreSQL DBs where a password contains a special character? Please help.
Hi there, thanks for opening the issue.
Hhmm I just tried this, and it seems to work for me.
-
Create Postgres 14.4 container with:
podman run --rm --name postgres -p 127.0.0.1:5432:5432 -e POSTGRES_USER=user -e POSTGRES_PASSWORD='abc#123' postgres:14.4
-
Change the connection string in the
postgres_test.js
example to:const db = sql.open('postgres', 'postgres://user:abc%[email protected]:5432/postgres?sslmode=disable');
-
Run
xk6 run tests/postgres_test.js
and the output is:INFO[0000] key: plugin-name, value: k6-plugin-sql source=console
What's your operating system and version, and the Postgres version you're connecting to?
I think your issue is that you're not specifying the port. Can you give that a try? Actually, it works without a port for me as well... :confused:
@parpera-nathan-liu I found this image, which helped me solve the problem. You need to replace any special character for its correspondent in this table. for example:
raw -> ABCD@123
converted -> ABCD%40123