zoukankan      html  css  js  c++  java
  • Postgres Basic Commands for Beginners

      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 );

         Noteauto_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

  • 相关阅读:
    第二章 java内存区域与内存溢出异常
    TCP实现可靠传输
    Tomcat的类加载架构
    浅析Synchronized
    设计数据库
    http和https
    IOC容器的依赖注入
    IOC容器初始化
    深入理解Java内存模型
    单例应该这么写
  • 原文地址:https://www.cnblogs.com/penghongwei/p/3227101.html
Copyright © 2011-2022 走看看