Postgres Basic Commands for Beginners

时间:2022-01-14 21:45:07

  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

Postgres Basic Commands for Beginners

2. login the postgres

psql -h hostname -U username

     psql -h localhost -U postgres

   Postgres Basic Commands for Beginners

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

3. list all the databases

\l or \list

Postgres Basic Commands for Beginners

4. list all the roles

\du

Postgres Basic Commands for Beginners

5. for help

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

it depends on the context.

6. create a new database

create database databasename

create database mydb;

Postgres Basic Commands for Beginners

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

Postgres Basic Commands for Beginners

7. connect to the database

\c databasename

\c mydb

or \connect mydb

Postgres Basic Commands for Beginners

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.

Postgres Basic Commands for Beginners

9. list tables in  connected database

\dt

Postgres Basic Commands for Beginners

10. list the schema of a table

\d tablename

     \d users

Postgres Basic Commands for Beginners

11. get current database name

select current_database();

Postgres Basic Commands for Beginners

……

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&quot ...

  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. JSP 使用

    JSP教程: http://www.w3cschool.cc/jsp/jsp-tutorial.html jsp语法: 任何语言都有自己的语法,JAVA中有,JSP虽然是在JAVA上的一种应用,但是依 ...

  2. JS 动态加载脚本 执行回调_转

    关于在javascript里面加载其它的js文件的问题可能很多人都遇到过,但很多朋友可能并不知道怎么判断我们要加载的js文件是否加载完成,如果没有加载完成我们就调用文件里面的函数是不会成功的.本文讲解 ...

  3. Data Base Oracle下载及安装

    Oracle   下载及安装 一.官方下地址:   http://www.oracle.com/technetwork/database/enterprise-edition/downloads/in ...

  4. ORA-01722: invalid number,ORA-12801

    SQL: SELECT /*+ parallel(a,32) */ a.id ,a.data_date ,a.mobile_num ,a.mobile_code ,b.prov AS mobile_p ...

  5. 前端跨域方案-跨域请求代理(node服务)

    前端开发人员在本地搭建node服务,调用接口首先走本地服务,然后转发到api站点,node服务代码如下: var express = require('express'), request = req ...

  6. window/mac系统关机

    window/mac系统关机 #ifdef Q_OS_WIN #include "windows.h" #endif void OnShutDown() { #ifdef Q_OS ...

  7. (转)Spring Boot (十):邮件服务

    http://www.ityouknow.com/springboot/2017/05/06/spring-boot-mail.html Spring Boot 仍然在狂速发展,才几个多月没有关注,现 ...

  8. weex用阿里矢量图

    首先这段代码来自 zwwill在github上的 weex网易严选项目 他是在utils下封装了一个方法 let utilFunc = { initIconFont () { let domModul ...

  9. 一般xcode报错

    下面这图报找不到FMDtabaseQueue,其实是把文件拖入xcode的时候xcode没有把.m文件添加进工程路径 解决办法:build phases-> compile sources &q ...

  10. 针对Jigsaw勒索软件的解锁工具

    针对Jigsaw勒索软件的解锁工具 据了解, 用户的计算机系统一旦感染了勒索软件Jigsaw,如果用户没有在一个小时之内支付赎金(0.4个比特币,价值约为150美金),那么恶意软件将会把系统中的上千份 ...