PostgreSQL 创建帐号,数据库,权限,备份,恢复

来源:互联网 发布:淘宝怎么买分期手机 编辑:程序博客网 时间:2024/05/31 06:22

创建用户 xxxx1,密码 xxxx,创建数据库 xxxx2,赋予 xxxx1 在 xxxx2 上的所有权限。

# sudo --u postgres
$ psql
postgres# 
CREATE USER xxxx1 WITH PASSWORD 'xxxx';
postgres# 
CREATE DATABASE xxxx2;
postgres# 
GRANT ALL PRIVILEGES ON DATABASE xxxx2 to xxxx1;


备份

pg_dump -h localhost -U Username dbName  -t tableName > ./gps.bak

恢复

psql -h localhost -U UserName -d dbName< ./Desktop/1.backup


从文或流中导入到数据库(copy from)

FOLDER=20120710_newfor file_a in ${FOLDER}/*; do  cat $file_a|psql -h localhost -U map -d dev -c "copy gps_histories_all (vehicle_no, longitude, latitude, speed, direction, "time") FROM stdin with delimiter ';';"done


原创粉丝点击