Just sharing what I have learned about postgres recently. Here is a part of basic commands you may need. Enjoy it!

  Before try the following commands, please ensure you are followed the introductions on github: https://github.com/thoughtworks/vagrant-postgresql.

1. boot up a database by virtualBox and vagrant

script/database up

2. login the postgres

psql -h hostname -U username

     psql -h localhost -U postgres

   

Note: password: it depends. Maybe "postgres" or "password" or "secret".

3. list all the databases

\l or \list

4. list all the roles

\du

5. for help

"\h" or "\?" or "help"

it depends on the context.

6. create a new database

create database databasename

create database mydb;

list all the databases, and you can find the database just created.

7. connect to the database

\c databasename

\c mydb

or \connect mydb

8. create a table

create table users (user_id bigserial primary key, user_name varchar(20) not null );

     Note: auto_increment is a MySQL feature. Postgres uses serial columns for the same purpose.

9. list tables in  connected database

\dt

10. list the schema of a table

\d tablename

     \d users

11. get current database name

select current_database();

……

Hopefully these commands will help you getting started with postgres command line quickly. For more information, please feel free to discuss with me or turn to these website:

http://www.postgresql.org/docs/9.1/static/app-psql.html,

http://www.commandprompt.com/ppbook/c4890

Postgres Basic Commands for Beginners的更多相关文章

  1. Network Basic Commands Summary

    Network Basic Commands Summary set or modify hostname a)     temporary ways hostname NEW_HOSTNAME, b ...

  2. Linux--Introduction and Basic commands(Part one)

    Welcome to Linux world! Introduction and Basic commands--Part one J.C 2018.3.11 Chapter 1 What Is Li ...

  3. CheeseZH: Octave basic commands

    1.Basic Operations 5+6 3-2 5*8 1/2 2^6 1 == 2 %false ans = 0 1 ~= 2 %true ans = 1 1 && 0 %AN ...

  4. linux basic commands

    1. man - an interface to the on-line reference manuals $man man 2. apt - advanced package tool SEE A ...

  5. kafka basic commands

    kafka-server-start.sh config/server.properties & kafka-server-stop.sh kafka-topics.sh    --creat ...

  6. Kali Basic Configuration

    1:Kali Version root@kali-node01:~# cat /etc/os-release PRETTY_NAME="Kali GNU/Linux Rolling" ...

  7. 13 Basic Cat Command Examples in Linux

    FROM: http://www.tecmint.com/13-basic-cat-command-examples-in-linux/ The cat (short for “concatenate ...

  8. 【转】Redis入门

    Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案. Redis从它的许多竞争继承来的三个主要特点: Redis数据库完全在内存中,使用磁盘仅用 ...

  9. ubuntu包管理

    查看某个文件属于哪个包dpkg -S add-apt-repository 包名software-properties-common命令名/usr/bin/add-apt-repository/usr ...

随机推荐

  1. 多线程查询FTP Server上的文件

    情形是这样的,最近做一个自动化的项目,当batch跑成功了,FTP Server上会有特定的生成文件.但是不确定是什么时候会有,大概是batch跑完了5分钟之内吧,所以在脚本里设置检查点的时候,需要每 ...

  2. $(function(){})与 (function(){})() (function($){})() 的区别

    1. $(function(){ }) 或 jQuery(function(){ }) 此函数也可以写成 jQuery(function(){ }), 用于存放操作DOM对象的代码,执行其中代码时DO ...

  3. epoll在socket通信中的应用

    当服务器需要服务多个客户时,需要使用并发通信,实现并发通信有以下几种方法: 1.在服务器中fork子进程来为每个客户服务  具体可参考http://www.cnblogs.com/ggjucheng/ ...

  4. Java程序员面试宝典——重要习题整理

    1.下面程序的输出结果是() public class Test { public static void main(String[] args) { int j = 0 ; for(int i = ...

  5. 智能指针(二):shared_ptr实现原理

    前面讲到auto_ptr有个很大的缺陷就是所有权的转移,就是一个对象的内存块只能被一个智能指针对象所拥有.但我们有些时候希望共用那个内存块.于是C++ 11标准中有了shared_ptr这样的智能指针 ...

  6. tool debug Android phonegap app

    phonegap debug 最近发现了一个可以调试phonegap的工具  在Google浏览器上调试Android真机的APP  这是好啊!!!跟Mac上的Safari 浏览器一样调试iOS 的A ...

  7. ubuntu多网卡绑定

    这是最近碰到这个问题,需要将两张网卡绑定,共用一个IP,实现冗余效果.实际上linux双网卡的绑定模式有7中,而在这里常用的是 active-backup linux有七种网卡绑定模式:0. roun ...

  8. 网络设备模拟器 GNS3

    https://www.gns3.com/support/docs/linux-installation sudo dpkg --add-architecture i386 sudo add-apt- ...

  9. Java Excel POI

    1.使用 String toFileName = "E:\\sheet1.xlsx"; String fromFileName = "E:\\sheet2.xlsx&qu ...

  10. php的命名规范

    1.类 类名每一个单词首字母大写,如类名StudentCourse. 2.常量 常量名所有字母大写,单词间用下划线分隔,如常量名NULL.TRUE.FALSE.ROOT_PATH等. 3.变量 为了保 ...