Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 9F4079FB279 for ; Tue, 16 Oct 2007 07:00:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 98741-03 for ; Tue, 16 Oct 2007 07:00:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from hu-out-0506.google.com (hu-out-0506.google.com [72.14.214.229]) by postgresql.org (Postfix) with ESMTP id DC3879F953E for ; Tue, 16 Oct 2007 07:00:15 -0300 (ADT) Received: by hu-out-0506.google.com with SMTP id 22so1433436hug for ; Tue, 16 Oct 2007 03:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=Nj0quXQT2pT0mH/JoxD+4t8aYmxPnVBK8eIljp6Gnyo=; b=coZNxHOkvrMjZDmkemUj72e9BKcKzSCBsNO0Aq4zUYrPFDSa+IbUrhch1wWOPCQCNcT9rEAp0ToM55R3rjvex8RIx8gNVdoMEWgZv7xReiHEn+zuqcVlFGI8ZEn7D9u59kIaJ9SYnLyYhKbQKLRGOXqd3CZfX9ZR+CDnQ/3UaHo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=WLvrLnBiM6hFd8pWSt7Ymc+uTs7uEN2n6958pC2/uwWqgUfTHpnkUeHY5l1kUiHrA+Q2/cAS6+AzM33RI3yet2DWBUO2uiyKhDe383c65LRnJ8dkvdbHg18BjkC1CU9Q0huWpUAG5kUocT5foW5pEI2i4eQ8SMpmN2tORKbsqAk= Received: by 10.141.42.10 with SMTP id u10mr3357467rvj.1192528810933; Tue, 16 Oct 2007 03:00:10 -0700 (PDT) Received: by 10.65.163.6 with HTTP; Tue, 16 Oct 2007 03:00:10 -0700 (PDT) Message-ID: <58729a240710160300y2754d5eegd33397dc167eb815@mail.gmail.com> Date: Tue, 16 Oct 2007 12:00:10 +0200 From: "Patrick De Zlio" To: pgsql-sql@postgresql.org Subject: Inconsistent sql result MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_74581_26549037.1192528810910" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/68 X-Sequence-Number: 29440 ------=_Part_74581_26549037.1192528810910 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi listers, As a PG administrator, I'm trying to read technical data from pg_class table to monitor tables and indexes space. We are running a quite big postgres platform, with multiple databases, multiples schemes in each database, and hundreds tables. When I run the attach python script, I get 1809 rows as result. When I run the included (from the script) select query from phpPgAdmin or pgAdmin III, I get 2010 rows as result. When I try to focus on specific table including where relname ='tablename' in both parts of the join, I also get different numbers of rows. So I can't have the full size of all indexes attached on a table. Does anyone has a clue of why the same query, on same database gives different result depending on it is included in a python script, or ran from a console? Many Thanks Patrick #!/usr/bin/python2.4 # import sys import pgdb DEBUG = True global db # # Database access # def opendb(): global db # connect to database port='5432' username='xxxxxxx' dbname='xxxxxxx' host='xx.xx.xx.xx' password='xxxxxxx' try: db = pgdb.connect(database=dbname,host=host, user=username, password=password) except Exception, detail: db.rollback() if DEBUG: print 'Error occured while connecting to database : %s' % detail sys.exit(0) # # Close Database # def closedb(): global db # Commit all changes before closing db.commit() db.close() if __name__== '__main__': # # Main # opendb() query = "SELECT relname, relnamespace, relkind, relfilenode, relpages, reltoastrelid, relname AS idx_table_name FROM pg_class UNION SELECT pg_c_i.relname, pg_c_i.relnamespace, pg_c_i.relkind, pg_c_i.relfilenode, pg_c_i.relpages, pg_c_i.reltoastrelid, pg_c_i_o.relname AS idx_table_name FROM pg_class pg_c_i, pg_index pg_i, pg_class pg_c_i_o WHERE pg_c_i.relfilenode = pg_i.indexrelid AND pg_i.indrelid = pg_c_i_o.relfilenode " cur = db.cursor() cur.execute(query) tables_details = cur.fetchall() nb_tables = len(tables_details) for table in tables_details: print table print "Tables count=",nb_tables closedb() ------=_Part_74581_26549037.1192528810910 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi listers,

As a PG administrator, I'm trying to read technical data from pg_class table to monitor tables and indexes space.

We are running a quite big postgres platform, with multiple databases, multiples schemes in each database, and hundreds tables.

When I run the attach python script, I get 1809 rows as result. When I run the included (from the script) select query from phpPgAdmin or pgAdmin III, I get 2010 rows as result.

When I try to focus on specific table including where relname ='tablename' in both parts of the join, I also get different numbers of rows. So I can't have the full size of all indexes attached on a table.

Does anyone has a clue of why the same query, on same database gives different result depending on it is included in a python script, or ran from a console?

Many Thanks
Patrick
#!/usr/bin/python2.4
#

import sys
import pgdb

DEBUG = True
global db
#
# Database access
#
def opendb():
global db
# connect to database
port='5432'
username='xxxxxxx'
dbname='xxxxxxx'
host='xx.xx.xx.xx'
password='xxxxxxx'

try:
db = pgdb.connect(database=dbname,host=host, user=username, password=password)
except Exception, detail:
db.rollback()
if DEBUG:
print 'Error occured while connecting to database : %s' % detail
sys.exit(0)

#
# Close Database
#
def closedb():
global db
# Commit all changes before closing
db.commit()
db.close()



if __name__== '__main__':

#
# Main
#
opendb()
query = "SELECT relname, relnamespace, relkind, relfilenode, relpages, reltoastrelid, relname AS idx_table_name FROM pg_class UNION SELECT pg_c_i.relname, pg_c_i.relnamespace, pg_c_i.relkind, pg_c_i.relfilenode, pg_c_i.relpages, pg_c_i.reltoastrelid, pg_c_i_o.relname AS idx_table_name FROM pg_class pg_c_i, pg_index pg_i, pg_class pg_c_i_o WHERE pg_c_i.relfilenode = pg_i.indexrelid AND pg_i.indrelid = pg_c_i_o.relfilenode "
cur = db.cursor()
cur.execute(query)
tables_details = cur.fetchall()
nb_tables = len(tables_details)
for table in tables_details:
print table
print "Tables count=",nb_tables

closedb()
------=_Part_74581_26549037.1192528810910--