मैं एक PostgreSQL डेटाबेस की सभी तालिकाओं को कैसे सूचीबद्ध कर सकता हूं और उन्हें आकार के अनुसार ऑर्डर कर सकता हूं ?
मैं एक PostgreSQL डेटाबेस की सभी तालिकाओं को कैसे सूचीबद्ध कर सकता हूं और उन्हें आकार के अनुसार ऑर्डर कर सकता हूं ?
जवाबों:
select table_name, pg_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public'
order by 2
यह स्कीमा में सभी तालिकाओं का आकार दिखाता है publicयदि आपके पास कई स्कीमा हैं, तो आप उपयोग करना चाहते हैं:
select table_schema, table_name, pg_relation_size('"'||table_schema||'"."'||table_name||'"')
from information_schema.tables
order by 3
SQLField उदाहरण: http://sqlfiddle.com/# -15/13157/3
मैनुअल में सभी ऑब्जेक्ट आकार कार्यों की सूची ।
select table_schema, table_name, pg_relation_size(table_schema||'.'||table_name) from information_schema.tables order by 3; मदद के लिए धन्यवाद!
select * from information_schema.tables where table_schema = 'public';भी शून्य पंक्तियों का उत्पादन करता है \dn। शायद 9.5 में बदलाव के कारण ऐसा हुआ?
यह आपको स्कीमा नाम, तालिका नाम, आकार सुंदर और आकार (क्रम के लिए आवश्यक) दिखाएगा।
SELECT
schema_name,
relname,
pg_size_pretty(table_size) AS size,
table_size
FROM (
SELECT
pg_catalog.pg_namespace.nspname AS schema_name,
relname,
pg_relation_size(pg_catalog.pg_class.oid) AS table_size
FROM pg_catalog.pg_class
JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid
) t
WHERE schema_name NOT LIKE 'pg_%'
ORDER BY table_size DESC;
मैं एक पोस्टग्रेक्यूएल डेटाबेस में आकार (सापेक्ष और निरपेक्ष) के साथ स्कीमा की सूची से समाधान के आधार पर इसका निर्माण करता हूं
यह अधिक स्पष्ट होगा।
pg_size_pretty(<numeric_value>) - no.of बाइट्स को मानव-पठनीय प्रारूप में परिवर्तित करता है।
pg_database_size(<db_name>)- बाइट्स में डेटाबेस साइज मिलता है ।
pg_total_relation_size(<relation_name>)- टेबल का कुल आकार और बाइट्स में इसका इंडेक्स मिलता है ।
pg_relation_size(<relation_name>)- बाइट्स में संबंध (तालिका / सूचकांक) आकार प्राप्त करता है ।
pg_index_size(<relation_name>)- बाइट्स में रिलेशन का इंडेक्स साइज मिलता है ।
current_database() - वर्तमान में उपयोग किया गया डेटाबेस मिलता है, जिस पर यह क्वेरी की जा रही है।
प्रश्न:
select current_database() as database,
pg_size_pretty(total_database_size) as total_database_size,
schema_name,
table_name,
pg_size_pretty(total_table_size) as total_table_size,
pg_size_pretty(table_size) as table_size,
pg_size_pretty(index_size) as index_size
from ( select table_name,
table_schema as schema_name,
pg_database_size(current_database()) as total_database_size,
pg_total_relation_size(table_name) as total_table_size,
pg_relation_size(table_name) as table_size,
pg_indexes_size(table_name) as index_size
from information_schema.tables
where table_schema=current_schema() and table_name like 'table_%'
order by total_table_size
) as sizes;
परिणाम:
database | total_database_size | schema_name | table_name | total_table_size | table_size | index_size
-----------+---------------------+-------------+------------+------------------+------------+------------
vigneshdb | 1586 MB | corpdata | table_aaa | 16 kB | 0 bytes | 8192 bytes
vigneshdb | 1586 MB | corpdata | table_bbb | 24 kB | 0 bytes | 16 kB
vigneshdb | 1586 MB | corpdata | table_ccc | 640 kB | 112 kB | 488 kB
vigneshdb | 1586 MB | corpdata | table_ddd | 9760 kB | 3152 kB | 6568 kB
vigneshdb | 1586 MB | corpdata | table_eee | 1120 MB | 311 MB | 808 MB
Humanized प्रारूप में प्रतिनिधित्व कर रहा है bytes, kB, MB, GB, और TB।
bytesसे kB- शुरू होता है10240 bytes
bytesकरने के लिए MB- से शुरू होती है 10485248 bytes= 10239.5 kB~10 MB
bytesकरने के लिए GB- से शुरू होती है 10736893952 bytes= 10239.5 MB~10 BG
bytesकरने के लिए TB- से शुरू होती है 10994579406848 bytes= 10239.5 GB~10 TB
सभी इकाई रूपांतरण से शुरू होता है 10 + <unit>।
संदर्भ के लिए - आधिकारिक दस्तावेज़ीकरण को स्थगित करें
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
यहाँ से https://wiki-bsse.ethz.ch/display/ITDOC/Check+size+of+tables+and+objects+in+PostgreSQL+database
मुझे यह खोजने की आवश्यकता थी कि कौन सी तालिका सबसे अधिक स्थान का उपयोग करती है।
अन्य उत्तरों के आधार पर, मैंने उस प्रश्न का उपयोग किया:
select table_name, pg_size_pretty( pg_relation_size(quote_ident(table_name)) )
from information_schema.tables
where table_schema = 'public'
order by pg_relation_size(quote_ident(table_name)) desc
मुझे निम्नलिखित परिणाम मिले:
table_name pg_size_pretty
--------------------------------------
trade_binance 96 GB
closs_v2_binance_stash 46 GB
closs_bitfinex_stash 5725 MB
trade_bitfinex 5112 MB
...
api_requests 0 bytes
trade_huobi 0 bytes
मुझे एक बड़ा SSD खरीदना चाहिए था।
select uv.a tablename, pg_size_pretty(uv.b) sizepretty
from (select tb.tablename a, pg_table_size('schemaname.'||tb.tablename::text) b
from pg_tables tb
where tb.schemaname ilike 'schemaname'
order by 2 desc
) uv
\d+आपको यह जानकारी दिखाएगा, हालांकि अनसर्टेड।