PostgreSQL - query from bash script as database user 'postgres'

后端 未结 8 1158
[愿得一人]
[愿得一人] 2020-12-22 19:22

I have a table in my PostgreSQL database which has 3 columns - c_uid, c_defaults and c_settings. c_uid simply stores the

8条回答
  •  离开以前
    2020-12-22 19:42

    To ans to @Jason 's question, in my bash script, I've dome something like this (for my purpose):

    dbPass='xxxxxxxx'
    .....
    ## Connect to the DB
    PGPASSWORD=${dbPass} psql -h ${dbHost} -U ${myUsr} -d ${myRdb} -P pager=on --set AUTOCOMMIT=off
    

    The another way of doing it is:

    psql --set AUTOCOMMIT=off --set ON_ERROR_STOP=on -P pager=on \
         postgresql://${myUsr}:${dbPass}@${dbHost}/${myRdb}
    

    but you have to be very careful about the password: I couldn't make a password with a ' and/or a : to work in that way. So gave up in the end.

    -S

提交回复
热议问题