Windows PSQL command line: is there a way to allow for passwordless login?

后端 未结 6 1680
星月不相逢
星月不相逢 2020-12-13 07:30

My goal is to be able to fire off a command without having to be prompted for my password. Is there any way to achieve this from the windows command line? In Linux I feel I

6条回答
  •  粉色の甜心
    2020-12-13 07:48

    I know it is an old question but for anyone looking like I was, it is hard to find a solution for windows. stick this in a .bat file and it will work (at least for me it did). change director to postres directory, set environment variable PGPASSWORD execute copy command to a csv file and then clear environment variable, then go back to root directory.

    cd C:\Program Files\PostgreSQL\9.5\bin\
    
    set PGPASSWORD=yourpassword
    
    
    psql -d databasename -U yourusername -w -c "\COPY (select * from yourtable) TO 'c:/Users/yourdirectory/yourcsvfilename.csv' DELIMITER '|' CSV HEADER;"
    
    set PGPASSWORD=
    
    cd c:\
    

提交回复
热议问题