Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reindex Postgres 9.1.3 from the command line

I have a series of deletes and updates on a few tables in a Postgres database I manage. It has been suggested to schedule a reindex after the series of deletes as a solution to the 10 minute next-step update freezing infinitely (as it randomly does.) The DOS instructions provide this:

Usage:
  reindexdb [OPTION]... [DBNAME]

Options:
  -a, --all                 reindex all databases
  -d, --dbname=DBNAME       database to reindex
  -e, --echo                show the commands being sent to the server
  -i, --index=INDEX         recreate specific index only
  -q, --quiet               don't write any messages
  -s, --system              reindex system catalogs
  -t, --table=TABLE         reindex specific table only
  --help                    show this help, then exit
  --version                 output version information, then exit

Connection options:
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt

We have to use version 9.1.3 as this is the corporate standard. I have tried every option I can think of but it won't take the command to reindex:

reindexdb.exe -U username=MyUserName -W MyPassword -t table=MyDatabase.MyTable

I've also tried

reindexdb.exe -U MyUserName -W MyPassword -t MyDatabase.MyTable

and

reindexdb.exe -U MyUserName -W MyPassword -t MyTable -d MyDatabase

...but they all end with the error:

reindexdb: too many command-line arguments (first is "-t")

Does anyone have a working sample that would be able to clarify what the right syntax is?

like image 554
Phoenix14830 Avatar asked Dec 04 '25 14:12

Phoenix14830


1 Answers

Remove MyPassword from your arguments, and enter it in when Postgres prompts you for it.

-W simply causes Postgres to prompt for the password; it doesn't accept the password itself. You should never specify passwords on the command line, as it's usually logged.

If you need to run it non-interactively, either set the PGPASSWORD environment variable or create a pgpass file.

like image 186
Colonel Thirty Two Avatar answered Dec 07 '25 16:12

Colonel Thirty Two



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!