xk6-sql icon indicating copy to clipboard operation
xk6-sql copied to clipboard

PostgreSQL connection string special character issues

Open ghost opened this issue 2 years ago • 2 comments

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.

ghost avatar Jul 07 '22 00:07 ghost

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%[email protected]: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:

imiric avatar Jul 07 '22 08:07 imiric

@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

lucass4 avatar Jul 27 '23 14:07 lucass4