PostgreSQL: तालिका तक अंतिम पहुंच समय


10

मैं एक बड़े PostgreSQL डेटाबेस के प्रभारी हूं, जिसमें कुछ दर्जन टेबल हैं। मुझे संदेह है कि इनमें से कई तालिकाओं को कभी एक्सेस नहीं किया गया है।

अंतिम बार एक निश्चित तालिका तक पहुंचने पर सबसे अच्छा तरीका क्या है? मैंने एक ट्रिगर जोड़ने के बारे में सोचा DELETE, INSERTऔर UPDATE, लेकिन मुझे उम्मीद है कि एक अधिक कुशल तरीका है।



धन्यवाद, सही किया। लॉगिंग समाधान हो सकता है, लेकिन डीबी का भारी उपयोग किया जाता है और लॉग शायद डिस्क स्थान को बहुत अधिक ले जाएगा।
एडम मटन

जवाबों:


9

pg_catalog.pg_statio_all_tables आपका मित्र है। तुम सब करने की ज़रूरत है समय-समय पर सवाल में तालिकाओं के लिए pg_statio_all_tables पोल। बदलते आँकड़े ~ सक्रिय तालिका, गैर-बदलते आँकड़े ~ संभावित अप्रयुक्त तालिका। बस सावधान रहें कि कोई भी select pg_stat_reset () ;आपकी निगरानी के बीच में नहीं करता है ।

उदाहरण के लिए:

test_1=# create table test_stats (col1 integer);
CREATE TABLE

test_1=# select * from pg_catalog.pg_statio_all_tables 
         where schemaname not in ('pg_catalog', 'information_schema') 
         and relname = 'test_stats';
 relid | schemaname |  relname   | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit 
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
 22957 | public     | test_stats |              0 |             0 |        [null] |       [null] |          [null] |         [null] |         [null] |        [null]
(1 row)

इंसर्ट:

test_1=# insert into test_stats (col1) select generate_series( 1, 10000000);
INSERT 0 10000000

test_1=# select * from pg_catalog.pg_statio_all_tables
         where schemaname not in ('pg_catalog', 'information_schema') 
         and relname = 'test_stats';
 relid | schemaname |  relname   | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit 
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
 22957 | public     | test_stats |          44260 |      10088481 |        [null] |       [null] |          [null] |         [null] |         [null] |        [null]
(1 row)

चयन:

test_1=# select count (*) from test_stats where col1 between 10000 and 50000;
 count 
-------
 40001
(1 row)

test_1=# select * from pg_catalog.pg_statio_all_tables
         where schemaname not in ('pg_catalog', 'information_schema') 
         and relname = 'test_stats';
 relid | schemaname |  relname   | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit 
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
 22957 | public     | test_stats |          85560 |      10091429 |        [null] |       [null] |          [null] |         [null] |         [null] |        [null]
(1 row)

हटाता है:

test_1=# delete from test_stats where col1 between 10000 and 50000;
DELETE 40001

test_1=# select * from pg_catalog.pg_statio_all_tables
         where schemaname not in ('pg_catalog', 'information_schema') 
         and relname = 'test_stats';
 relid | schemaname |  relname   | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit 
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
 22957 | public     | test_stats |         155075 |      10136163 |        [null] |       [null] |          [null] |         [null] |         [null] |        [null]
(1 row)

अपडेट-- 2011-09-01

आगे का परीक्षण इंगित करता है कि vacuumकुछ हद तक pg_statio_all_tables में मूल्यों को बढ़ाता हुआ प्रतीत होता है, जो आपके इच्छित उपयोग के लिए दुर्भाग्यपूर्ण है। हालांकि vacuumयह pg_statio_all_tables का उपयोग बेकार नहीं करता है, लेकिन यह परिणामों को थोड़ा अस्पष्ट बनाता है।

शायद मॉनिटर करने के लिए एक बेहतर जगह है pg_catalog.pg_stat_all_tables (कम से कम Pg के नए संस्करणों के साथ)। मैं संस्करण and.४ को देख रहा हूं और इसमें टुपल्स के लिए काउंट्स डाले गए हैं, पढ़े गए, अपडेट किए गए और हटाए गए हैं - ISTR have.२ में वह सब नहीं है और मुझे 8.3 के बारे में इतना पता नहीं है कि YMMV Pg के संस्करण के आधार पर है कि आप हैं का उपयोग करते हुए।

एक तीसरा विकल्प (डालने, अद्यतन करने और गतिविधि को हटाने के लिए) $ PGDATA / आधार / $ डेटिड निर्देशिका में फ़ाइल टाइमस्टैम्प को देखने के लिए है। फ़ाइल नाम को तालिका की ओड में मैप करना चाहिए, इसलिए आप इसका उपयोग उन तालिकाओं को पहचानने के लिए कर सकते हैं जिन्हें आवेषण, अद्यतन या हटाए नहीं जा रहे हैं। दुर्भाग्य से, यह उन तालिकाओं को संबोधित नहीं करता है जो अभी भी से चुने जा रहे हैं, और तालिकाओं का उपयोग करने से अतिरिक्त जटिलताएं पैदा होंगी (क्योंकि वे फाइलें $ PGDATA / आधार / $ डेटािड के तहत नहीं होंगी)। टाइमस्टैम्प तब तक अपडेट नहीं होगा जब तक कि किसी भी लंबित परिवर्तन को वापस नहीं किया जाता है, लेकिन यदि फ़ाइल महीनों में नहीं बदली है, तो वर्तमान में लंबित परिवर्तन की संभावनाएं बहुत कम हैं।


3

आप अंतिम परिवर्तन के बारे में कुछ जानकारी तालिका के साथ प्राप्त कर सकते हैं xmin, जैसे:

select max(xmin::text::bigint) from t;

लेकिन, आपको मॉडुलो और रैपराउंड और फ्रोजन एक्सिड्स के बारे में पता होना चाहिए । इसे "समय" में परिवर्तित करने का कोई तरीका नहीं है, लेकिन यदि आप अभी अपनी तालिका के लिए मान कैप्चर करते हैं, तो बाद की तारीख में तुलना करें, तो आप उन तालिकाओं की सूची प्राप्त कर सकते हैं जो बदल गए हैं

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.