Gaurav Rajput Gaurav Rajput - 2 months ago 21
Bash Question

How to fire VACUUM command using shell script in postgres

Here is my shell script

#!/bin/bash
psql --host=127.0.0.1 --port=5432 --dbname=SIEM --username=dbauser
vacuumdb --analyze --verbose --table 'vuln' SIEM


but its not working fine and gives error as:

linux-lxh4:/home/gaurav # ./script.sh
psql (9.2.5)
Type "help" for help.

SIEM=# \q
vacuumdb: could not connect to database root: FATAL: Peer authentication failed for user "root"


Edit1:I used this code :

psql --host=127.0.0.1 --port=5432 --dbname=SIEM --username=dbauser
VACUUM FULL VERBOSE vuln


And here is error:

./script.sh: line 4: VACUUM: command not found

Answer

From Postgres VACUUM documentation

the administrative command is called vacuum not vacuumdb.

I don't have a psql here but it should be

#!/bin/bash
psql --host=127.0.0.1 --port=5432 --dbname=SIEM --username=dbauser
-c 'VACUUM VERBOSE ANALYZE vuln'
Comments