Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7C38358D09B for ; Wed, 9 Nov 2011 13:06:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 94973-01 for ; Wed, 9 Nov 2011 17:06:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail2.sdb.it (mail2.sdb.it [85.37.147.67]) by mail.postgresql.org (Postfix) with ESMTP id 98AE058D09A for ; Wed, 9 Nov 2011 13:06:12 -0400 (AST) Received: by mail2.sdb.it (Postfix, from userid 500) id E819B8016; Wed, 9 Nov 2011 18:06:11 +0100 (CET) Received: from geronimo.sdb.it (geronimo.sdb.it [10.101.1.20]) by mail2.sdb.it (Postfix) with ESMTP id E2FAD8008; Wed, 9 Nov 2011 18:06:11 +0100 (CET) Received: from mailtech.sdb.it (localhost [127.0.0.1]) by geronimo.sdb.it (Postfix) with ESMTP id 6C5A5380807; Wed, 9 Nov 2011 18:06:00 +0100 (CET) Received: from [10.118.101.88] (silviob.sdb.it [10.118.101.88]) by mailtech.sdb.it (Postfix) with ESMTP id 6D50E60061; Wed, 9 Nov 2011 18:01:13 +0100 (CET) Message-ID: <4EBAB303.2080307@tech.sdb.it> Date: Wed, 09 Nov 2011 18:06:11 +0100 From: Silvio Brandani User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.23) Gecko/20110920 Thunderbird/3.1.15 MIME-Version: 1.0 To: "Ruslan A. Bondar" Cc: pgsql-admin@postgresql.org Subject: Re: database not using indexes References: <4EBA9AAC.9030900@tech.sdb.it> <20111109195838.237a4470@list.ru> In-Reply-To: <20111109195838.237a4470@list.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Private-Material: Please read notice X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.401 tagged_above=-10 required=5 tests=BAYES_50=0.8, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/35 X-Sequence-Number: 38629 Ok, the problem was on a big table on query like this: select outmessage0_.out_msg_id as out1_0_ from edi.out_messages outmessage0_, edi.transaction_set_partners transactio1_ where outmessage0_.transaction_set_partner=transactio1_.trn_set_prtn_id and outmessage0_.status_id='TOSND' and transactio1_.legacy_sender_id='ALL' and transactio1_.legacy_receiver_id='00004542' and outmessage0_.transaction_set_id='INTERNAL_USE' order by outmessage0_.out_msg_id the existing indexes on status_id CREATE INDEX out_msg_status_idex ON edi.out_messages USING btree (status_id); and transaction_set_partners CREATE INDEX edi_out_messages_trn_set_prtn_id_fk_idx ON edi.out_messages USING btree (transaction_set_partner); where not used anyore. I created the following one: CREATE INDEX out_msg_status_trn_set_prtn_idx ON edi.out_messages USING btree (status_id,transaction_set_partner); and still the explain show a seq scan then I inverted the fields and now it works: CREATE INDEX out_msg_status_trn_set_prtn_idx2 ON edi.out_messages USING btree (transaction_set_partner,status_id); I wonder why not use anymore the existing indexes. regards Il 09/11/2011 16.58, Ruslan A. Bondar ha scritto: > Why have you decided it isn't using indexes? > If index exists - postgres will use it. > To write a script for this I need at least database version. > > On Wed, 09 Nov 2011 16:22:20 +0100 > Silvio Brandani wrote: > >> Our database seems not using index anymore, please help with, is a >> production database. >> >> is there a script to check missing index on foreign key ?? >> >> thanks a lot >> >> --- >> >> >> >> >> --- Utilizziamo i dati personali che la riguardano esclusivamente per nostre finalitą amministrative e contabili, anche quando li comunichiamo a terzi. Informazioni dettagliate, anche in ordine al Suo diritto di accesso e agli altri Suoi diritti, sono riportate alla pagina http://www.savinodelbene.com/privacy.html Se avete ricevuto questo messaggio per errore Vi preghiamo di ritornarlo al mittente eliminandolo assieme agli eventuali allegati, ai sensi art. 616 codice penale http://www.savinodelbene.com/privacy/codice_penale_616.html L'Azienda non si assume alcuna responsabilitą giuridica qualora pervengano da questo indirizzo messaggi estranei all'attivitą lavorativa o contrari a norme. --