Skip to content

Conversation

@mmomjian
Copy link
Collaborator

When connecting to psql, it by default connects to a database that matches the username. This works for our standard setup (user=postgres), since the postgres database always exists. However, this is not the case for all users.

Fixes #15227

@mmomjian mmomjian added documentation Improvements or additions to documentation changelog:documentation labels Jan 12, 2025
@bo0tzz
Copy link
Member

bo0tzz commented Jan 12, 2025

Can we just source .env for all of these?

@mmomjian mmomjian marked this pull request as draft January 12, 2025 11:14
@mmomjian
Copy link
Collaborator Author

mmomjian commented Jan 12, 2025

That's a good idea but I tried that, I did some testing on my end, it only works if we wrap it in bash -c which is really ugly. Since we are moving to no .env, we can't interpret it on the host.

I wouldn't feel super confident doing our commands wrapped in bash, especially the restore. Things can get weird.

source, 2

$ docker exec -it immich_postgres psql --username='$POSTGRES_USER' --dbname='$POSTGRES_DB'
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "$POSTGRES_USER" does not exist
$ docker exec -it immich_postgres psql --username='\$POSTGRES_USER' --dbname='$POSTGRES_DB'
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "\$POSTGRES_USER" does not exist
$ docker exec -it immich_postgres psql --username='\\$POSTGRES_USER' --dbname='$POSTGRES_DB'
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "\\$POSTGRES_USER" does not exist
$ docker exec -it immich_postgres psql --username='$${POSTGRES_USER}' --dbname='$POSTGRES_DB'
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "$${POSTGRES_USER}" does not exist
$ docker exec -it immich_postgres psql --username="$${POSTGRES_USER}" --dbname='$POSTGRES_DB'
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  role "65294{POSTGRES_USER}" does not exist
$ docker exec -it immich_postgres bash -c 'psql --username="${POSTGRES_USER}" --dbname="$POSTGRES_DB"'
psql (14.10 (Debian 14.10-1.pgdg120+1))
Type "help" for help.

@mmomjian mmomjian marked this pull request as ready for review January 12, 2025 11:35
@jrasm91 jrasm91 merged commit b74f013 into immich-app:main Jan 14, 2025
33 checks passed
@mmomjian mmomjian deleted the dbname branch January 14, 2025 01:59
arctic-foxtato pushed a commit to arctic-foxtato/immich that referenced this pull request Jan 14, 2025
* cleanup dbname

* 2

* Update database-queries.md

* Update backup-and-restore.md

* Update backup-and-restore.md
vladd11 pushed a commit to vladd11/immich that referenced this pull request Jan 25, 2025
* cleanup dbname

* 2

* Update database-queries.md

* Update backup-and-restore.md

* Update backup-and-restore.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:documentation documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants