2

Hello expert I want to refresh materialized view in postgresql via batch file. I don't have any idea how to connect postgresql database via batch file. I have to run following query via batch file - "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view"

Stream
  • 89
  • 1
  • 9

1 Answers1

3

Update: based on comments, filled in all the parameters required to connect to a database "planet" with user, port and password information. The quotes are really for the shell, for easy replacement.

You can do this with psql.

psql -Upostgres -p5432 -c "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view" planet

and put that in the batch file or script or whatever.

With this in your ~/.pgpass file:

localhost:5432:planet:postgres:pes

or variants thereof. You can also use

*:*:*:postgres:pes
Johann Oskarsson
  • 776
  • 6
  • 15
  • I need the full answer with example. how to connect with database. – Stream Nov 23 '17 at 05:47
  • 1
    This is the full example. On my machine this works `psql -c "select version()"` You can add `--host=hostname`, `--port=portnum`, `--username=username` and `dbname` as standalone parameter. Put your psasword in `~/.pgpass`. – Johann Oskarsson Nov 23 '17 at 06:13
  • If you don't mind i need the complete script for batch file example- i have a database "planet", user="postgres", password="pes", port="5432" and i want to run "REFRESH MATERIALIZED VIEW deposit.mv_transaction_view" query. – Stream Nov 23 '17 at 09:17
  • 2
    Stack overflow is not an excuse not to read the manual. However, I'll update the answer. – Johann Oskarsson Nov 23 '17 at 12:28
  • 1
    @JharanaGharti: https://stackoverflow.com/questions/15359348/run-batch-file-with-psql-command-without-password and https://stackoverflow.com/q/6405127/330315 –  Nov 25 '17 at 07:09