> ${LOG_FIL...">
Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

How to use psql with no psql password prompt?

Asked by Buffy Heaton Mar 13, 2023 2.8K views 1 answer
Share

About this question

 I wrote a script to REINDEX indexes in a database. Here is one of them:

echo -e "nreindex for unq_vbvdata_vehicle started at: `date "+%F %T"`" >> ${LOG_FILE}
psql -U ${USERNAME} -h ${HOSTNAME} -d ${DBNAME} -c "REINDEX INDEX scm_main.unq_vbvdata_vehicle;"
if [[ ${?} -eq 0 ]]; then
    echo "reindex for unq_vbvdata_vehicle finished at: `date "+%F %T"`" >> ${LOG_FILE}
else
    echo "reindex for unq_vbvdata_vehicle failed" >> ${LOG_FILE}
    exit 1

fi

The problem is I can not run this script in standalone mode. psql is prompting password every time it runs. There is also two limitations:


I can not create a user on a database with no password.


Because REINDEX locks tables, I should use sleep  between each REINDEX.

Is there any automatic solution?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.