Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2531042
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: 数据库开发技术

2012-05-29 14:03:47

使用psql连接远程数据库:

PostgreSQL命令行界面:“开始--PostgreSQL 9.1--SQL Shell(psql)”

点击(此处)折叠或打开

  1. psql -h remote_server -U username -d database

以下是通过psql连接到远程主机123.123.123.123上的postgres数据库,使用的用户名是postgres

点击(此处)折叠或打开

  1. Server [localhost]: psql -h 123.123.123.123 -U postgres -d postgres
  2. Database [postgres]: postgres
  3. Port [5432]: 5432
  4. Username [postgres]: postgres
  5. psql (9.1.3)
  6. 输入 "help" 来获取帮助信息.

  7. postgres=# select current_user;
  8.  current_user
  9. --------------
  10.  postgres
  11. (1 行记录)

连接数据库后,我们可能希望查看有多少个数据库,某个数据库中有多少表,每个表的字段有哪些。下面,我们对比mysql和PostgreSQL进行说明:


  1. mysql: SHOW TABLES
  2. postgresql: \d
  3. postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';

  4. mysql: SHOW DATABASES
  5. postgresql: \l
  6. postgresql: SELECT datname FROM pg_database;

  7. mysql: SHOW COLUMNS
  8. postgresql: \d table
  9. postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

  10. mysql: DESCRIBE TABLE
  11. postgresql: \d+ table
  12. postgresql: SELECT column_name FROM information_schema.columns WHERE table_name ='table';

备份与还原操作:
(待续)





阅读(4248) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~