---
# System prepended metadata

title: 重建PostgreSQL table
tags: [PostgreSQL, 維運]

---

# 重建PostgreSQL table

###### tags: `維運` `PostgreSQL`

因為table scheme資料毀損，所以須重建table

1. 匯出redemine_project table from devopsdb
```
postgres@devopsdb-64997d8ccf-8cvqj:~$ pg_dump -t redmine_project devopsdb > redmine_project.sql
```

2. Drop redemine_project table

3. 匯入 redmine_project.sql
```
postgres=# \connect devopsdb
You are now connected to database "devopsdb" as user "postgres".
devopsdb=# \i /var/lib/postgresql/redmine_project.sql
SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE SEQUENCE
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
COPY 0
 setval
--------
   2149
(1 row)

ALTER TABLE
devopsdb=#
```
4. 確認table是否有重建完成