标签:
postgres=# \d+ test Table "public.test" Column | Type | Modifiers | Storage | Stats target | Description --------+-----------------------------+----------------------------------------------------+---------+--------------+------------- id | integer | not null default nextval(‘test_id_seq‘::regclass) | plain | | val | timestamp without time zone | default now() | plain | | Indexes: "test_pkey" PRIMARY KEY, btree (id)
postgres=# CREATE UNIQUE INDEX CONCURRENTLY ON test USING btree(id); CREATE INDEX
postgres=# BEGIN; BEGIN postgres=# ALTER TABLE test DROP CONSTRAINT test_pkey; ALTER TABLE postgres=# ALTER TABLE test ADD CONSTRAINT test_id_idx PRIMARY KEY USING INDEX test_id_idx; ALTER TABLE postgres=# COMMIT; COMMIT
postgres=# \d+ test Table "public.test" Column | Type | Modifiers | Storage | Stats target | Description --------+-----------------------------+----------------------------------------------------+---------+--------------+------------- id | integer | not null default nextval(‘test_id_seq‘::regclass) | plain | | val | timestamp without time zone | default now() | plain | | Indexes: "test_id_idx" PRIMARY KEY, btree (id)
这样的好处是,可以在白天负载低的时候维护主键
PostgreSQL主键膨胀的使用CONCURRENTLY维护
标签:
原文地址:http://my.oschina.net/u/2426299/blog/487913