pg psql命令

linux下使用psql命令操作数据库

下面主要用到了insert into  ,pg_dump  , pg_restore 命令

按步骤走

su postgres                          切换指定用户

pg_restore -d mydb /mnt/mydb.backup                        mydb指定数据库     mydb.backup    恢复的文件

ALTER TABLE table1 RENAME TO table2;             给表重命名  把表1改成表2

insert into table1  select name,age,height from student where add_time <'2013-10-01';    insert into 的使用   table1必须存在

select * into table1 from student where name like '%杉%';      select into的使用    talbe1必须不存在 把查询到的数据插入到table1

psql -d xxx                          xxx指定数据库

dt                                     查看当前数据库非系统表

c   xx            切换指定db;

select * from student;                           注意一定带上分号 ";" 表示命令的结束

q           退出psql模式

备份指定表

pg_dump --host localhost --port 5432 --username "sqluser" --format custom --blobs --encoding UTF8 --ignore-version --verbose 数据库 -t 表 --file /mnt/11.backup

恢复指定表

pg_restore -d 数据库 /mnt/11.backup 

原文地址:https://www.cnblogs.com/sheapchen/p/3376576.html