Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PGPASSFILE environment variable?

Tags:

postgresql

I am using areca backup program and I wrote a script in it to backup postgre database. I want to get password via pgpass.conf file but I can't give it's path to script. How can I use PGPASSFILE ? This is my script (; is separator) :

-U;postgres;-w;-F;custom;-b;-f;D:\satraAutoBackup\Daily\Saturday\postgresql\geoMolkBackup;geoMolkPortal2
like image 239
Obtice Avatar asked Dec 09 '22 09:12

Obtice


1 Answers

  1. Create .pgpass file with content

    host:5432:somedb:someuser:somepass

  2. set the permissions using command

    sudo chmod 600 .pgpass

  3. Set the file owner as the same user using which you logged in :

    sudo chown login_username:login_username .pgpass

  4. Set PGPASSFILE environment variable :

    export PGPASSFILE='/home/user/.pgpass'

Now check by connecting to database (remove -w) :

psql -h host -U someuser somedb

It will not prompt for password and logged in to postgresql.

like image 156
Shrinivas Avatar answered Dec 14 '22 14:12

Shrinivas