欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

PostgreSQL中的刪除列操作是什么

本篇內(nèi)容主要講解“PostgreSQL中的刪除列操作是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“PostgreSQL中的刪除列操作是什么”吧!

創(chuàng)新互聯(lián)服務(wù)項目包括太湖網(wǎng)站建設(shè)、太湖網(wǎng)站制作、太湖網(wǎng)頁制作以及太湖網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,太湖網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到太湖省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

創(chuàng)建數(shù)據(jù)表

[local:/data/run/pg12]:5120 pg12@testdb=# create table t_drop(id int);
CREATE TABLE
[local:/data/run/pg12]:5120 pg12@testdb=# insert into t_drop select generate_series(1,10000000);
INSERT 0 10000000
[local:/data/run/pg12]:5120 pg12@testdb=# 
[local:/data/run/pg12]:5120 pg12@testdb=#  SELECT pg_size_pretty( pg_relation_size( 't_drop' ) );
 pg_size_pretty 
----------------
 346 MB
(1 row)

新增列

[local:/data/run/pg12]:5120 pg12@testdb=# \timing on
Timing is on.
[local:/data/run/pg12]:5120 pg12@testdb=# ALTER TABLE t_drop ADD COLUMN c1 text  DEFAULT md5( random()::text );
ALTER TABLE
Time: 45769.146 ms (00:45.769)
[local:/data/run/pg12]:5120 pg12@testdb=# SELECT pg_size_pretty( pg_relation_size( 't_drop' ) );
 pg_size_pretty 
----------------
 651 MB
(1 row)
Time: 0.840 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

新增列后,占用空間達到了651MB.

刪除列

[local:/data/run/pg12]:5120 pg12@testdb=# alter table t_drop drop c1;
ALTER TABLE
Time: 2.886 ms
[local:/data/run/pg12]:5120 pg12@testdb=# SELECT pg_size_pretty( pg_relation_size( 't_drop' ) );
 pg_size_pretty 
----------------
 651 MB
(1 row)
Time: 1.788 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

刪除列,但空間沒有釋放.

數(shù)據(jù)字典

[local:/data/run/pg12]:5120 pg12@testdb=# \d pg_attribute
              Table "pg_catalog.pg_attribute"
    Column     |   Type    | Collation | Nullable | Default 
---------------+-----------+-----------+----------+---------
 attrelid      | oid       |           | not null | 
 attname       | name      |           | not null | 
 atttypid      | oid       |           | not null | 
 attstattarget | integer   |           | not null | 
 attlen        | smallint  |           | not null | 
 attnum        | smallint  |           | not null | 
 attndims      | integer   |           | not null | 
 attcacheoff   | integer   |           | not null | 
 atttypmod     | integer   |           | not null | 
 attbyval      | boolean   |           | not null | 
 attstorage    | "char"    |           | not null | 
 attalign      | "char"    |           | not null | 
 attnotnull    | boolean   |           | not null | 
 atthasdef     | boolean   |           | not null | 
 atthasmissing | boolean   |           | not null | 
 attidentity   | "char"    |           | not null | 
 attgenerated  | "char"    |           | not null | 
 attisdropped  | boolean   |           | not null | 
 attislocal    | boolean   |           | not null | 
 attinhcount   | integer   |           | not null | 
 attcollation  | oid       |           | not null | 
 attacl        | aclitem[] |           |          | 
 attoptions    | text[]    | C         |          | 
 attfdwoptions | text[]    | C         |          | 
 attmissingval | anyarray  |           |          | 
Indexes:
    "pg_attribute_relid_attnam_index" UNIQUE, btree (attrelid, attname)
    "pg_attribute_relid_attnum_index" UNIQUE, btree (attrelid, attnum)
[local:/data/run/pg12]:5120 pg12@testdb=# select attrelid,attname,atttypid,attisdropped from pg_attribute where attrelid = 't_drop'::regclass;
 attrelid |           attname            | atttypid | attisdropped 
----------+------------------------------+----------+--------------
   994249 | tableoid                     |       26 | f
   994249 | cmax                         |       29 | f
   994249 | xmax                         |       28 | f
   994249 | cmin                         |       29 | f
   994249 | xmin                         |       28 | f
   994249 | ctid                         |       27 | f
   994249 | id                           |       23 | f
   994249 | ........pg.dropped.2........ |        0 | t
(8 rows)
Time: 0.896 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

查看數(shù)據(jù)字典,發(fā)現(xiàn)刪除的c1列變?yōu)閜g.dropped.2,邏輯標記為刪除.
使用vacuum/vacuum full回收空間.

[local:/data/run/pg12]:5120 pg12@testdb=# vacuum t_drop;
VACUUM
Time: 2510.368 ms (00:02.510)
[local:/data/run/pg12]:5120 pg12@testdb=# SELECT pg_size_pretty( pg_relation_size( 't_drop' ) );
 pg_size_pretty 
----------------
 651 MB
(1 row)
Time: 0.718 ms
[local:/data/run/pg12]:5120 pg12@testdb=# vacuum full t_drop;
VACUUM
Time: 7996.658 ms (00:07.997)
[local:/data/run/pg12]:5120 pg12@testdb=# SELECT pg_size_pretty( pg_relation_size( 't_drop' ) );
 pg_size_pretty 
----------------
 346 MB
(1 row)
Time: 1.258 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

但數(shù)據(jù)字典仍保留刪除列的信息

[local:/data/run/pg12]:5120 pg12@testdb=# select attrelid,attname,atttypid,attisdropped from pg_attribute where attrelid = 't_drop'::regclass;
 attrelid |           attname            | atttypid | attisdropped 
----------+------------------------------+----------+--------------
   994249 | tableoid                     |       26 | f
   994249 | cmax                         |       29 | f
   994249 | xmax                         |       28 | f
   994249 | cmin                         |       29 | f
   994249 | xmin                         |       28 | f
   994249 | ctid                         |       27 | f
   994249 | id                           |       23 | f
   994249 | ........pg.dropped.2........ |        0 | t
(8 rows)
Time: 0.757 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

新增列,查看數(shù)據(jù)字典

[local:/data/run/pg12]:5120 pg12@testdb=# ALTER TABLE t_drop ADD COLUMN c1 text  DEFAULT md5( random()::text );
ALTER TABLE
Time: 24483.254 ms (00:24.483)
[local:/data/run/pg12]:5120 pg12@testdb=# select attrelid,attname,atttypid,attisdropped from pg_attribute where attrelid = 't_drop'::regclass;
 attrelid |           attname            | atttypid | attisdropped 
----------+------------------------------+----------+--------------
   994249 | tableoid                     |       26 | f
   994249 | cmax                         |       29 | f
   994249 | xmax                         |       28 | f
   994249 | cmin                         |       29 | f
   994249 | xmin                         |       28 | f
   994249 | ctid                         |       27 | f
   994249 | id                           |       23 | f
   994249 | ........pg.dropped.2........ |        0 | t
   994249 | c1                           |       25 | f
(9 rows)
Time: 1.067 ms
[local:/data/run/pg12]:5120 pg12@testdb=#

到此,相信大家對“PostgreSQL中的刪除列操作是什么”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

網(wǎng)頁標題:PostgreSQL中的刪除列操作是什么
路徑分享:http://chinadenli.net/article28/jhgsjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃網(wǎng)站排名域名注冊品牌網(wǎng)站設(shè)計網(wǎng)站改版用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)