Postgres常用命令总结

 一:命令行备份与恢复postgres数据库
 
①:首先切换为postgres用户
su postgres


②:备份名为host的数据库到临时文件host.dump
pg_dump -W host > /tmp/host.dump


③:从备份文件infile中导入数据到数据库名为dbname的数据库
psql dbname < infile
 


二:更新数据表中的某条数据记录
 
①:以postgres用户登录到数据库中
sudo su postgres -c psql template1


②:连接一个数据库数据库
\c databasename


③:查询config表中的数据
select configid,key from config;


④:跟新value字段的值
update config set value='29' where configid='50ce7b11-53c3-4e5f-e02-

e4df37af51aa18';

 

 

三:创建postgres数据库

 
①:以postgres用户登录

    su postgres    输入postgres用户的密码

 

 ②:创建数据库

    createdb host

 


 四:制作PostgreSQL脚本,创建postgres中文数据库

 

echo "install database..."
#install postgres from source
process=$(cat /etc/passwd |grep postgres)
if [ -z "$process" ]; then

   useradd postgres
else
   echo "postgres:Postgres1" >/tmp.txt
   chpasswd < /tmp.txt
   rm -f /tmp.txt
fi
process=$(cat /etc/postgresql/8.4/main/pg_hba.conf |grep 0/0)
proces1=$(cat /etc/ssh/sshd_config |grep "allowusers admin")
if [ -z "$process" ] &&  [ -z "$proces1" ]; then
   echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/8.4/main/pg_hba.conf
   sed -i 's/#listen_addresses/listen_addresses/g'

/etc/postgresql/8.4/main/postgresql.conf
  sed -i 's/localhost/*/g' /etc/postgresql/8.4/main/postgresql.conf
fi

#change password for user :postgres in database
/etc/init.d/postgresql-8.4 restart
sleep 5
su - postgres << EOF
psql -c "alter user postgres with password 'Postgres1'" <<E2
E2
psql -c "create database cloud with encoding='SQL_ASCII' LC_COLLATE='C'

LC_CTYPE='C' template template0 CONNECTION LIMIT = -1;" <<E3
E3
EOF

学习网址:http://wiki.ubuntu.org.cn/PostgreSQL

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值