Implement pg_database_size().

In this implementation dbsize equals sum of all relation sizes, excluding shared ones.
This commit is contained in:
Anastasia Lubennikova
2022-05-03 13:23:18 +03:00
committed by Anastasia Lubennikova
parent b68e3b03ed
commit e2cf77441d
3 changed files with 67 additions and 2 deletions

View File

@@ -32,7 +32,16 @@ def test_createdb(zenith_simple_env: ZenithEnv):
# Test that you can connect to the new database on both branches
for db in (pg, pg2):
db.connect(dbname='foodb').close()
with closing(db.connect(dbname='foodb')) as conn:
with conn.cursor() as cur:
# Check database size in both branches
cur.execute(
'select pg_size_pretty(pg_database_size(%s)), pg_size_pretty(sum(pg_relation_size(oid))) from pg_class where relisshared is false;',
('foodb', ))
res = cur.fetchone()
# check that dbsize equals sum of all relation sizes, excluding shared ones
# This is how we define dbsize in zenith for now
assert res[0] == res[1]
#