差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
database:postgres:alignment [2022/09/25 18:06] tony [How to?] |
database:postgres:alignment [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 54: | 行 54: | ||
d = double alignment (8 bytes on many machines, but by no means all). | d = double alignment (8 bytes on many machines, but by no means all). | ||
</code> | </code> | ||
- | 接著就可以按照前述規則去調整欄位了。型態別名可以參考此[[https://www.postgresql.org/docs/current/datatype.html|link]]。 | + | 接著就可以按照前述規則去調整欄位了。型態別名可以參考此[[https://www.postgresql.org/docs/current/datatype.html|link]]。\\ |
+ | 也可以直接透過以下SQL直接查詢某table的狀態: | ||
+ | <code> | ||
+ | # 替換example_table為你的table即可。 | ||
+ | SELECT a.attname, t.typname, t.typalign, t.typlen | ||
+ | FROM pg_class c | ||
+ | JOIN pg_attribute a ON (a.attrelid = c.oid) | ||
+ | JOIN pg_type t ON (t.oid = a.atttypid) | ||
+ | WHERE c.relname = 'example_table' | ||
+ | AND a.attnum >= 0 | ||
+ | ORDER BY a.attnum; | ||
+ | </code> | ||
+ | 透過上述SQL,可以快速確認調整結果: (需在建index之前測試,不然會不準喔!) | ||
+ | {{:database:postgres:pg_data_alignment_result.png?750|}} | ||
===== Reference ===== | ===== Reference ===== | ||
* [[https://www.enterprisedb.com/postgres-tutorials/data-alignment-postgresql|Data Alignment in PostgreSQL]] | * [[https://www.enterprisedb.com/postgres-tutorials/data-alignment-postgresql|Data Alignment in PostgreSQL]] |