logo
down
shadow

Calculating PostgreSql DB size in python


Calculating PostgreSql DB size in python

By : user3851511
Date : October 16 2020, 11:12 AM
should help you out I want to write a cron job to calculate PosgreSql database size in python. Is there any API's in python. Cron job will find all the databases & calculate sizes for all of them daily. , Just a query:
code :


Share : facebook icon twitter icon
Calculating a directory's size using Python?

Calculating a directory's size using Python?


By : user1441577
Date : March 29 2020, 07:55 AM
wish helps you Before I re-invent this particular wheel, has anybody got a nice routine for calculating the size of a directory using Python? It would be very nice if the routine would format the size nicely in Mb/Gb etc. , This walks all sub-directories; summing file sizes:
code :
import os

def get_size(start_path = '.'):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            # skip if it is symbolic link
            if not os.path.islink(fp):
                total_size += os.path.getsize(fp)

    return total_size

print(get_size(), 'bytes')
import os
sum(os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f))
import os

nbytes = sum(d.stat().st_size for d in os.scandir('.') if d.is_file())
from pathlib import Path

root_directory = Path('.')
sum(f.stat().st_size for f in root_directory.glob('**/*') if f.is_file() )

Calculating the size of a column type in Postgresql

Calculating the size of a column type in Postgresql


By : user5096798
Date : March 29 2020, 07:55 AM
I wish this help you only few types in pg has fixed length - almost all types are varlena type - it has dynamic length. You can check queries like
code :
 postgres=# select typlen from pg_type where oid = 'int'::regtype::oid;
  typlen 
 --------
       4
 (1 row)


 postgres=# select attlen from pg_attribute where attrelid = 'x'::regclass and attname = 'a';
  attlen 
 --------
       4
 (1 row)
postgres=# \df *size*
                                   List of functions
   Schema   |          Name          | Result data type | Argument data types |  Type  
------------+------------------------+------------------+---------------------+--------
 pg_catalog | pg_column_size         | integer          | "any"               | normal
 pg_catalog | pg_database_size       | bigint           | name                | normal
 pg_catalog | pg_database_size       | bigint           | oid                 | normal
 pg_catalog | pg_indexes_size        | bigint           | regclass            | normal
 pg_catalog | pg_relation_size       | bigint           | regclass            | normal
 pg_catalog | pg_relation_size       | bigint           | regclass, text      | normal
 pg_catalog | pg_size_pretty         | text             | bigint              | normal
 pg_catalog | pg_size_pretty         | text             | numeric             | normal
 pg_catalog | pg_table_size          | bigint           | regclass            | normal
 pg_catalog | pg_tablespace_size     | bigint           | name                | normal
 pg_catalog | pg_tablespace_size     | bigint           | oid                 | normal
 pg_catalog | pg_total_relation_size | bigint           | regclass            | normal
(12 rows)



 postgres=# select pg_column_size('Hello');
  pg_column_size 
 ----------------
          6
 (1 row)

 postgres=# select pg_column_size(10);
  pg_column_size 
 ----------------
               4
 (1 row)

 postgres=# select pg_column_size(now());
  pg_column_size 
 ----------------
               8
calculating the real size of a python string

calculating the real size of a python string


By : abhishek choudhury
Date : March 29 2020, 07:55 AM
This might help you Python objects have a minimal size, the overhead of keeping several pieces of bookkeeping data attached to the object.
A Python str object is no exception. Take a look at the difference between a string with no, one, two and three characters:
code :
>>> import sys
>>> sys.getsizeof('')
37
>>> sys.getsizeof('a')
38
>>> sys.getsizeof('aa')
39
>>> sys.getsizeof('aaa')
40
Calculating size folder python

Calculating size folder python


By : Mark Detron
Date : March 29 2020, 07:55 AM
This might help you I want to ask how to calculate 3 folder size together using python and show as dataframe. , Try the below code-
code :
import os
f= r"D:\Reg"
folder_name= os.path.basename(f)
def get_size(start_path = '.'):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            total_size += os.path.getsize(fp)
    return total_size
print "{0:<20}      {1:>0}".format("Folder"," Size")
print "{0:<20}        {1:>0}".format(folder_name,str(get_size(f))+" bytes")
calculating total floor size (Python)

calculating total floor size (Python)


By : TCobb91
Date : March 29 2020, 07:55 AM
seems to work fine I need to calculate the total floor size. it first asks for number of rooms(all are rectangular) and then using a for loop asks for length and width of each one. Here's my code(python):
code :
norooms = int(input('How many rooms does the floor have?'))
length = dict()
width = dict()
for i in range(norooms):
    length[i] = input('what is the length of room?')
    width[i] =input('what is the width of room?')
    print('that was room number:',i+1)
total=0
for i in range(norooms):
    total += float(length[i])*float(width[i])

print 'total is:' ,total
room_counts = int(input('How many rooms does the floor have?'))
total=0
for i in xrange(room_counts)
    length=float(input('room #%s length?'%(i+1)))
    width=float(input('room #%s width?'%(i+1)))
    total +=length*width
print 'total is ',total
shadow
Privacy Policy - Terms - Contact Us © bighow.org