PostgreSQL Learning Logs(I)

Indispensable setups before start

  • postgresql
  • php5
  • phppgadmin

After the installation, PostgreSQL has created a superuser named postgres by default.


At the beginning

  1. Log in as Superuser postgres
    $ sudo su - postgres
    The result shows "postgres@zhejiang12" instead of "lina@zhejiang12".

  2. Entering PostgreSQL
    $ psql
    The default is to enter database postgres.If you wanna go to a specific database, try:
    $ psql -d databasename

  3. Create database
    create database databasename;
    Attention: there is a semicolon at the end!!!

  4. Create new user
    create user username;
    If you want to add password or authority to the user, try:
    alter user username with password '123456';
    alter user with superuser createdb createrole;
    or
    add these infor when creating new user:
    create user username with superuser createdb createrole password '123456';

  5. Delete user or database
    drop user username;
    drop database databasename;


Basic statements

  • Enter PostgreSQL from Terminal:
    $ psql -U username -d databasename


Commands

  • \l
    Check the existing databases.

  • \du
    Check the existing user.

  • \q
    quit psql.


Problems and solutions


  • DESCRIPTION
    psql: FATAL: Ident authentication failed for user "cassie"

  • SOLUTION
    gedit file pg_hba.conf located at /etc/postgresql/X.Y/main/pg_hba.conf. (X.Y is the version number of PostgreSQL)
    $ sudo gedit /etc/postgresql/8.4/main/pg_hba.conf
    change the following line:
    local all all ident
    into:
    local all all trust
    then reload postgresql in Terminal:
    $ /etc/init.d/postgresql reload


相关推荐

你的评论

就没有什么想说的吗?

最新博客

关于我们 移动版

©2017传客网    琼ICP备15003173号-2    

本站部分文章来源于互联网,版权归属于原作者。
本站所有转载文章言论不代表本站观点,如是侵犯了原作者的权利请发邮件联系站长(weishubao@126.com),我们收到后立即删除。
站内所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!

X