grafana / xk6-sql

k6 extension to load test RDBMSs (PostgreSQL, MySQL, MS SQL and SQLite3)
Apache License 2.0
107 stars 57 forks source link

PostgreSQL connection string special character issues #21

Open ghost opened 2 years ago

ghost commented 2 years ago

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%23123@db.host/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%23123@db.host/mydb');

ERRO[0005] GoError: parse "postgres://myusername:abc%!?(MISSING)k@db.host/mydb": invalid port ":abc%!"(MISSING) after host

How should can I connect to PostgreSQL DBs where a password contains a special character? Please help.

imiric commented 2 years ago

Hi there, thanks for opening the issue.

Hhmm I just tried this, and it seems to work for me.

  1. 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
  2. Change the connection string in the postgres_test.js example to:

    const db = sql.open('postgres', 'postgres://user:abc%23123@127.0.0.1:5432/postgres?sslmode=disable');
  3. 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:

lucass4 commented 1 year ago

@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

image