How to specify a user to perform the dump of a postgresql database?

is it possible to specify a username with password in the /usr/local/etc/urbackup/postgresqldump.conf file?

this possibility is proposed in /usr/local/etc/urbackup/mariadbdump.conf:

#!/bin/sh
MARIADB_DUMP_ENABLED=0
MARIADB_BACKUP_USER=root
MARIADB_BACKUP_PASSWORD=foobar
MARIADB_DUMP=mysqldump

but i cant find anything regarding postgresql … yet when using docker containers we often need to specify the user who is allowed to connect to the postgresql server.

Thanks in advance.

Documentation for pg_dump here:
PostgreSQL: Documentation: 14: 26.1. SQL Dump

Excerpt:

Like any other PostgreSQL client application, pg_dump will by default connect with the database user name that is equal to the current operating system user name. To override this, either specify the -U option or set the environment variable PGUSER . Remember that pg_dump connections are subject to the normal client authentication mechanisms (which are described in Chapter 21).

Don’t know how helpful that’ll be, personally I found Chapter 21 a tad impenetrable.

thank you very much for your suggestion, it’s a good idea … but so far it’s not working.
the file .pgpass is used by postgresql to retrieve the password of the user specified in the psql command line.

Suppose you have this .pgpass file:

# hostname:port:database:username:password
localhost:5432:cargos:cargos:cargos

you can connect to the postgresql server with the following command:

root:~ # psql cargos -h localhost -U cargos
psql (11.14 (Debian 11.14-0+deb10u1), serveur 11.7 (Debian 11.7-2.pgdg100+1))
Connexion SSL (protocole : TLSv1.3, chiffrement : TLS_AES_256_GCM_SHA384, bits : 256, compression : désactivé)
Saisissez « help » pour l'aide.
cargos=# \q

but if you do not specify the user, the connection fails:

root:~ # psql cargos
psql: could not connect to the server: No such file or folder
Is the server locally active and accepting connections on the socket Unix « /var/run/postgresql/.s.PGSQL.5432 » ?

root@cargos-mshe:~ # psql cargos -h localhost
Mot de passe pour l'utilisateur root : 

it should be necessary to modify the pg_hba.conf file of the Docker container … except that a container should not be modified.

for now, as I cannot use UrBackup to back up a Docker container database, I am using the container
docker-pg-backup to back up the data to the host.

it is indeed very simple to provide an identifier to the container to perform the data dump.

dbbackups:
  image: kartoza/pg-backup:11.0
  volumes:
    - /srv/dbbackups:/backups
  environment:
    - DUMPPREFIX=cargos
    - POSTGRES_HOST=database
    - POSTGRES_USER=cargos
    - POSTGRES_PASS=cargos
    - POSTGRES_PORT=5432
  restart: on-failure
  depends_on:
    - database
  networks:
    - my-network

in this way, the data will therefore be backed up in fine by UrBackup.
but I still take a backup of the postgresql data directly by Urbackup!

Thanks in advance,

Ernest.