forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
108 lines
18 KiB
HTML
108 lines
18 KiB
HTML
<a name="EN-US_TOPIC_0000001098671154"></a><a name="EN-US_TOPIC_0000001098671154"></a>
|
|
|
|
<h1 class="topictitle1">Database Object Functions</h1>
|
|
<div id="body1553151203304"><div class="section" id="EN-US_TOPIC_0000001098671154__sb24151ede6b344a5b74cd8063aeb7016"><h4 class="sectiontitle">Database Object Size Functions</h4><p id="EN-US_TOPIC_0000001098671154__aaee277591227423fb6bbcb7e402014ac">Database object size functions calculate the actual disk space used by database objects.</p>
|
|
<ul id="EN-US_TOPIC_0000001098671154__u4945ddcafdc64e878699da5c6de82a23"><li id="EN-US_TOPIC_0000001098671154__le46636976f2c43b3ae0f90dc56d2ac36">pg_column_size(any)<p id="EN-US_TOPIC_0000001098671154__aac6e660f56764ccbbfa16111eda556d3"><a name="EN-US_TOPIC_0000001098671154__le46636976f2c43b3ae0f90dc56d2ac36"></a><a name="le46636976f2c43b3ae0f90dc56d2ac36"></a>Description: Specifies the number of bytes used to store a particular value (possibly compressed).</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a31a1e8dd2eb548ddbff14e082d879016">Return type: int</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a975d7c142da24eae93a5bb72908b6df8">Note: <strong id="EN-US_TOPIC_0000001098671154__b842352706111736">pg_column_size</strong> displays the space for storing an independent data value.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098671154__s0e44c94b77fe44e89fcf92089e5ccf68"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">pg_column_size</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">pg_column_size</span><span class="w"> </span>
|
|
<span class="c1">----------------</span>
|
|
<span class="w"> </span><span class="mi">4</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__lbf0d24b97335405aad750fe00ba9a7de">pg_database_size(oid)<p id="EN-US_TOPIC_0000001098671154__a468b89ddea2e433a86aac31fd9b9ad0b"><a name="EN-US_TOPIC_0000001098671154__lbf0d24b97335405aad750fe00ba9a7de"></a><a name="lbf0d24b97335405aad750fe00ba9a7de"></a>Description: Specifies the disk space used by the database with the specified OID.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a02a1a82df63944138cb6e43fca5ab96b">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__lfd18b3b53ea940fda4bf50ac648ef138">pg_database_size(name)<p id="EN-US_TOPIC_0000001098671154__ad90e375c29bd4294acac9ef273920641"><a name="EN-US_TOPIC_0000001098671154__lfd18b3b53ea940fda4bf50ac648ef138"></a><a name="lfd18b3b53ea940fda4bf50ac648ef138"></a>Description: Specifies the disk space used by the database with the specified name.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ab6fe1ec740994329aaaa6f69312c8651">Return type: bigint</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a745e30b874114f2abbbd3df9ac8feca2">Note: <strong id="EN-US_TOPIC_0000001098671154__en-us_topic_0058965547_b84235270611180">pg_database_size</strong> receives the OID or name of a database and returns the disk space used by the corresponding object.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ad25fe4c172c9471da2a5ce7e48ca46b8">For example:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098671154__sed0d9ecf8c7246f49210581dfd6f9266"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">pg_database_size</span><span class="p">(</span><span class="s1">'gaussdb'</span><span class="p">);</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">pg_database_size</span><span class="w"> </span>
|
|
<span class="c1">------------------</span>
|
|
<span class="w"> </span><span class="mi">51590112</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l84b003e407064991a46a68b85972572b">pg_relation_size(oid)<p id="EN-US_TOPIC_0000001098671154__a294766ef27b748888330492d6f45bdb6"><a name="EN-US_TOPIC_0000001098671154__l84b003e407064991a46a68b85972572b"></a><a name="l84b003e407064991a46a68b85972572b"></a>Description: Specifies the disk space used by the table with a specified OID or index.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a6e5262617ab84a9fbcedbc8241900205">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__li17524103519191">get_db_source_datasize()<p id="EN-US_TOPIC_0000001098671154__p210912510197"><a name="EN-US_TOPIC_0000001098671154__li17524103519191"></a><a name="li17524103519191"></a>Description: Estimates the total size of non-compressed data in the current database.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__p21096258193">Return type: bigint</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__p9109102510191">Note: (1) <strong id="EN-US_TOPIC_0000001098671154__b84235270619633">ANALYZE</strong> must be performed before this function is called. (2) Calculate the total size of non-compressed data by estimating the compression rate of column-store tables.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__p1810952531919">For example:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098671154__screen14971319192417"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span>
|
|
<span class="normal">6</span>
|
|
<span class="normal">7</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">analyze</span><span class="p">;</span><span class="w"></span>
|
|
<span class="k">ANALYZE</span><span class="w"></span>
|
|
<span class="k">select</span><span class="w"> </span><span class="n">get_db_source_datasize</span><span class="p">();</span><span class="w"></span>
|
|
<span class="w"> </span><span class="n">get_db_source_datasize</span><span class="w"></span>
|
|
<span class="c1">------------------------</span>
|
|
<span class="w"> </span><span class="mi">35384925667</span><span class="w"></span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l81d3f715f62f4537862ab11ef88cd15a">pg_relation_size(text)<p id="EN-US_TOPIC_0000001098671154__a090f49da938349e088e9693bdb593658"><a name="EN-US_TOPIC_0000001098671154__l81d3f715f62f4537862ab11ef88cd15a"></a><a name="l81d3f715f62f4537862ab11ef88cd15a"></a>Description: Specifies the disk space used by the table with a specified name or index. The table name can be schema-qualified.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__acce0ad5bc0e1489999be91de754d4ac2">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__lfc165a7ccff5465b84a92bc6d40d0d7e">pg_relation_size(relation regclass, fork text)<p id="EN-US_TOPIC_0000001098671154__ad87008d13de5492a9b99f60c12e21469"><a name="EN-US_TOPIC_0000001098671154__lfc165a7ccff5465b84a92bc6d40d0d7e"></a><a name="lfc165a7ccff5465b84a92bc6d40d0d7e"></a>Description: Specifies the disk space used by the specified bifurcating tree ('main', 'fsm', or 'vm') of a certain table or index.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a448f438f84014df8b2e2cd681be1c4f1">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__la74e245ecce0406380c052d7c04a9e8c">pg_relation_size(relation regclass)<p id="EN-US_TOPIC_0000001098671154__a8c104e0320c945c391a126d7b74e9f5c"><a name="EN-US_TOPIC_0000001098671154__la74e245ecce0406380c052d7c04a9e8c"></a><a name="la74e245ecce0406380c052d7c04a9e8c"></a>Description: Is an abbreviation of <strong id="EN-US_TOPIC_0000001098671154__b16329132895017">pg_relation_size(..., 'main')</strong>.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a8cae5a23799c4085a49fbad40eab4b84">Return type: bigint</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ae66fd4876a744ed1892bd2e805fe481e">Note: <strong id="EN-US_TOPIC_0000001098671154__b842352706111859">pg_relation_size</strong> receives the OID or name of a table, index, or compressed table, and returns the size.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l9d8888f00fe14ce89cae70d86f1f5260">pg_partition_size(oid,oid)<p id="EN-US_TOPIC_0000001098671154__aad83715f59604f28b2654c27acc2774b"><a name="EN-US_TOPIC_0000001098671154__l9d8888f00fe14ce89cae70d86f1f5260"></a><a name="l9d8888f00fe14ce89cae70d86f1f5260"></a>Description: Specifies the disk space used by the partition with a specified OID. The first <strong id="EN-US_TOPIC_0000001098671154__b15448614515">oid</strong> is the OID of the table and the second <strong id="EN-US_TOPIC_0000001098671154__b141931035113">oid</strong> is the OID of the partition.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__aff2154382b854625ada1e49d966c7f13">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l419d6fe096d9455b948dc46caa637e14">pg_partition_size(text, text)<p id="EN-US_TOPIC_0000001098671154__aabe8e7db6f704ee6a6f64be8519bdefb"><a name="EN-US_TOPIC_0000001098671154__l419d6fe096d9455b948dc46caa637e14"></a><a name="l419d6fe096d9455b948dc46caa637e14"></a>Description: Specifies the disk space used by the partition with a specified name. The first <strong id="EN-US_TOPIC_0000001098671154__b12551489525">text</strong> is the table name and the second <strong id="EN-US_TOPIC_0000001098671154__b502133529">text</strong> is the partition name.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ab69479fd3f544e07893c783b0d37683b">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l20b014c26395422182a3c99feda57701">pg_partition_indexes_size(oid,oid)<p id="EN-US_TOPIC_0000001098671154__a3f60855c70ab46a9a34c03deb6eecd10"><a name="EN-US_TOPIC_0000001098671154__l20b014c26395422182a3c99feda57701"></a><a name="l20b014c26395422182a3c99feda57701"></a>Description: Specifies the disk space used by the index of the partition with a specified OID. The first <strong id="EN-US_TOPIC_0000001098671154__b71492267521">oid</strong> is the OID of the table and the second <strong id="EN-US_TOPIC_0000001098671154__b16150182615526">oid</strong> is the OID of the partition.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a16f80c96d5ed4e7abb1980aacfb7fd59">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__ld2a65a89c9054c3aba790fb4f7f52012">pg_partition_indexes_size(text,text)<p id="EN-US_TOPIC_0000001098671154__a989d7095a3a0408aa50bcc6a8fc6b509"><a name="EN-US_TOPIC_0000001098671154__ld2a65a89c9054c3aba790fb4f7f52012"></a><a name="ld2a65a89c9054c3aba790fb4f7f52012"></a>Description: Specifies the disk space used by the index of the partition with a specified name. The first <strong id="EN-US_TOPIC_0000001098671154__b14382553115213">text</strong> is the table name and the second <strong id="EN-US_TOPIC_0000001098671154__b16384165316522">text</strong> is the partition name.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a4170ff92660246fdba03cacc6b02bc2b">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l25bbe89de812464cadd003e344f7a9d5">pg_indexes_size(regclass)<p id="EN-US_TOPIC_0000001098671154__a54aa4a7bbee54e7aada7afc8092dbb37"><a name="EN-US_TOPIC_0000001098671154__l25bbe89de812464cadd003e344f7a9d5"></a><a name="l25bbe89de812464cadd003e344f7a9d5"></a>Description: Specifies the total disk space used by the index appended to the specified table.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a3a6a4e3b35454b0bbeaae78bd7f4554f">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__lc3178bd8b1564d87bdd5e01ca47714a7">pg_size_pretty(bigint)<p id="EN-US_TOPIC_0000001098671154__a2891d6c3b88b4a4c8dffbc6f2b8c78d3"><a name="EN-US_TOPIC_0000001098671154__lc3178bd8b1564d87bdd5e01ca47714a7"></a><a name="lc3178bd8b1564d87bdd5e01ca47714a7"></a>Description: Converts the calculated byte size into a size readable to human beings.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a4f13374133ac4050834cb0768c5b3fa3">Return type: text</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l739b4155452140a19876b38a4fc8c442">pg_size_pretty(numeric)<p id="EN-US_TOPIC_0000001098671154__a67978263329444b8a010e41a88938279"><a name="EN-US_TOPIC_0000001098671154__l739b4155452140a19876b38a4fc8c442"></a><a name="l739b4155452140a19876b38a4fc8c442"></a>Description: Converts the calculated byte size indicated by a numeral into a size readable to human beings.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ac2e566935c8b409597d4a5c9db6c27f2">Return type: text</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__aaa358b6179194e1384089ff9a26a8a10">Note: <strong id="EN-US_TOPIC_0000001098671154__b842352706112013">pg_size_pretty</strong> formats the results of other functions into a human-readable format. KB/MB/GB/TB can be used.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l52bab23d1d044feeb975280de4990dd1">pg_table_size(regclass)<p id="EN-US_TOPIC_0000001098671154__ad046ecbdb22942f6ba79661d280fd286"><a name="EN-US_TOPIC_0000001098671154__l52bab23d1d044feeb975280de4990dd1"></a><a name="l52bab23d1d044feeb975280de4990dd1"></a>Description: Specifies the disk space used by the specified table, excluding indexes (but including TOAST, free space mapping, and visibility mapping).</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a019f9f9f5b664624b9d3f6ba112e048d">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__ldb06fb74ee344941beac28f5b1eedec2">pg_total_relation_size(oid)<p id="EN-US_TOPIC_0000001098671154__a1cb0f0b0e65949aeb760a5d84fd96dd5"><a name="EN-US_TOPIC_0000001098671154__ldb06fb74ee344941beac28f5b1eedec2"></a><a name="ldb06fb74ee344941beac28f5b1eedec2"></a>Description: Specifies the disk space used by the table with a specified OID, including the index and the compressed data.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a3ddf029c502143da8f4b9884047aebf9">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__lf22100b4dfd8495789e23701250df208">pg_total_relation_size(regclass)<p id="EN-US_TOPIC_0000001098671154__a7560858b96fc4be0bea566e8f0c6dcfd"><a name="EN-US_TOPIC_0000001098671154__lf22100b4dfd8495789e23701250df208"></a><a name="lf22100b4dfd8495789e23701250df208"></a>Description: Specifies the total disk space used by the specified table, including all indexes and TOAST data.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ade7c6651990d48898077a6983ebb1cbf">Return type: bigint</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l0fb2ac1785a0483aa2c38934cfc6b098">pg_total_relation_size(text)<p id="EN-US_TOPIC_0000001098671154__a7e4e36f9265242ab9c4b36191120ef44"><a name="EN-US_TOPIC_0000001098671154__l0fb2ac1785a0483aa2c38934cfc6b098"></a><a name="l0fb2ac1785a0483aa2c38934cfc6b098"></a>Description: Specifies the disk space used by the table with a specified name, including the index and the compressed data. The table name can be schema-qualified.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a193de2485a834bd782d45f015c927c76">Return type: bigint</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__ab15fff7915324bbabcc889b2368a36bc">Note: <strong id="EN-US_TOPIC_0000001098671154__b8423527062020">pg_total_relation_size</strong> receives the OID or name of a table or a compressed table, and returns the sizes of the data, related indexes, and the compressed table in bytes.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098671154__s7031ed06ef834ecc843ba39f48ae145f"><h4 class="sectiontitle">Database Object Position Functions</h4><ul id="EN-US_TOPIC_0000001098671154__ue88017ba18b44309b65fa915f3ba8ad4"><li id="EN-US_TOPIC_0000001098671154__lac3234ee8f734b7c82f8d5fb60074fe0">pg_relation_filenode(relation regclass)<p id="EN-US_TOPIC_0000001098671154__a4b0fd600cb1a4cd483b71997841aacf3"><a name="EN-US_TOPIC_0000001098671154__lac3234ee8f734b7c82f8d5fb60074fe0"></a><a name="lac3234ee8f734b7c82f8d5fb60074fe0"></a>Description: Specifies the ID of a filenode with the specified relationship.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a306a46f7d018474caf7ddcc9370402fc">Return type: oid</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a824e687d8c0b4f5eb1d6cf65c06e050d">Description: <strong id="EN-US_TOPIC_0000001098671154__b842352706112144">pg_relation_filenode</strong> receives the OID or name of a table, index, sequence, or compressed table, and returns the filenode number allocated to it. The filenode is the basic component of the file name used by the relationship. For most tables, the result is the same as that of <strong id="EN-US_TOPIC_0000001098671154__b821619511363">pg_class.relfilenode</strong>. For the specified system directory, <strong id="EN-US_TOPIC_0000001098671154__b842352706103326">relfilenode</strong> is <strong id="EN-US_TOPIC_0000001098671154__b842352706103331">0</strong> and this function must be used to obtain the correct value. If a relationship that is not stored is transmitted, such as a view, this function returns <strong id="EN-US_TOPIC_0000001098671154__b185968212916">NULL</strong>.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098671154__l627fbe316b3449eea9323761c33c7571">pg_relation_filepath(relation regclass)<p id="EN-US_TOPIC_0000001098671154__a39f002f73bfc42a59730aee5de1b879c"><a name="EN-US_TOPIC_0000001098671154__l627fbe316b3449eea9323761c33c7571"></a><a name="l627fbe316b3449eea9323761c33c7571"></a>Description: Specifies the name of a file path with the specified relationship.</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a3bf0e902aabc47feb2235a9ccfb76001">Return type: text</p>
|
|
<p id="EN-US_TOPIC_0000001098671154__a151f2d3500074540bdb2e24f9dbe7d01">Description: <strong id="EN-US_TOPIC_0000001098671154__b842352706112154">pg_relation_filepath</strong> is similar to <strong id="EN-US_TOPIC_0000001098671154__b842352706112157">pg_relation_filenode</strong>, except that <strong id="EN-US_TOPIC_0000001098671154__b84235270611223">pg_relation_filepath</strong> returns the whole file path name for the relationship (relative to the data directory <strong id="EN-US_TOPIC_0000001098671154__b103964271107">PGDATA</strong> of the database cluster).</p>
|
|
</li></ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0052.html">System Administration Functions</a></div>
|
|
</div>
|
|
</div>
|
|
|