ऐसा लगता है कि आप समर्पित डेटाबेस के बजाय साझा का उपयोग कर रहे हैं, इसलिए आपको इसे कठिन तरीके से करना होगा। यदि आपके पास एक समर्पित डेटाबेस था तो आप जो भी खोज रहे हैं उसे पाने के लिए heroku pg:psql
और फिर \di
and assorted other psql
commands कर सकते थे।
हालांकि हमेशा कठिन तरीका है और इसमें आंतरिक कैटलॉग टेबल शामिल हैं। एसक्यूएल के कुछ भाग हैं जिन्हें आपको आवश्यकता होगी, आप उन्हें ActiveRecord::Base.connection.select_rows
कॉल में लपेट सकते हैं और अपने रेल कंसोल से परिणामों तक पहुंच सकते हैं।
आप इस के साथ अपने टेबल और उनके अनुक्रमित की एक सूची प्राप्त कर सकते हैं:
select c2.relname as table, c2.oid as table_oid, c.relname as name, c.oid as index_oid
from pg_catalog.pg_class c
join pg_catalog.pg_index i on i.indexrelid = c.oid
join pg_catalog.pg_class c2 on i.indrelid = c2.oid
left join pg_catalog.pg_user u on u.usesysid = c.relowner
left join pg_catalog.pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'i'
and n.nspname <> 'pg_catalog'
and pg_catalog.pg_table_is_visible(c.oid)
order by c2.relname, c.relname
तो फिर तुम index_oid
उपयोग कर सकते हैं इस के साथ सवाल में सूचकांक का एक विवरण प्राप्त करने के लिए:
select c.relname, c.oid, i.indisprimary, i.indisunique, i.indisclustered, i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), c.reltablespace
from pg_catalog.pg_class c
join pg_catalog.pg_index i on c.oid = i.indexrelid
where c.oid = '#{index_oid}'
या आप उस तालिका के लिए इंडेक्स की सूची प्राप्त करने के लिए table_oid
का उपयोग कर सकते हैं:
select ci.relname, ci.oid, i.indisprimary, i.indisunique, i.indisclustered, i.indisvalid, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true), ci.reltablespace
from pg_catalog.pg_index i
join pg_catalog.pg_class ci on i.indexrelid = ci.oid
where i.indrelid = '#{table_oid}'
order by ci.relname
आप शायद आसान पहुँच के लिए एक उपयोगिता वर्ग में यह सब सामान रैप करने के लिए चाहते हैं:
class PGInfo
def self.list_indexes
data = ActiveRecord::Base.connection.select_rows(%Q{
select c2.relname as table, c.relname as name, c.oid as oid
...
})
# do something pretty with the array of arrays that is in data
end
# etc.
end
मैं Heroku पर एक साझा डेटाबेस के साथ इन प्रयास नहीं किया है (क्षमा करें, मैं केवल एक समर्पित डेटाबेस निभानी है साथ में)। आसान तरीके हो सकते हैं लेकिन इन्हें नौकरी मिलनी चाहिए और यदि आप उन्हें पीजीइन्फो कक्षा में लपेटते हैं तो उनका उपयोग करना आसान होगा।
वह सब जो आपको आवश्यक इंडेक्स जानकारी देता है, तो आप अपनी अनुक्रमणिका को जोड़ने, हटाने या संशोधित करने के लिए सामान्य माइग्रेशन का उपयोग कर सकते हैं।
यह $ 15/माह पोस्टग्रेस, 20 गीगा है। मुझे यकीन नहीं है कि यह साझा या समर्पित है या नहीं। – Brand