0

I have a bash script that exports ENV vars to use in connecting to an Azure Postgres DB (mydb.postgres.database.azure.com). For the user portion of that specifically it looks like this:

export PGUSER="postgres@mydb"

This works fine to connect to my local DB where the @mydb part isn't required, but it fails when connecting to Azure (where it is required) with:

psql: FATAL: Invalid Username specified. Please check the Username and retry connection. The Username should be in username@hostname format.

I've found lots of solutions/answers to this like this one and this one however those aren't viable solutions when using ENV vars to set connection details (and while I didn't expect it to work I nonetheless tried changing my script to export PGUSER="postgres%40mydb" and indeed it did yield the same error).

Does anyone know how to accomplish this?

7
  • PGUSER might be superseded. Please show the psql options on the command line and any other detail that might be relevant. Commented Sep 29, 2020 at 14:32
  • @DanielVérité Thanks, I linked to current docs in first sentence of my question. It's still supported, and as mentioned it works fine if there's no @ required in the username. There are no psql options on the command line, that's the point of exporting the env vars. Commented Sep 29, 2020 at 17:05
  • 1
    OK. PostgreSQL as released publicly does not have an error that says The Username should be in username@hostname format, this is an Azure-specific change. You should file a support ticket to Azure for this one. Commented Sep 29, 2020 at 22:28
  • In addition to the mystery of why it does not work on Azure, I guess there is also the mystery of why it does work locally. It certainly doesn't for me I get FATAL: role "postgres@mydb" does not exist. Have you inspected the env to make sure it is actually set the way you think it is? Commented Sep 29, 2020 at 22:28
  • @jjanes I assume the @mydb part of that user identifier is not req'd in your environment, it also is not in mine. It is however required with Azure. Commented Sep 29, 2020 at 23:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.