时间:2021-07-01 10:21:17 帮助过:3人阅读
一、 安装脚本:
前提: 已安装好psql客户端
#curl firxiao.com/sh/recreate_views.sh -o recreate_views.sh|chmod +x recreate_views.sh
操作步骤如下:
二、 配置脚本:
编辑脚本 将以下内容更改为你自己 然后保存退出
###config HOST="ip or hostname" DB_NAME="dbname" DB_USER="user" DB_PASSWORD="password" ###
三、 查看帮助
#./recreate_views.sh Useage: recreate_views.sh: -b <view_name> #backup view and dependent objects Useage: recreate_views.sh: -d <view_name> #delete view and dependent objects Useage: recreate_views.sh: -c "<sql>" #exec custom sql command Useage: recreate_views.sh: -r <view_name> #restore view and dependent objects
四、 测试是否能正常连接
#./recreate_views.sh -c "\dt" List of relations Schema | Name | Type | Owner --------+-----------+-------+------- public | change_me | table | root (1 row)
五、 备份视图
#./recreate_views.sh -b v_change_me backup v_change_me to v_change_me_bak.sql backup v_change_me_too to v_change_me_bak.sql
将自动将删除的视图及依赖备份到 视图名_bak.sql
六、删除视图
#./recreate_views.sh -d v_change_me 注意: 递归删除 视图 v_change_me_too DROP VIEW
更改表字段类型
#./recreate_views.sh -c "ALTER TABLE change_me ALTER too_short TYPE VARCHAR(30);" ALTER TABLE
七、恢复已删视图
#./recreate_views.sh -r v_change_me SET SET SET SET SET SET SET 错误: 视图 "v_change_me" 不存在 SET CREATE VIEW SET SET SET SET SET SET SET 错误: 视图 "v_change_me_too" 不存在 SET CREATE VIEW
八、查看表类型
./recreate_views.sh -c "\d v_change_me" View "public.v_change_me" Column | Type | Modifiers -----------+-----------------------+----------- too_short | character varying(30) |
至此已完成了对表字段类型的更改
postgresql 重建视图脚本
标签: