Postgres常用命令总结
来源:互联网 发布:手机淘宝卖家账号注册 编辑:程序博客网 时间:2024/05/19 21:01
一:命令行备份与恢复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
- Postgres常用命令总结
- Postgres 常用命令
- Postgres常用命令
- postgres常用命令
- postgres数据库常用命令
- Postgres注入总结
- postgres运维总结
- 整理使用postgres需要设置和常用命令
- postgres
- postgres
- postgres
- postgres
- Postgres
- linux 下 postgres 的使用总结
- Postgres数据库备份与恢复总结
- 常用命令总结
- 常用命令总结
- 常用命令总结
- Web开发(1)
- adb uninstall
- Web开发(2)
- Web开发(3)
- c++ volatile用法
- Postgres常用命令总结
- Java内联函数
- java swing 中使用JFileChooser读取Excel并进行解析
- 使用JMS接口接入WebSphere MQ消息
- 动态申请内存与释放时的异常---Byte越界(CheckBytes函数的内部机制)
- Java web开发中读取资源文件
- Android2.3 中如何使用GPU硬件加速
- cannot open file "mfc42u.lib"的解决方案
- oracle dba系统管理的有用sql