shell下postgres下批量修改数据库里面所有表的所属主 - Go语言中文社区

shell下postgres下批量修改数据库里面所有表的所属主


直接在postgres用户下操作

将数据库名,写入1脚本中

#vi 1
#!/bin/bash 

for i in `cat b`
do
psql xc_hzh_nanxun -c "alter table $i owner to hzhnanxun"
done

使用dt,查看数据库里面所有的表

#vi 11.txt #将数据库里面的表复制到11.txt里面(也可以直接写成11)

 public | resource_url                       | table | xchzhlinan
 public | role                               | table | xchzhlinan
 public | send_ets_focusinfo                 | table | xchzhlinan
 public | site_inner_outer                   | table | xchzhlinan
 public | site_post_info                     | table | xchzhlinan
 public | spid_article                       | table | xchzhlinan
 public | spid_article_content               | table | xchzhlinan
 public | spid_article_reply                 | table | xchzhlinan
 public | spid_task                          | table | xchzhlinan
 public | spid_task_account                  | table | xchzhlinan
 public | spid_task_syn                      | table | xchzhlinan
 public | spid_task_syn_all                  | table | xchzhlinan

$awk ‘{print $3}’ 11.txt #只显示出打印的表名
在这里插入图片描述
awk ‘{print $3}’ 11.txt>12.txt #将11.txt中的表名导入到12.txt中
在这里插入图片描述
#cat 12.txt #查看b脚本是否只有表名

postgres@shhkfys:~$ cat b                                  #查看脚本中,需要修改的表名。

postgres@shhkfys:~$ cat 1                                  #核对a脚本里面,需要修改的数据库名和表名,是否有误。

postgres@shhkfys:~$ bash -x 1                            #执行脚本1,更改数据库表的用户名

在这里插入图片描述

查看脚本执行结果。查看用户是否有权限查看数据库表的内容

postgres@shhkfys:~$ psql
psql.bin (9.4.1)
Type "help" for help.

No entry for terminal type "xterm";
using dumb terminal settings.
postgres=# c xc_hzh_nanxun
You are now connected to database "xc_hzh_nanxun" as user "postgres".
xc_hzh_nanxun=# c - hzhnanxun
Password for user hzhnanxun: 
You are now connected to database "xc_hzh_nanxun" as user "hzhnanxun".
xc_hzh_nanxun=> dt

在这里插入图片描述

xc_hzh_nanxun=> select * from cust_site;

在这里插入图片描述
修改完成。

批量添加cmdb系统的采集器名称

#!/bin/bash
for i in `cat x`
do
weixin=',weixinStorer_6000'
psql yun -c 'update asset_server set describe=CONCAT(describe,'"'$weixin'"') where ip='"'$i'"';'
done

x内容如下:

postgres@hdslave20:~$ cat x
1.1.1.1
1.1.1.2
1.1.1.3
1.1.1.4
1.1.1.5
1.1.1.6
版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_40907977/article/details/108387814
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢