Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL connection string special character issues #21

Open
ghost opened this issue Jul 7, 2022 · 2 comments
Open

PostgreSQL connection string special character issues #21

ghost opened this issue Jul 7, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 7, 2022

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.

@imiric
Copy link
Contributor

imiric commented Jul 7, 2022

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... 😕

@lucass4
Copy link

lucass4 commented Jul 27, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants