<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EDB 技術專欄 彙整 - 歐立威科技</title>
	<atom:link href="https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/</link>
	<description>歐立威科技 Omniwaresoft｜全方位企業級開源軟體解決方案</description>
	<lastBuildDate>Tue, 22 Apr 2025 05:50:12 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.4</generator>

<image>
	<url>https://www.omniwaresoft.com.tw/wp-content/uploads/2022/12/android-icon-192x192-1.png</url>
	<title>EDB 技術專欄 彙整 - 歐立威科技</title>
	<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">242464019</site>	<item>
		<title>偷跑篇：EDB11 新的小功能—Pragma Autonomous Transaction</title>
		<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/edb-pragma-autonomous-transaction/</link>
		
		<dc:creator><![CDATA[Omni]]></dc:creator>
		<pubDate>Fri, 17 Aug 2018 09:46:28 +0000</pubDate>
				<category><![CDATA[EDB 技術專欄]]></category>
		<category><![CDATA[技術專欄]]></category>
		<category><![CDATA[EDB]]></category>
		<guid isPermaLink="false">http://www.omniwaresoft.com.tw/?p=13414</guid>

					<description><![CDATA[關聯式資料庫有交易的概念，確保多用戶進行資料的查詢/異動有一個規範。有一些 Oracle 用戶會使用到更進階的交易，叫做 Autonomous Transaction，能夠從當前交易中「再」分支的一個交易。]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="13414" class="elementor elementor-13414" data-elementor-post-type="post">
						<section data-particle_enable="false" data-particle-mobile-disabled="false" class="elementor-section elementor-top-section elementor-element elementor-element-3ade4691 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="3ade4691" data-element_type="section">
						<div class="elementor-container elementor-column-gap-thegem"><div class="elementor-row">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7ed9c2b7" data-id="7ed9c2b7" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-630a477f flex-horizontal-align-default flex-horizontal-align-tablet-default flex-horizontal-align-mobile-default flex-vertical-align-default flex-vertical-align-tablet-default flex-vertical-align-mobile-default elementor-widget elementor-widget-text-editor" data-id="630a477f" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
												<div class="elementor-text-editor elementor-clearfix">
						<p style="text-align: right;">本文授權轉載自<a href="http://ravenonhill.blogspot.com/">渡鴉之丘</a></p>
<p><a href="https://docs.postgresql.tw/tutorial/advanced-features/transactions"><span style="font-weight: 400;">關聯式資料庫有交易的概念</span></a><span style="font-weight: 400;">，確保多用戶進行資料的查詢/異動有一個規範。有一些 Oracle 用戶會使用到更進階的交易，叫做 Autonomous Transaction，能夠從當前交易中「再」分支的一個交易。</span></p>
<p><span style="font-weight: 400;">通常聽到這功能的用途，是有一些作業需要避免會被當前作業的成敗所影響，最常見的就是額外的 Log 紀錄。</span><br>
<span style="font-weight: 400;">這種功能在 PostgreSQL 裡面其實一直都從缺（可能是因為 PGSQL 社群上開發的人都偏好扁平式的系統設計＆規劃？），但是在一些習慣 Oracle 的用戶來說，已經有一些既定的規範，非得使用這種功能才行。</span></p>
<p><span style="font-weight: 400;">之前</span><a href="http://ravenonhill.blogspot.com/2017/10/postgresql-96-autonomous-transaction.html"><span style="font-weight: 400;">已經有一次筆記</span></a><span style="font-weight: 400;">，演練這個功能的 Workaround 手法，不過現在（2018 年 8 月），下一版的 EDB Postgres 企業版 v11 總算補上了這個「Oracle 相容」功能～</span></p>
<p><span style="font-weight: 400;">這邊直接仿照</span><a href="https://oracle-base.com/articles/misc/autonomous-transactions"><span style="font-weight: 400;">一篇 Oracle 的教學</span></a><span style="font-weight: 400;">，直接拿來套用，直接驗證 EDB 的 Oracle 語法相容性～</span></p>
<p><span style="font-weight: 400;">首先建測試表&nbsp;</span></p>
<table>
<tbody>
<tr>
<td>
<pre style="text-align: left;">edb=# CREATE TABLE test (
id NUMBER NOT NULL,
description VARCHAR2(50) NOT NULL
);
CREATE TABLE
edb=#</pre>
</td>
</tr>
</tbody>
</table>
<p>然後，套用上面這篇的 Oracle 範例：這邊唯一的小小差別，就是 EDB / PGSQL 的操作指令 psql 預設的是交易模式是 Autocommit，在 Oracle 的 SQL*Plus 預設需要執行 Commit 才行～故這邊使用 begin &#8230; commit/rollback 來具體弄成一個交易。</p>
<table>
<tbody>
<tr>
<td>
<pre style="text-align: left;">edb=# begin;
BEGIN
edb=# INSERT INTO test (id, description) VALUES (1, 'Description for 1');
INSERT 0 1
edb=# INSERT INTO test (id, description) VALUES (2, 'Description for 2');
INSERT 0 1
edb=# DECLARE
edb-# &nbsp;&nbsp;PRAGMA AUTONOMOUS_TRANSACTION;
edb$# BEGIN
edb$# &nbsp;&nbsp;FOR i IN 3 .. 10 LOOP
edb$# &nbsp;&nbsp;&nbsp;&nbsp;INSERT INTO test (id, description)
edb$# &nbsp;&nbsp;&nbsp;&nbsp;VALUES (i, 'Description for ' || i);
edb$# &nbsp;&nbsp;END LOOP;
edb$# &nbsp;&nbsp;COMMIT;
edb$# END;
EDB-SPL Procedure successfully completed
edb=# SELECT * FROM test;
 id | &nbsp;&nbsp;&nbsp;description
----+--------------------
  1 | Description for 1
  2 | Description for 2
  3 | Description for 3
  4 | Description for 4
  5 | Description for 5
  6 | Description for 6
  7 | Description for 7
  8 | Description for 8
  9 | Description for 9
 10 | Description for 10
(10 rows)
edb=# ROLLBACK;
ROLLBACK
edb=# SELECT * FROM test;
 id | &nbsp;&nbsp;&nbsp;description
----+--------------------
  3 | Description for 3
  4 | Description for 4
  5 | Description for 5
  6 | Description for 6
  7 | Description for 7
  8 | Description for 8
  9 | Description for 9
 10 | Description for 10
(8 rows)
edb=#</pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">上面可見，透過 AUTONOMOUS_TRANSACTION 所塞的資料，並沒有因為這邊的 Rollback 而被取消。而當前交易所塞進去的前兩筆資料，則因為 Rollback 而取消了。</span></p>
<p><span style="font-weight: 400;">另外，這邊可以看到，此處使用的是 Oracle 相容語法，並不是用在 PGSQL 原生的 Function 或是 </span><a href="https://www.postgresql.org/docs/11/static/sql-createprocedure.html"><span style="font-weight: 400;">PGSQL 11 將引進能處理交易的 Procedure 功能</span></a><span style="font-weight: 400;">，但是看到 Procedure 功能導入，就可以猜測，後續原生的 PGSQL 語法也應該會支援了。</span></p>
<p><span style="font-weight: 400;">這篇是使用 EDB 公司在八月初發行的 Beta 測試版進行練習的，不過通常 PGSQL 的軟體到了 Beta 階段，功能上就已經固定下來了，主要都是在除錯而已～所以這篇叫做偷跑篇（同時也是一則流水帳、拖杳篇）～～</span></p>
<p><span style="font-weight: 400;">當然，EDB 11 不會只有這個改進而已（也會包含 </span><a href="https://h50146.www5.hpe.com/products/software/oe/linux/mainstream/support/lcc/pdf/PostgreSQL_11_New_Features_beta1_en_20180525-1.pdf"><span style="font-weight: 400;">PGSQL 11 新增改進</span></a><span style="font-weight: 400;">），等到正式出來，再來看看要挑什麼來練習吧～</span></p>
<p><span style="font-weight: 400;">參考資料</span><br>
<a href="https://oracle-base.com/articles/misc/autonomous-transactions"><span style="font-weight: 400;">ORACLE-BASE &#8211; Autonomous Transactions</span></a><br>
<a href="https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/autonotransaction_pragma.htm"><span style="font-weight: 400;">PL/SQL Language Elements &#8211; AUTONOMOUS_TRANSACTION Pragma</span></a><br>
<a href="https://get.enterprisedb.com/docs/EDB_Postgres_Advanced_Server_v11.0_Release_Notes.pdf?_ga=2.4586099.1176918063.1533916181-255214656.1531489476"><span style="font-weight: 400;">EPASv11 release notes</span></a><br>
<a href="https://blog.2ndquadrant.com/postgresql-11-server-side-procedures-part-1/"><span style="font-weight: 400;">PostgreSQL 11 &#8211; Server-side Procedures (Part 1) | 2ndQuadrant Blog</span></a><br>
<a href="https://www.cybertec-postgresql.com/en/tech-preview-postgresql-11-create-procedure/"><span style="font-weight: 400;">Tech preview: PostgreSQL 11 &#8211; CREATE PROCEDURE &#8211; Cybertec</span></a><br>
<a href="https://blog.dbi-services.com/postgresql-11-procedures-are-coming/"><span style="font-weight: 400;">PostgreSQL 11 : Procedures are coming &#8211; Blog dbi services</span></a><br>
<a href="https://h50146.www5.hpe.com/products/software/oe/linux/mainstream/support/lcc/pdf/PostgreSQL_11_New_Features_beta1_en_20180525-1.pdf"><span style="font-weight: 400;">PostgreSQL 11 New Features With Examples (Beta 1) &#8211; Noriyoshi Shinoda ( HPE Japan Co, Ltd. )</span></a></p>							</div>
										</div>
				</div>
					</div>
		</div>
					</div></div>
		</section>
				</div>
		]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">13414</post-id>	</item>
		<item>
		<title>EDB Postgres 10 企業版裡面的 Partitioned Table 系統表</title>
		<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/edb-10-partitionedtable/</link>
		
		<dc:creator><![CDATA[Omni]]></dc:creator>
		<pubDate>Tue, 06 Feb 2018 09:00:48 +0000</pubDate>
				<category><![CDATA[EDB 技術專欄]]></category>
		<category><![CDATA[EDB]]></category>
		<category><![CDATA[Techcolumn]]></category>
		<guid isPermaLink="false">https://goodpoint-studio.com/?p=13015</guid>

					<description><![CDATA[以下參考 Postgres 10 Partitioned Table 原生語法範例與 EDB 10 企業版範例，分別建立 Partitioned Table。然後查詢 Postgres 10 新增的原生系統表與企業版的 Oracle 相容 Data Dictionary。

首先是利用 EDB 10 企業版語法建立 Partitioned Table，然後分別查找原生 Partitioned Table 系統表 pg_partitioned_table 與企業版的 ALL_PART_TABLES]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="13015" class="elementor elementor-13015" data-elementor-post-type="post">
						<section data-particle_enable="false" data-particle-mobile-disabled="false" class="elementor-section elementor-top-section elementor-element elementor-element-5be53ead elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="5be53ead" data-element_type="section">
						<div class="elementor-container elementor-column-gap-thegem"><div class="elementor-row">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-52f44042" data-id="52f44042" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-4a698fdf flex-horizontal-align-default flex-horizontal-align-tablet-default flex-horizontal-align-mobile-default flex-vertical-align-default flex-vertical-align-tablet-default flex-vertical-align-mobile-default elementor-widget elementor-widget-text-editor" data-id="4a698fdf" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
												<div class="elementor-text-editor elementor-clearfix">
						<p style="text-align: right;">本文授權轉載自<a href="http://ravenonhill.blogspot.com/">渡鴉之丘</a></p>
<p><span style="font-weight: 400;">在 PostgreSQL 10 引進了原生的 Partitioned Table 語法，EDB 的企業版在很久之前就有 Tartitioned Table，各自也都有相關的系統表。那麼，這些系統表有相互含括嗎？</span></p>
<p><span style="font-weight: 400;">這裡紀錄一下這個問題，然後順便偷懶，當作新的 Partitioned Table 語法功能筆記～</span></p>
<hr>
<p><span style="font-weight: 400;">以下參考 </span><a href="https://www.postgresql.org/docs/10/static/sql-createtable.html"><span style="font-weight: 400;">Postgres 10 Partitioned Table 原生語法範例</span></a><span style="font-weight: 400;">與 </span><a href="https://www.enterprisedb.com/docs/en/10.0/Ora_Compat_Dev_Guide/Database_Compatibility_for_Oracle_Developers_Guide.1.105.html#pID0E0SZB0HA"><span style="font-weight: 400;">EDB 10 企業版範例</span></a><span style="font-weight: 400;">，分別建立 Partitioned Table。然後查詢 Postgres 10 新增的原生系統表與企業版的 Oracle 相容 Data Dictionary。</span></p>
<p><span style="font-weight: 400;">首先是利用 EDB 10 企業版語法建立 Partitioned Table，然後分別查找原生 Partitioned Table 系統表 pg_partitioned_table 與企業版的 ALL_PART_TABLES&nbsp;</span></p>
<table style="height: 3779px;" width="612">
<tbody>
<tr>
<td style="text-align: left;">
<pre><span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">-- 驗明正身～</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">select version();</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span style="font-weight: 400;">-------------------------------------------------------------------------------------------------------------</span>
<span style="font-weight: 400;"> EnterpriseDB 10.1.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18), 64-bit</span>
<span style="font-weight: 400;">(1 row)</span>
<span style="font-weight: 400;">edb=# </span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">CREATE TABLE sales</span>
<span style="font-weight: 400;">(</span>
<span style="font-weight: 400;">dept_no number,</span>
<span style="font-weight: 400;">part_no varchar2,</span>
<span style="font-weight: 400;">country varchar2(20),</span>
<span style="font-weight: 400;">date date,</span>
<span style="font-weight: 400;">amount number</span>
<span style="font-weight: 400;">)</span>
<span style="font-weight: 400;">PARTITION BY LIST(country)</span>
<span style="font-weight: 400;">(</span>
<span style="font-weight: 400;">PARTITION europe VALUES('FRANCE', 'ITALY'),</span>
<span style="font-weight: 400;">PARTITION asia VALUES('INDIA', 'PAKISTAN'),</span>
<span style="font-weight: 400;">PARTITION americas VALUES('US', 'CANADA')</span>
<span style="font-weight: 400;">);</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">edb=#</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">\x</span>
<span style="font-weight: 400;">Expanded display is on.</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">select * from pg_partitioned_table;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]-+------</span>
<span style="font-weight: 400;">partrelid &nbsp;&nbsp;&nbsp;&nbsp;| 16384</span>
<span style="font-weight: 400;">partstrat &nbsp;&nbsp;&nbsp;&nbsp;| l</span>
<span style="font-weight: 400;">partnatts &nbsp;&nbsp;&nbsp;&nbsp;| 1</span>
<span style="font-weight: 400;">partattrs &nbsp;&nbsp;&nbsp;&nbsp;| 3</span>
<span style="font-weight: 400;">partclass &nbsp;&nbsp;&nbsp;&nbsp;| 3126</span>
<span style="font-weight: 400;">partcollation | 100</span>
<span style="font-weight: 400;">partexprs &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">partnullorder | 0</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">select * from all_part_tables ;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]-------------+-------------</span>
<span style="font-weight: 400;">owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| SALES</span>
<span style="font-weight: 400;">partitioning_type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| LIST</span>
<span style="font-weight: 400;">subpartitioning_type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">partition_count &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 3</span>
<span style="font-weight: 400;">def_subpartition_count &nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">partitioning_key_count &nbsp;&nbsp;&nbsp;| 1</span>
<span style="font-weight: 400;">subpartitioning_key_count | </span>
<span style="font-weight: 400;">status &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| VALID</span>
<span style="font-weight: 400;">def_tablespace_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_initial_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_min_extents &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_max_extents &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_freelist_groups &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">def_compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">def_buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| DEFAULT</span>
<span style="font-weight: 400;">ref_ptn_constraint_name &nbsp;&nbsp;| </span>
<span style="font-weight: 400;">interval &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|</span>
<span style="font-weight: 400;">edb=#</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">select * from all_tab_partitions ;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]------+------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| SALES</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| EUROPE</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES IN ('FRANCE', 'ITALY')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 33</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| sales_europe</span>
<span style="font-weight: 400;">-[ RECORD 2 ]------+------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| SALES</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| ASIA</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES IN ('INDIA', 'PAKISTAN')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 35</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| sales_asia</span>
<span style="font-weight: 400;">-[ RECORD 3 ]------+------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| SALES</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| AMERICAS</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES IN ('US', 'CANADA')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 30</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| sales_americas</span>
<span style="font-weight: 400;">edb=#</span>
<span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">\d+ sales</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">Table "public.sales"</span>
<span style="font-weight: 400;"> Column &nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">Type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| Collation | Nullable | Default | Storage &nbsp;| Stats target | Description</span>
<span style="font-weight: 400;">---------+-----------------------------+-----------+----------+---------+----------+--------------+-------------</span>
<span style="font-weight: 400;"> dept_no | numeric &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| main </span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> part_no | character varying &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| extended | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> country | character varying(20) &nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| extended | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> date</span> <span style="font-weight: 400;">| timestamp without time zone | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| plain</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> amount &nbsp;| numeric &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| main </span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;">Partition key: LIST (country)</span>
<span style="font-weight: 400;">Partitions: sales_americas FOR VALUES IN ('US', 'CANADA'),</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">sales_asia FOR VALUES IN ('INDIA', 'PAKISTAN'),</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">sales_europe FOR VALUES IN ('FRANCE', 'ITALY')</span>
<span style="font-weight: 400;">edb=#</span></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">上面可見，透過 Oracle 相容語法建立的 Partitioned Table 也會在 pg_partitioned_table 裡面註冊相關資訊。</span><br>
<span style="font-weight: 400;">下面切換到 postgres database 裡面，用原生語法建立 Partitioned Table。一樣用兩種</span></p>
<table style="height: 4932px;" width="771">
<tbody>
<tr>
<td style="text-align: left;">
<pre><span style="font-weight: 400;">edb=# </span><span style="font-weight: 400;">\c postgres</span>
<span style="font-weight: 400;">You are now connected to database "postgres" as user "enterprisedb".</span>
<span style="font-weight: 400;">postgres=#</span>
<span style="font-weight: 400;">postgres=# --PGSQL10 原生語法</span>
<span style="font-weight: 400;">postgres=# </span>
<span style="font-weight: 400;">postgres=# </span><span style="font-weight: 400;">CREATE TABLE measurement_year_month (</span>
<span style="font-weight: 400;">logdate &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">date not null,</span>
<span style="font-weight: 400;">peaktemp &nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">int,</span>
<span style="font-weight: 400;">unitsales &nbsp;&nbsp;</span> <span style="font-weight: 400;">int</span>
<span style="font-weight: 400;">) PARTITION BY RANGE (EXTRACT(YEAR FROM logdate), EXTRACT(MONTH FROM logdate));</span>
<span style="font-weight: 400;">CREATE TABLE measurement_ym_older</span>
<span style="font-weight: 400;">PARTITION OF measurement_year_month</span>
<span style="font-weight: 400;">FOR VALUES FROM (MINVALUE, MINVALUE) TO (2016, 11);</span>
<span style="font-weight: 400;">CREATE TABLE measurement_ym_y2016m11</span>
<span style="font-weight: 400;">PARTITION OF measurement_year_month</span>
<span style="font-weight: 400;">FOR VALUES FROM (2016, 11) TO (2016, 12);</span>
<span style="font-weight: 400;">CREATE TABLE measurement_ym_y2016m12</span>
<span style="font-weight: 400;">PARTITION OF measurement_year_month</span>
<span style="font-weight: 400;">FOR VALUES FROM (2016, 12) TO (2017, 01);</span>
<span style="font-weight: 400;">CREATE TABLE measurement_ym_y2017m01</span>
<span style="font-weight: 400;">PARTITION OF measurement_year_month</span>
<span style="font-weight: 400;">FOR VALUES FROM (2017, 01) TO (2017, 02);</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">CREATE TABLE</span>
<span style="font-weight: 400;">postgres=#</span>
<span style="font-weight: 400;">postgres=# </span><span style="font-weight: 400;">select * from pg_partitioned_table;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]-+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</span>
<span style="font-weight: 400;">partrelid &nbsp;&nbsp;&nbsp;&nbsp;| 16408</span>
<span style="font-weight: 400;">partstrat &nbsp;&nbsp;&nbsp;&nbsp;| r</span>
<span style="font-weight: 400;">partnatts &nbsp;&nbsp;&nbsp;&nbsp;| 2</span>
<span style="font-weight: 400;">partattrs &nbsp;&nbsp;&nbsp;&nbsp;| 0 0</span>
<span style="font-weight: 400;">partclass &nbsp;&nbsp;&nbsp;&nbsp;| 3123 3123</span>
<span style="font-weight: 400;">partcollation | 0 0</span>
<span style="font-weight: 400;">partexprs &nbsp;&nbsp;&nbsp;&nbsp;| ({FUNCEXPR :funcid 2021 :funcresulttype 701 :funcretset false :funcvariadic false :funcformat 0 :funccollid 0 :inputcollid 100 :args ({CONST :consttype 25 :consttypmod -1 :constcollid 100 :constlen -1 :constbyval false :constisnull false :location 152 :constvalue 8 [ 32 0 0 0 121 101 97 114 ]} {VAR :varno 1 :varattno 1 :vartype 1114 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 162}) :location 144} {FUNCEXPR :funcid 2021 :funcresulttype 701 :funcretset false :funcvariadic false :funcformat 0 :funccollid 0 :inputcollid 100 :args ({CONST :consttype 25 :consttypmod -1 :constcollid 100 :constlen -1 :constbyval false :constisnull false :location 180 :constvalue 9 [ 36 0 0 0 109 111 110 116 104 ]} {VAR :varno 1 :varattno 1 :vartype 1114 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 191}) :location 172})</span>
<span style="font-weight: 400;">partnullorder | 0</span>
<span style="font-weight: 400;">postgres=#</span>
<span style="font-weight: 400;">postgres=# </span><span style="font-weight: 400;">select * from all_part_tables ;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]-------------+-----------------------</span>
<span style="font-weight: 400;">owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YEAR_MONTH</span>
<span style="font-weight: 400;">partitioning_type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| RANGE</span>
<span style="font-weight: 400;">subpartitioning_type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">partition_count &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 4</span>
<span style="font-weight: 400;">def_subpartition_count &nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">partitioning_key_count &nbsp;&nbsp;&nbsp;| 2</span>
<span style="font-weight: 400;">subpartitioning_key_count | </span>
<span style="font-weight: 400;">status &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| VALID</span>
<span style="font-weight: 400;">def_tablespace_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_initial_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_min_extents &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_max_extents &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_freelist_groups &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">def_logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">def_compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">def_buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| DEFAULT</span>
<span style="font-weight: 400;">ref_ptn_constraint_name &nbsp;&nbsp;| </span>
<span style="font-weight: 400;">interval &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">postgres=#</span>
<span style="font-weight: 400;">postgres=# </span><span style="font-weight: 400;">select * from all_tab_partitions ;</span>
<span style="font-weight: 400;">-[ RECORD 1 ]------+-------------------------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YEAR_MONTH</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YM_OLDER</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES FROM (MINVALUE, MINVALUE) TO ('2016', '11')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 54</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| measurement_ym_older</span>
<span style="font-weight: 400;">-[ RECORD 2 ]------+-------------------------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YEAR_MONTH</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YM_Y2016M11</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES FROM ('2016', '11') TO ('2016', '12')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 48</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| measurement_ym_y2016m11</span>
<span style="font-weight: 400;">-[ RECORD 3 ]------+-------------------------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YEAR_MONTH</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YM_Y2016M12</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES FROM ('2016', '12') TO ('2017', '1')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 47</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| measurement_ym_y2016m12</span>
<span style="font-weight: 400;">-[ RECORD 4 ]------+-------------------------------------------------------</span>
<span style="font-weight: 400;">table_owner &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| ENTERPRISEDB</span>
<span style="font-weight: 400;">schema_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| PUBLIC</span>
<span style="font-weight: 400;">table_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YEAR_MONTH</span>
<span style="font-weight: 400;">composite &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">partition_name &nbsp;&nbsp;&nbsp;&nbsp;| MEASUREMENT_YM_Y2017M01</span>
<span style="font-weight: 400;">subpartition_count | 0</span>
<span style="font-weight: 400;">high_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| FOR VALUES FROM ('2017', '1') TO ('2017', '2')</span>
<span style="font-weight: 400;">high_value_length &nbsp;| 46</span>
<span style="font-weight: 400;">partition_position | </span>
<span style="font-weight: 400;">tablespace_name &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">pct_free &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_used &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">ini_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_trans &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">initial_extent &nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">next_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">min_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">max_extent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">pct_increase &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">freelists &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">freelist_groups &nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">logging &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">compression &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NONE</span>
<span style="font-weight: 400;">num_rows &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0</span>
<span style="font-weight: 400;">empty_blocks &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_space &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">chain_cnt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">avg_row_len &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">sample_size &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">last_analyzed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">buffer_pool &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| </span>
<span style="font-weight: 400;">global_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| YES</span>
<span style="font-weight: 400;">user_stats &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| NO</span>
<span style="font-weight: 400;">backing_table &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| measurement_ym_y2017m01</span>
<span style="font-weight: 400;">postgres=#</span>
<span style="font-weight: 400;">postgres=# </span><span style="font-weight: 400;">\d+ measurement_year_month</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">Table "public.measurement_year_month"</span>
<span style="font-weight: 400;"> &nbsp;Column &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">Type &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| Collation | Nullable | Default | Storage | Stats target | Description</span>
<span style="font-weight: 400;">-----------+-----------------------------+-----------+----------+---------+---------+--------------+-------------</span>
<span style="font-weight: 400;"> logdate &nbsp;&nbsp;| timestamp without time zone | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| not null | &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| plain &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> peaktemp &nbsp;| integer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| plain &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;"> unitsales | integer &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| &nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">| plain &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">|</span>
<span style="font-weight: 400;">Partition key: RANGE (date_part('year'::text, logdate), date_part('month'::text, logdate))</span>
<span style="font-weight: 400;">Partitions: measurement_ym_older FOR VALUES FROM (MINVALUE, MINVALUE) TO ('2016', '11'),</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">measurement_ym_y2016m11 FOR VALUES FROM ('2016', '11') TO ('2016', '12'),</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">measurement_ym_y2016m12 FOR VALUES FROM ('2016', '12') TO ('2017', '1'),</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span style="font-weight: 400;">measurement_ym_y2017m01 FOR VALUES FROM ('2017', '1') TO ('2017', '2')</span>
<span style="font-weight: 400;">postgres=#</span></pre>
</td>
</tr>
</tbody>
</table>
<p>上面可以看到，原生語法建立的 Partitioned Table 也可以在企業版的 data dictionary 查看得到。這讓 Partitioned Table 狀況查看在企業版更為容易～</p>
<p>此外，兩個 Partitioned Table 語法的內部架構上應該還是有一點點差異，從 pg_partitioned_table 可以略窺一二。<br>
既然這篇要順道紀錄 Partitioned Table 功能，就再紀錄一下以下幾點：</p>
<ul>
<li>Oracle 語法利用 Partitioned Name 管理，不會直接看 Table Partitions 名稱；建立 PGSQL 10 partitioned table 則會自動指定 Partitioned Name</li>
</ul>
<ul>
<li>在 EDB10 裡面，企業版語法提供 List/Range/Hash 三種，而原生的支援 List/Range 兩種（PGSQL 11 將引入 Hash Partitioned Table 支援）</li>
</ul>
<ul>
<li>PGSQL 10 的 Partitioned Table Index 建立目前還是需要逐個對個別 Table Partitions 建立；此外，目前還沒支援類似 Oracle 的 Global Index 這種跨 Partition 的 Unique Constraint 物件</li>
</ul>
<ul>
<li>目前的 Partitioned Table 還不支援 Upsert 功能（INSERT &#8230; ON CONFLICT）；也還沒支援更新 Partitioned Key 欄位的資料（涉及資料的跨表格搬遷）</li>
</ul>
<ul>
<li>查詢上，還是需要調整 constraint_exclusion 為 partition 才能讓查詢把 Partitioned Key 納入執行計畫考量。不過這已經預設好了，其實不用管它～</li>
</ul>
<ul>
<li>舊方法的 Table Partitioning 還是能用的！先前的幾個 Partitioned Table 管理套件都還是能在 PGSQL 10 使用（例如，<a href="https://github.com/keithf4/pg_partman">pg_partman</a> 或是 <a href="https://github.com/ankane/pgslice">pgslice</a> 等擴充套件）</li>
</ul>
<ul>
<li>在 pgAdmin4 v2.1 裡面，正式支援 Partitioned Table 的資訊。呈現上，只會呈現母表，點開之後，才會看到列舉 Partitions，點右鍵就可以建立 Index。</li>
</ul>
<p><img fetchpriority="high" data-recalc-dims="1" class="wp-image-13021 aligncenter" src="https://i0.wp.com/www.omniwaresoft.com.tw/wp-content/uploads/2018/02/EDB-Postgres-10-%E4%BC%81%E6%A5%AD%E7%89%88%E8%A3%A1%E9%9D%A2%E7%9A%84-Partitioned-Table-%E7%B3%BB%E7%B5%B1%E8%A1%A81.png?resize=692%2C369&#038;ssl=1" alt="EDB Postgres 10 企業版裡面的 Partitioned Table 系統表1" width="692" height="369"></p>
<p>最後，根據 <a href="https://postgresweekly.com/issues/240">PostgresWeekly&nbsp; 2018 年一月號電子報</a>發出的訊息，<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=8b08f7d4820fd7a8ef6152a9dd8c6e3cb01e5f9">PGSQL 11 的 Partitioned Table 將會</a><a href="http://paquier.xyz/postgresql-2/postgres-11-partition-index/">改善建立 Index 的功能</a>，可以對母表下達 Index 建立指令，就自動幫所有 Table Partitions 建立完畢；以及<a href="https://www.depesz.com/2018/01/22/waiting-for-postgresql-11-allow-update-to-move-rows-between-partitions/">更新 Partitioned Key 欄位資料</a>（跨 Table Partition 資料異動）。目前 Partitoined Table 還正在優化中，後續會不斷有更多強化功能（例如，跟 Foreign data Wrapper 整合～），請各位拭目以待。</p>
<p>最後，看來 EDB 企業版與 PGSQL 原生功能的整合性還不錯，功能都不會延遲跟上～<br>
參考資料</p>
<p>舊方法的 Partitioned Table：還是能用的</p>
<p><a href="https://ravenonhill.blogspot.com/2017/06/postgresql-9x-partitioned-table-diy.html">之前的筆記</a><br>
<a href="http://alexc168.blogspot.tw/2012/08/postgresql-partition-table.html">艾力克斯札記: PostgreSQL Partition Table</a><br>
<a href="https://medium.com/@StreamBright/creating-partitions-automatically-in-postgresql-7006d68c0fbb">Creating partitions automatically in PostgreSQL – StreamBright – Medium</a><br>
<a href="https://blog.heroku.com/handling-very-large-tables-in-postgres-using-partitioning">Handling Very Large Tables in Postgres Using Partitioning | Heroku</a></p>
<p>EDB 10 企業版手冊<br>
PostgreSQL 10 手冊</p>							</div>
										</div>
				</div>
					</div>
		</div>
					</div></div>
		</section>
				</div>
		]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">13015</post-id>	</item>
		<item>
		<title>EDB-Loader 工具的簡單範例</title>
		<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/edb-loadertools-examples/</link>
		
		<dc:creator><![CDATA[Omni]]></dc:creator>
		<pubDate>Tue, 06 Feb 2018 08:41:55 +0000</pubDate>
				<category><![CDATA[EDB 技術專欄]]></category>
		<category><![CDATA[技術專欄]]></category>
		<category><![CDATA[EDB]]></category>
		<category><![CDATA[Techcolumn]]></category>
		<guid isPermaLink="false">https://goodpoint-studio.com/?p=12989</guid>

					<description><![CDATA[Brandon 相仿 Oracle 的 ...]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="12989" class="elementor elementor-12989" data-elementor-post-type="post">
						<section data-particle_enable="false" data-particle-mobile-disabled="false" class="elementor-section elementor-top-section elementor-element elementor-element-7b6d2b8e elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="7b6d2b8e" data-element_type="section">
						<div class="elementor-container elementor-column-gap-thegem"><div class="elementor-row">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-36c9c952" data-id="36c9c952" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-3b6b20d0 flex-horizontal-align-default flex-horizontal-align-tablet-default flex-horizontal-align-mobile-default flex-vertical-align-default flex-vertical-align-tablet-default flex-vertical-align-mobile-default elementor-widget elementor-widget-text-editor" data-id="3b6b20d0" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
												<div class="elementor-text-editor elementor-clearfix">
						<p style="text-align: right;">Brandon</p>
<p>相仿 Oracle 的 SQL*Loader 工具，是EDB 用來載入大筆資料的工具。<br>
設置方式幾乎與 SQL*Loader 一樣，一樣是設置 Control File，藉此載入 csv 資料進資料庫。<br>
以下將在 EDB 10 以及 Oracle XE 11 使用一樣的 Control File 以及資料，對照 Loader 的使用指令。</p>
<hr>
<p><span style="font-weight: 400;">一份表格的 SQL，在 EDB 與 Oracle 通用：&nbsp;</span></p>
<table>
<tbody>
<tr>
<td>
<pre style="text-align: left;">create table testtab( myin int PRIMARY KEY,
str varchar2(1000),
mylabel int
);</pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">把表格建立到 EDB 跟 Oracle 裡面，下面就開始匯入資料。</span><br>
<span style="font-weight: 400;">首先，先有一份 csv 資料以及欄位，並設置 Control File，最後執行指令即可。</span><br>
<span style="font-weight: 400;">以下資料，放在 CSV 文字檔裡面，命名為 </span><span style="font-weight: 400;">demo.csv</span></p>
<table style="height: 129px;" width="455">
<tbody>
<tr>
<td>
<pre style="text-align: left;"><span style="font-weight: 400;">1,"apple",10</span>
<span style="font-weight: 400;">2,"apple2",10</span>
<span style="font-weight: 400;">3,"book",</span>
<span style="font-weight: 400;">4,"banana",20</span>
<span style="font-weight: 400;">5,"banana2",20</span></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;"><span style="font-weight: 400;">下面是 EDB 使用的 Control File， </span><span style="font-weight: 400;">demo.ctl </span>這個資料包含一個沒有值的格子，需要下面的 Control file 設定才能運作。</span></p>
<table style="height: 206px;" width="446">
<tbody>
<tr>
<td style="text-align: left;">
<pre><span style="font-weight: 400;">LOAD DATA</span>
<span style="font-weight: 400;"> &nbsp;INFILE &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'demo.csv'</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;BADFILE &nbsp;&nbsp;&nbsp;&nbsp;'emp_fixed.bad'</span>
<span style="font-weight: 400;"> &nbsp;</span><span style="font-weight: 400; color: #ff0000;">APPEND</span>
<span style="font-weight: 400;"> &nbsp;INTO TABLE testtab</span>
<span style="font-weight: 400;"> &nbsp;&nbsp; FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' </span>
<span style="color: #ff0000;"><span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;</span><span style="font-weight: 400;">TRAILING NULLCOLS</span></span>
<span style="font-weight: 400;"> &nbsp;(</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;myin,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;str,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;mylabel</span>
<span style="font-weight: 400;"> &nbsp;)</span></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">裡面幾個非必要修飾詞，如 append（指定資料累加到表格裡面），trailing nullcols（允許 csv 最末一欄沒有值的資料）。大致上跟 Oracle SQL*Loader 差不多。下面也會直接套用在 Oracle XE 裡面。</span><br>
<span style="font-weight: 400;">接著就載入資料：在這裡用上面的檔案，分別在 EDB 與 Oracle 上執行</span><br>
EDB</p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre>bash-$ source /opt/edb/as10/pgplus_env.sh
bash-$ edbldr -h localhost -p 5444 -d edb USERID=enterprisedb/password CONTROL=/your/path/demo.ctl
EDB*Loader: Copyright (c) 2007-2017, EnterpriseDB Corporation.
Successfully processed (5) records
bash-$</pre>
</td>
</tr>
</tbody>
</table>
<p>Oracle</p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre>bash-$ sqlldr userid/password@tnsname control=/your/path/demo.ctl
SQL*Loader: Release 11.2.0.2.0 - Production on Fri Jan 26 09:47:02 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. &nbsp;All rights reserved.
ORA-28002: the password will expire within 7 days
Commit point reached - logical record count 6
bash-$</pre>
</td>
</tr>
</tbody>
</table>
<p>兩<span style="font-weight: 400;">者都匯入成功。查看一下</span><br>
EDB</p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre>edb=# select * from testtab;
myin | &nbsp;&nbsp;str &nbsp;&nbsp;| mylabel
------+---------+---------
 &nbsp;&nbsp;&nbsp;1 | apple &nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10
 &nbsp;&nbsp;&nbsp;2 | apple2 &nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10
 &nbsp;&nbsp;&nbsp;3 | book &nbsp;&nbsp;&nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;4 | banana &nbsp;| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20
 &nbsp;&nbsp;&nbsp;5 | banana2 | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20
(5 rows)
edb=#</pre>
</td>
</tr>
</tbody>
</table>
<p>Oracle</p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre>SQL&gt; select * from testtab;
&nbsp;&nbsp;&nbsp;&nbsp; MYIN
----------
STR
--------------------------------------------------------------------------------
&nbsp; MYLABEL
----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1
apple
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2
apple2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10
&nbsp;&nbsp;&nbsp;&nbsp; MYIN
----------
STR
--------------------------------------------------------------------------------
&nbsp; MYLABEL
----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3
book
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4
banana
&nbsp;&nbsp;&nbsp;&nbsp; MYIN
----------
STR
--------------------------------------------------------------------------------
&nbsp; MYLABEL
----------
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5
banana2
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20
SQL&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>我<span style="font-weight: 400;">們可以看到，Oracle 的 SQL*Loader 使用的流程幾乎可以無須調整，便能在 EnterpriseDB 企業版的 EDB*Loader 執行。</span><br>
<span style="font-weight: 400;">在此提醒一點，EDB*Loader 不可以跨版本使用，只可以對相同版本的資料庫匯入。</span><br>
<span style="font-weight: 400;">最後來看看原生的 Postgres 如何使用內建的 COPY 指令載入資料。不過這指令要求檔案要在資料庫主機上面，因為該指令會透過資料庫服務的 OS 帳號去讀檔案：</span></p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre><span style="font-weight: 400;">COPY testtab FROM '/your/full/path/demo.csv' </span>
<span style="font-weight: 400;">WITH (FORMAT csv ,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp; DELIMITER ',' ,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp; NULL '' ,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp; HEADER false ,</span>
<span style="font-weight: 400;"> &nbsp;&nbsp;&nbsp;&nbsp; QUOTE '"');</span></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">這個指令有一些 CSV 的設定選項，例如分隔符號、檔案編碼之類的，詳情可以到</span><a href="https://www.postgresql.org/docs/current/static/sql-copy.html"><span style="font-weight: 400;">手冊頁面</span></a><span style="font-weight: 400;">查看。</span><br>
<span style="font-weight: 400;">此外，使用 COPY 指令時，記得要把「</span><span style="font-weight: 400; color: #ff0000;">最後一行 Enter</span><span style="font-weight: 400;">」拿掉！！不然會匯入失敗的</span></p>
<table>
<tbody>
<tr>
<td style="text-align: left;">
<pre><span style="font-weight: 400;">edb=# -- 注意檔案最後多空一行</span>
<span style="font-weight: 400;">edb=# \! cat /your/full/path/demo.csv</span>
<span style="font-weight: 400;">1,"apple",10</span>
<span style="font-weight: 400;">2,"apple2",10</span>
<span style="font-weight: 400;">3,"book",</span>
<span style="font-weight: 400;">4,"banana",20</span>
<span style="font-weight: 400;">5,"banana2",20</span>
<span style="font-weight: 400;">edb=# COPY testtab FROM '/your/full/path/demo.csv'</span>
<span style="font-weight: 400;">WITH (FORMAT csv ,</span>
<span style="font-weight: 400;"> &nbsp;</span> <span style="font-weight: 400;">DELIMITER ',' ,</span>
<span style="font-weight: 400;"> &nbsp;</span> <span style="font-weight: 400;">NULL '' ,</span>
<span style="font-weight: 400;"> &nbsp;</span> <span style="font-weight: 400;">HEADER false ,</span>
<span style="font-weight: 400;"> &nbsp;</span> <span style="font-weight: 400;">QUOTE '"');</span>
<span style="font-weight: 400;">ERROR: &nbsp;missing data for column "str"</span>
<span style="font-weight: 400;">CONTEXT: &nbsp;COPY testtab, </span><span style="font-weight: 400; color: #ff0000;">line 6: ""</span>
<span style="font-weight: 400;">edb=#</span></pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-weight: 400;">上面出現神秘的檔案第六行，就是多一個 Enter 造成的。不過這個不影響 EDB*Loader～</span><br>
<span style="font-weight: 400;">參考資料</span></p>
<p><a href="https://www.enterprisedb.com/docs/en/10.0/Ora_Tools_Utilities_v10/Database_Compatibility_for_Oracle_Developers_Tools_and_Utilities_Guide.1.04.html#"><span style="font-weight: 400;">EDB Postgres Advanced Server 10.0 Database Compatibility for Oracle Developers Tools and Utilities Guide / 2 EDB*Loader</span></a><br>
<span style="font-weight: 400;">比較 Oracle SQL*Loader：</span><span style="font-weight: 400;">sql loader 用法 &#8211; Google 搜尋</span><br>
<span style="font-weight: 400;">類似工具：&nbsp;</span><span style="font-weight: 400;"><a href="https://github.com/ossc-db/pg_bulkload">pg_bulkload</a>&nbsp;&nbsp;</span><a href="http://pgloader.io/"><span style="font-weight: 400;">pgloader</span></a></p>							</div>
										</div>
				</div>
					</div>
		</div>
					</div></div>
		</section>
				</div>
		]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12989</post-id>	</item>
		<item>
		<title>EDB-Point 即時資料恢復功能與設定</title>
		<link>https://www.omniwaresoft.com.tw/techcolumn/edb-techcolumn/edb-point-in-time-recovery/</link>
		
		<dc:creator><![CDATA[Omni]]></dc:creator>
		<pubDate>Thu, 23 Feb 2017 02:08:05 +0000</pubDate>
				<category><![CDATA[EDB 技術專欄]]></category>
		<category><![CDATA[EDB]]></category>
		<guid isPermaLink="false">https://goodpoint-studio.com/?p=12414</guid>

					<description><![CDATA[資料庫的備份還原機制是必須的，但是總不可能在每個時段做全備份的動作，所以當資料庫必須回復到某一個時間點時，就必須借助PITR(Point-In-Time-Recovery)功能，PITR 在PostgreSQL或EDB都是內建功能，以下就來驗證PITR功能：]]></description>
										<content:encoded><![CDATA[		<div data-elementor-type="wp-post" data-elementor-id="12414" class="elementor elementor-12414" data-elementor-post-type="post">
						<section data-particle_enable="false" data-particle-mobile-disabled="false" class="elementor-section elementor-top-section elementor-element elementor-element-79e6af33 elementor-section-boxed elementor-section-height-default elementor-section-height-default" data-id="79e6af33" data-element_type="section">
						<div class="elementor-container elementor-column-gap-thegem"><div class="elementor-row">
					<div class="elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-24cde3b3" data-id="24cde3b3" data-element_type="column">
			<div class="elementor-widget-wrap elementor-element-populated">
						<div class="elementor-element elementor-element-361960bb flex-horizontal-align-default flex-horizontal-align-tablet-default flex-horizontal-align-mobile-default flex-vertical-align-default flex-vertical-align-tablet-default flex-vertical-align-mobile-default elementor-widget elementor-widget-text-editor" data-id="361960bb" data-element_type="widget" data-widget_type="text-editor.default">
				<div class="elementor-widget-container">
												<div class="elementor-text-editor elementor-clearfix">
						<p></p>
<figure class="wp-block-image aligncenter size-full"><img width="560" height="285" data-recalc-dims="1" src="https://i0.wp.com/www.omniwaresoft.com.tw/wp-content/uploads/2017/02/EDB_Point-In-Time-Recovery.jpg?w=1170&#038;ssl=1" alt="EDB Point In Time Recovery" class="wp-image-30426"></figure>
<p></p>
<p></p>
<p>資料庫的備份還原機制是必須的，但是總不可能在每個時段做全備份的動作，所以當資料庫必須回復到某一個時間點時，就必須借助PITR(Point-In-Time-Recovery)功能，PITR 在PostgreSQL或EDB都是內建功能，以下就來驗證PITR功能：&nbsp;</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">1.設定環境變數(使用root建立database需要的資料夾)</h2>
<p></p>
<p></p>
<p style="font-size:16px">#mkdir -p /tmp/backup<br>#mkdir -p /tmp/archive<br>#chown -R enterprisedb.enterprisedb /tmp/backup<br>#chown -R enterprisedb.enterprisedb /tmp/archive</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">2.更改資料庫設定檔(postgresql.conf)，啟動 archive mode。</h2>
<p></p>
<p></p>
<p>wal_level = archive<br>archive_mode = on<br>archive_command = ‘test ! -f /tmp/archive/%f &amp;&amp; cp %p /tmp/archive/%f’</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">3.重新啟動資料庫服務</h2>
<p></p>
<p></p>
<p>#service ppas-9.4 restart</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">4.建立測試資料表</h2>
<p></p>
<p></p>
<p>#edb-psql -U labuser test<br>edb=#create table lab_table(id number,col varchar2(100));<br>edb=#\q</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">5.資料庫完整備份(fullybackup)</h2>
<p></p>
<p></p>
<p>$pg_basebackup -D /tmp/backup -Ft -z -U enterprisedb -p 5444</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">6.確認完整備份時間(T1)</h2>
<p></p>
<p></p>
<p>edb=#select now();</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">7.新增100筆資料</h2>
<p></p>
<p></p>
<p>edb=#insert into lab_table values (generate_series(1,100),’###’);</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">8.確認異動時間(T2)</h2>
<p></p>
<p></p>
<p>edb=#select now();</p>
<p></p>
<p></p>
<h2 class="wp-block-heading">9.回復至T1時間的資料(此時只有建立好的資料表，無資料)</h2>
<p></p>
<p></p>
<ul class="wp-block-list">
<li>資料庫crash</li>
<li>將資料庫完整備份檔回復到database的目錄</li>
<li>建立並設定conf檔，並可以指定回復時間點</li>
</ul>
<p></p>
<p></p>
<p>restore_command = ‘cp /tmp/archive/%f %p’<br>recovery_target_time = ‘2015-01-01 00:00:00</p>
<p></p>
<p></p>
<ul class="wp-block-list">
<li>啟動資料庫服務</li>
<li>確認lab_table資料為0筆</li>
<li>若想回復至100筆資料，只需重複以上步驟並且在3的時間設定為100筆資料時間即可</li>
</ul>
<p></p>
<p></p>
<h2 class="wp-block-heading" style="font-size:30px">10.完成</h2>
<p></p>							</div>
										</div>
				</div>
					</div>
		</div>
					</div></div>
		</section>
				</div>
		]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12414</post-id>	</item>
	</channel>
</rss>
