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. 自定义PageControl样式

    #define iOS7 ([[UIDevice currentDevice].systemVersion doubleValue] >= 7.0) //调用方法 改变PageControl样式 ...

  2. EF,ADO.NET Entity Data Model简要的笔记

    1. 新建一个项目,添加一个ADO.NET Entity Data Model的文件,此文件会生成所有的数据对象模型,如果是用vs2012生的话,在.Designer.cs里会出现“// Defaul ...

  3. ionic goto other page or alert

    有时候需要 调试,这是就需要alert 的...可惜的是我不会angular  所以记录一下 .controller('mainctr', function($scope, $window) { $w ...

  4. HDOJ1010(BFS)

    //为什么bfs不行呢,想不通 #include<cstdio>#include<cstring>#include<queue>using namespace st ...

  5. 注册码 myeclipse6.5-6.8

    package controllersli; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

  6. CSS强制文本在一行内显示若有多余字符则使用省略号表示

    这篇文章主要介绍了强制文本在一行内显示,多余字符使用省略号,设置或检索是否使用一个省略标记(...)标示对象内文本的溢出.对应的脚本特性为textOverflow 设置或检索是否使用一个省略标记(.. ...

  7. verilog中符号位的扩展问题

    以下内容转自 艾米电子 - 使用有符号数,Verilog(http://www.cnblogs.com/yuphone/archive/2010/12/12/1903647.html) Verilog ...

  8. 使用cnpm搭建企业内部私有NPM仓库

    cnpm是企业内部搭建npm镜像和私有npm仓库的开源方案.它同时解决了现有npm架构的一些问题. 为什么企业需要私有NPM 主要有如下理由: 确保npm服务快速.稳定:对于企业来说,上线生产系统的时 ...

  9. .NET中的访问修饰符

    .NET中一共有五种访问修饰符   分别是   public                          公共的,访问权限最高的. private                         ...

  10. (一)、NodeJS (转载)

    NodeJS基础                                                 ------ 转载自阿里巴巴 什么是NodeJS JS是脚本语言,脚本语言都需要一个解 ...