hi,
I am trying to rebuild index and update statistics for a postgresql 9.3.6 DB and the command I use is:
REINDEX DATABASE <Application database>;
REINDEX SYSTEM <Application database> ;
VACUUM(FULL, ANALYZE, VERBOSE);
I ran that for the first time and 137GB database takes 9 hours to finish but later that the DB size seems goes down to 80GB.
are SQL commands and require that you to connect to the database that you intend to run it on.
REINDEX system "alfresco";
If that works then your database was created with double quotes around the name.SELECT * FROM "table"
will work but notSELECT * FROM table
REINDEX system "alfresco";
REINDEX table alf_node_properties; --314GB tables.
REINDEX table alf_node ; --80GB tables
REINDEX table alf_child_assoc; --17GB tables.
REINDEX SYSTEM alfresco;
VACUUM(FULL, ANALYZE, VERBOSE);
how about in postgreSQL?You open a dedicated connection to a database in PostgreSQL. The USE SQL keyword is only used and works in SQLServer, MySQL and MariaDB. See the relevent SQL keywords list in the DBMS manuals.
is there any command/script for postgreSQL to say only to rebuild the index of a table if the fragmentation is >30% and pass that process if not ?By querying the stat catalog tables you can easily build a script that executes VACUUM / REINDEX commands if a certain fragmentation threshold is reached.
You open a dedicated connection to a database in PostgreSQL. The USE SQL keyword is only used and works in SQLServer, MySQL and MariaDB. See the relevent SQL keywords list in the DBMS manuals.
you mean we can ONLY do it in connection string level ?Yes, as stated in the PostgreSQL manual.
REINDEX table alf_node_properties; --
-- SQL Error [23505]: ERROR: could not create unique index "alf_node_properties_pkey"
Detail: Key (node_id, qname_id, list_index, locale_id)=(51060016, 28, -1, 1) is duplicated.
REINDEX table alf_node ; --
SQL Error [23505]: ERROR: could not create unique index "alf_node_pkey"
Detail: Key (id)=(844) is duplicated.
SELECT pg_size_pretty (pg_indexes_size('alf_child_ass'));
You will need at least that size of free space on your disk and more for other workload. SELECT pg_size_pretty (pg_indexes_size('alf_child_ass'));
SELECT pg_size_pretty (pg_relation_size('alf_child_ass
'));
REINDEX INDEX the_indexname;
VACUUM(FULL, ANALYZE, VERBOSE);
REINDEX table alf_node_properties; -- -- SQL Error [23505]: ERROR: could not create unique index "alf_node_properties_pkey"
Detail: Key (node_id, qname_id, list_index, locale_id)=(51060016, 28, -1, 1) is duplicated.
REINDEX table alf_node ; --SQL Error [23505]: ERROR: could not create unique index "alf_node_pkey"
Detail: Key (id)=(844) is duplicated.
REINDEX table alf_node_properties; -- -- SQL Error [23505]: ERROR: could not create unique index "alf_node_properties_pkey" Detail: Key (node_id, qname_id, list_index, locale_id)=(51060016, 28, -1, 1) is duplicated.
REINDEX table alf_node ; --SQL Error [23505]: ERROR: could not create unique index "alf_node_pkey" Detail: Key (id)=(844) is duplicated.
Doing reindex on a busy table can lead to duplicate entries in a table between the time when the reindex process drops a unique index and then tries to recreate it.
If you asking about why it is about half the size, did you recently delete a LOT of data in the database? Rebuilding of indexes will remove the dead rows from the indexes.