当前位置: 传客网 > PostgreSQL Learning Logs(I)

PostgreSQL Learning Logs(I)

2016-11-01 作者:小丝丝瓜

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



相关推荐

返回
顶部