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. 使用AS3.0代码实现给图片添加滤镜的模糊与斜角效果

    滤镜可应用于任何显示对象(即,从 DisplayObject 类继承的对象), 例如 MovieClip.SimpleButton.TextField 和 Video 对象,以及 BitmapData ...

  2. 【LeetCode】20. Valid Parentheses

    题目:

  3. 图形设备接口(GDI)

    图形设备接口(GDI,Graphics Device Interface)负责在显示器和打印机上显示图形.GDI 是由几百个函数和一些相关的数据类型.宏和结构构成的.Windows 98/NT 中的图 ...

  4. OSGI.NET 插件启动方法

    在使用OSGI.NET框架来开发插件过程中,有时为了测试一个插件,或运行一个插件,需要启动主个插件,如果没有主窗口程序,那么该 如何启动一个插件,而不是再开发一个主窗口程序(那样是不是太麻烦,仅仅是为 ...

  5. J2SE宏观总结

  6. UML的9种图例解析

    摘自: http://blog.csdn.net/fatherican/article/details/44966891 UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现 类与类图 1) 类 ...

  7. select 嵌套查询

    1. SELECT语句的子查询 语法:     SELECT ... FROM (subquery) AS name ... 先创建一个表: CREATE TABLE t1 (s1 INT, s2 C ...

  8. 解决win 7&win xp等系统无法正常用U盘安装或启动

    目前,制作启动U盘通常是用ultraiso,但由于各种硬件设备与系统的更新,导致现在装系统会出现各种错误. 在用ultraiso制作的启动U盘,装XP时,可能找不到引导项:装win7时,可能提示”wi ...

  9. 第四章_PHP基本语法(2)

    1.常量的声明 在PHP中,定义常量使用define()函数来实现 2.魔术常量 名称 作用 __LINE__ 返回文件中的当前行号 __FILE__ 返回该文件的完整路径和文件名 __DIR__ 返 ...

  10. android应用商店完整版源码

    这个是从一个安卓学习的网站上转载过来的,android应用商店完整版源码,大家可以看看一下吧. _op><ignore_js_op> <ignore_js_op>< ...